Class ParameterRegistry<T>
- Namespace
- AiDotNet.ModelLoading
- Assembly
- AiDotNet.dll
Manages named parameters for weight loading.
public class ParameterRegistry<T>
Type Parameters
TThe numeric type used for calculations.
- Inheritance
-
ParameterRegistry<T>
- Inherited Members
Remarks
For Beginners: This class is like a phone book for model parameters. Each parameter has a name (like "encoder.conv1.weight") and we can look up or set parameters by their names.
When loading pretrained weights, we need to know:
- What parameters exist in our model
- What shape each parameter should be
- Where to actually put the weight data
This registry provides all three capabilities.
Constructors
ParameterRegistry()
Initializes a new empty parameter registry.
public ParameterRegistry()
Properties
Count
Gets the number of registered parameters.
public int Count { get; }
Property Value
Methods
GetNames()
Gets all registered parameter names.
public IEnumerable<string> GetNames()
Returns
GetShape(string)
Gets the expected shape for a parameter.
public int[]? GetShape(string name)
Parameters
namestring
Returns
- int[]
Load(Dictionary<string, Tensor<T>>, Func<string, string?>?, bool)
Loads weights from a dictionary.
public WeightLoadResult Load(Dictionary<string, Tensor<T>> weights, Func<string, string?>? mapping = null, bool strict = false)
Parameters
Returns
Register(string, int[], Func<Tensor<T>?>, Action<Tensor<T>>)
Registers a parameter with getter and setter delegates.
public void Register(string name, int[] shape, Func<Tensor<T>?> getter, Action<Tensor<T>> setter)
Parameters
namestringThe parameter name.
shapeint[]The expected shape.
getterFunc<Tensor<T>>Function to get the current tensor.
setterAction<Tensor<T>>Action to set the tensor value.
RegisterChild(string, ParameterRegistry<T>)
Registers a child ParameterRegistry with a prefix.
public void RegisterChild(string prefix, ParameterRegistry<T> child)
Parameters
prefixstringPrefix to add to all child parameter names.
childParameterRegistry<T>The child registry.
RegisterLayer(string, ILayer<T>)
Registers a layer's weights and biases.
public void RegisterLayer(string prefix, ILayer<T> layer)
Parameters
prefixstringName prefix for the layer (e.g., "encoder.conv1").
layerILayer<T>The layer to register.
RegisterLayers(string, IEnumerable<(string Name, ILayer<T> Layer)>)
Registers multiple layers with a naming pattern.
public void RegisterLayers(string prefix, IEnumerable<(string Name, ILayer<T> Layer)> layers)
Parameters
prefixstringPrefix for all layer names.
layersIEnumerable<(string Name, ILayer<T> Layer)>The layers to register.
TryGet(string, out Tensor<T>?)
Tries to get a parameter by name.
public bool TryGet(string name, out Tensor<T>? tensor)
Parameters
namestringtensorTensor<T>
Returns
TrySet(string, Tensor<T>)
Sets a parameter by name.
public bool TrySet(string name, Tensor<T> value)
Parameters
namestringvalueTensor<T>
Returns
- bool
True if set successfully, false if name not found.
Validate(IEnumerable<string>, Func<string, string?>?)
Validates weights against registered parameters.
public WeightLoadValidation Validate(IEnumerable<string> weightNames, Func<string, string?>? mapping = null)
Parameters
weightNamesIEnumerable<string>mappingFunc<string, string>