Module Execution #
This file connects typed module definitions to executable scalar modules. It provides state
initialization and explicit execution settings. Command-line selection lives in
NN.API.Module.Command.
ObjectiveDefinition describes a scalar objective together with model state and input shapes.
Instantiating it produces a mutable Objective that can evaluate the objective, return explicit
state gradients, and update trainable entries. The shape lists remain part of both types, so
construction and execution use the same state ordering.
Executable state for a model and scalar objective.
The runtime trainer and device machinery are intentionally hidden. Public code interacts with an
objective through operations such as loss, grad, step, and state.
- runtimeObjective : Runtime.Autograd.Model.Module.Objective α β stateShapes inputShapes dataInputShapes
Instances For
Wrap a runtime objective behind the public execution boundary.
Reveal the runtime objective only to implementation code.
Evaluate the scalar objective.
Instances For
Differentiate the objective with respect to its state.
Entries that do not require gradients are zero. Set value := true to return
(gradient, objectiveValue) from one forward tape.
Instances For
Start a fresh optimizer history from the module's current parameters and buffers.
This clears backend-owned moments and permits switching between native and generic updates. Use the returned optimizer state for subsequent steps.
Instances For
Compute one gradient update.
By default this returns the next optimizer state. Set loss := true to return
(nextOptimizerState, lossValue) from the same training tape.
Instances For
Try one backend-native mean-gradient update over a nonempty batch.
Instances For
Apply a generic optimizer update from an already-computed, shape-aligned state gradient.
On CUDA, this cannot share an optimizer history with native steps: their device moments are
separate from the explicit optimizer state. Call initOptimizer before switching paths.
Instances For
Read the complete parameter-and-buffer state as host tensors.
On CUDA, parameters changed on the device are copied back before this function returns. The runtime retains these host values and reuses them while they remain current. Reading the state after another device update requires a fresh transfer and host storage for the updated parameters.
Use this operation when inspecting, saving, or transferring a model's state. For large models, include the host copy in the memory needed for those operations.
Instances For
Replace the complete parameter-and-buffer state.
Instances For
Instantiate an objective with an explicit scalar-literal conversion.
Instances For
Instantiate an executable objective, optionally starting from exact typed state.
initialState? bypasses the model's stored Float initializers. Without it, initialization uses the
runtime arithmetic's standard Float conversion.
This is the low-level constructor for custom losses and multi-input programs. The higher-level
nn.Module and Trainer APIs should be preferred for ordinary sequential models.