Table of Contents

Class ParameterRegistry<T>

Namespace
AiDotNet.ModelLoading
Assembly
AiDotNet.dll

Manages named parameters for weight loading.

public class ParameterRegistry<T>

Type Parameters

T

The 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:

  1. What parameters exist in our model
  2. What shape each parameter should be
  3. 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

int

Methods

GetNames()

Gets all registered parameter names.

public IEnumerable<string> GetNames()

Returns

IEnumerable<string>

GetShape(string)

Gets the expected shape for a parameter.

public int[]? GetShape(string name)

Parameters

name string

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

weights Dictionary<string, Tensor<T>>
mapping Func<string, string>
strict bool

Returns

WeightLoadResult

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

name string

The parameter name.

shape int[]

The expected shape.

getter Func<Tensor<T>>

Function to get the current tensor.

setter Action<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

prefix string

Prefix to add to all child parameter names.

child ParameterRegistry<T>

The child registry.

RegisterLayer(string, ILayer<T>)

Registers a layer's weights and biases.

public void RegisterLayer(string prefix, ILayer<T> layer)

Parameters

prefix string

Name prefix for the layer (e.g., "encoder.conv1").

layer ILayer<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

prefix string

Prefix for all layer names.

layers IEnumerable<(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

name string
tensor Tensor<T>

Returns

bool

TrySet(string, Tensor<T>)

Sets a parameter by name.

public bool TrySet(string name, Tensor<T> value)

Parameters

name string
value Tensor<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

weightNames IEnumerable<string>
mapping Func<string, string>

Returns

WeightLoadValidation