Table of Contents

Interface IChainableComputationGraph<T>

Namespace
AiDotNet.Interfaces
Assembly
AiDotNet.dll

Interface for layers that can chain their computation graph with a provided input node.

public interface IChainableComputationGraph<T>

Type Parameters

T

The numeric type used for calculations.

Remarks

This interface is designed for composite layers (layers that contain other layers internally) to support JIT compilation. Instead of creating their own input variable node, implementing layers build their computation graph using a provided input node, allowing parent layers to chain multiple sub-layer computation graphs together.

For Beginners: Some neural network layers are "composite" - they internally use other layers (like convolutions, batch normalization, etc.) to perform their function. When we want to compile the entire network for faster execution (JIT compilation), we need a way to connect these internal layers together. This interface provides that connection point.

Example usage in a composite layer like DenseBlock:

public override ComputationNode<T> ExportComputationGraph(List<ComputationNode<T>> inputNodes)
{
    var inputNode = TensorOperations<T>.Variable(symbolicInput, "input");
    inputNodes.Add(inputNode);
var currentFeatures = inputNode;
foreach (var layer in _subLayers)
{
    var layerOutput = layer.BuildComputationGraph(currentFeatures, $"layer{i}_");
    currentFeatures = TensorOperations<T>.Concat(new[] { currentFeatures, layerOutput }, axis: 1);
}
return currentFeatures;

}

Methods

BuildComputationGraph(ComputationNode<T>, string)

Builds the computation graph for this layer using the provided input node.

ComputationNode<T> BuildComputationGraph(ComputationNode<T> inputNode, string namePrefix)

Parameters

inputNode ComputationNode<T>

The input computation node from the parent layer.

namePrefix string

Prefix for naming internal nodes (for debugging/visualization).

Returns

ComputationNode<T>

The output computation node representing this layer's computation.

Remarks

Unlike ILayer<T>.ExportComputationGraph, this method does NOT create a new input variable. Instead, it uses the provided inputNode as its input, allowing the parent layer to chain multiple sub-layers together in a single computation graph.

The namePrefix parameter should be used to prefix all internal node names to avoid naming conflicts when multiple instances of the same layer type are used.