ILayer<T>
Interfaces · AiDotNet.Interfaces
Defines the contract for neural network layers in the AiDotNet framework.
Implements: IDiagnosticsProvider, IParameterSource<T>, IWeightLoadable<T>
Known implementations: IAttentionBlockDecorator<T>, IContextualLayer<T>, IGraphConvolutionLayer<T>, ILoRAAdapter<T>, ITrainableLayer<T>
How It Works
For Beginners: A neural network is made up of layers, similar to how a sandwich has layers. Each layer processes data in some way and passes it to the next layer.
This interface defines what all layers must be able to do, regardless of their specific type. Think of it as a checklist of abilities that every layer must have to work within our neural network.
Properties
| Property | Summary |
|---|---|
bool CanExecuteOnGpu { get; } |
Gets whether this layer can execute on GPU. |
bool IsShapeResolved { get; } |
Indicates whether this layer’s input/output shapes are concrete or still deferred. |
bool SupportsGpuTraining { get; } |
Gets whether this layer supports GPU-resident training (forward, backward, and parameter updates on GPU). |
bool SupportsTraining { get; } |
Indicates whether this layer supports training operations. |
string LayerName { get; } |
Gets the name of this layer for mixed-precision policy lookup. |
Methods
| Method | Summary |
|---|---|
IEnumerable<ActivationFunction> GetActivationTypes() |
Gets the activation functions used by this layer. |
IReadOnlyList<ILayer<T>> GetSubLayers() |
Returns the immediate child layers contained within this layer. |
LayerShape GetOutputLayerShape() |
This layer’s output shape, in which individual axes may be dynamic and may be named. |
Tensor<T> Forward(Tensor<T> input) |
Processes input data through the layer during the forward pass. |
Tensor<T> ForwardGpu(Tensor<T>[] inputs) |
Performs a GPU-resident forward pass, keeping the result on the GPU. |
Tensor<T> ForwardWithPrecisionCheck(Tensor<T> input) |
Processes input data through the layer with automatic mixed-precision handling. |
Tensor<T> GetBiases() |
Gets the bias tensor for layers that have trainable biases. |
Tensor<T> GetWeights() |
Gets the weight tensor for layers that have trainable weights. |
Vector<T> GetParameterGradients() |
Gets the gradients of all trainable parameters. |
int[] GetInputShape() |
Gets the shape (dimensions) of the input data expected by this layer. |
int[] GetOutputShape() |
Gets the shape (dimensions) of the output data produced by this layer. |
void ClearGradients() |
Clears all accumulated gradients in the layer. |
void Deserialize(BinaryReader reader) |
Loads the layer’s configuration and parameters from a binary stream. |
void DownloadWeightsFromGpu() |
Downloads the layer’s weights and biases from GPU memory back to CPU. |
void ResetState() |
Resets the internal state of the layer to its initial condition. |
void Serialize(BinaryWriter writer) |
Saves the layer’s configuration and parameters to a binary stream. |
void SetTrainingMode(bool isTraining) |
Sets the layer to training or evaluation mode. |
void UpdateParameters(T learningRate) |
Updates the layer’s parameters using the provided parameter values. |
void UpdateParameters(Vector<T> parameters) |
Updates the layer’s parameters using the provided parameter values. |
void UpdateParametersGpu(IGpuOptimizerConfig config) |
Updates the layer’s parameters on GPU using the specified optimizer configuration. |
void UploadWeightsToGpu() |
Uploads the layer’s weights and biases to GPU memory for GPU-resident training. |
void ZeroGradientsGpu() |
Resets the GPU gradient accumulators to zero. |