TrainingObjective<T>
Models & Types · AiDotNet.Training
One optimizer step a model declares instead of writing its own training loop: the step’s data and the loss built from it. The network base class packs the data, runs the step on the shared fused session (the compiled plan when it applies, the shared eager tape otherwise) and restores whatever the step changed.
How It Works
A model declares its objectives in NeuralNetworkBase.DefineTrainingObjectives. A model with one network
and one loss returns one objective. A model that steps several networks with their own optimizers (a GAN’s critic
and generator) returns one per network, in the order they step.
Everything that changes from step to step (noise, timesteps, masks, an adjacency matrix, labels) goes in
Data. The base class packs it into the step’s input, so a compiled plan replays each step on that
step’s own data. Loss receives views of the packed tensors in the same order and shapes; any other
host value it reads is frozen into the plan at trace time.
Constructors
| Constructor | Summary |
|---|---|
TrainingObjective(Func<IReadOnlyList<Tensor<T>>> drawData, Func<IReadOnlyList<Tensor<T>>, Tensor<T>> loss) |
Creates an objective whose data is drawn when its step runs: after the objectives declared before it have stepped. |
TrainingObjective(IReadOnlyList<Tensor<T>> data, Func<IReadOnlyList<Tensor<T>>, Tensor<T>> loss) |
Creates an objective whose data is drawn when its step runs: after the objectives declared before it have stepped. |
Properties
| Property | Summary |
|---|---|
Action AfterStep { get; set; } |
Runs after the step, whether it succeeded or not: restores state the loss changed. |
Action<T> OnLoss { get; set; } |
Receives the step’s loss after a successful step: loss histories, and updates that follow an optimizer step (weight clipping, a moving average). |
Func<IReadOnlyList<Tensor<T>>, Tensor<T>> Loss { get; } |
Builds the scalar loss from views of Data. |
Func<IReadOnlyList<Tensor<T>>> Parameters { get; set; } |
The tensors this step trains, or null for the model’s whole trainable set. |
IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> Optimizer { get; set; } |
The optimizer for this step, or null for the model’s training optimizer. |
IReadOnlyList<Tensor<T>> Data { get; } |
The tensors that change from step to step, in the order Loss receives them. |
NeuralNetworkBase<T> Network { get; set; } |
The network whose fused session runs this step, or null for the model that declared it. |