ILayeredModel<T>
Interfaces · AiDotNet.Interfaces
Provides layer-level access to a neural network’s architecture and parameters.
Known implementations: INeuralNetwork<T>, SubModel<T>
For Beginners
Neural networks are made up of layers stacked on top of each other. Most model interfaces only let you access all parameters as one big list. This interface lets you inspect and manipulate individual layers - their shapes, weights, types, and connections. This enables advanced techniques like:
How It Works
This interface exposes individual layers with their metadata, enabling per-layer operations across the AiDotNet stack: pipeline parallelism, quantization, pruning, LoRA, meta-learning, activation checkpointing, model export, and knowledge distillation.
Reference: This design is inspired by PyTorch’s nn.Module hierarchy,
Megatron-LM’s pipeline partition API, and Flax NNX’s module introspection.
Properties
| Property | Summary |
|---|---|
IReadOnlyList<ILayer<T>> Layers { get; } |
Gets the ordered list of layers in this model. |
int LayerCount { get; } |
Gets the number of layers in this model. |
Methods
| Method | Summary |
|---|---|
IReadOnlyList<LayerInfo<T>> GetAllLayerInfo() |
Gets metadata for all layers. |
LayerInfo<T> GetLayerInfo(int layerIndex) |
Gets metadata for a specific layer including its parameter offset within the flat parameter vector, enabling layer-aware slicing. |
SubModel<T> ExtractSubModel(int startLayer, int endLayer) |
Extracts a contiguous sub-model from startLayer to endLayer (inclusive). |
bool ValidatePartitionPoint(int afterLayerIndex) |
Validates that a partition point between layers is valid (output shape of layer at afterLayerIndex is compatible with input shape of the next layer). |