Indexed Models and Embeddings #
This module defines models with non-differentiable tensor inputs, their scalar objectives, and
embedding-table builders. Import NN.API.Neural.Indexed when constructing or executing an indexed
model; ordinary sequential builders remain in NN.API.Neural.Builders.
A shape-typed model with one non-differentiable tensor input.
Shapes of trainable parameters and persistent buffers.
- kindValue : String
- initialStateValue : TorchLean.nn.State Float self.stateShapes
- initializationPlanValue : Option (Runtime.Autograd.Model.Module.RuntimeInit.Plan self.stateShapes)
- inputValidatorValue : TorchLean.Tensor β σ → Except String Unit
- programValue (_mode : TorchLean.nn.Mode) {α : Type} [TorchLean.Storage α] [Context α] : Runtime.Autograd.Model.Program.Data α β self.stateShapes [σ] τ
Instances For
Construct an indexed model from its complete runtime definition.
Build an indexed-model placeholder whose static configuration is known to be invalid.
The placeholder owns no parameters or buffers and is rejected by IndexedModel.validate before
allocation or execution.
Instances For
The model readers are opaque so proofs cannot unfold them into private fields. Public readers
expose model metadata; this namespace supplies the runtime-only configuration and program readers.
Builders can change the representation without exposing it to downstream proofs.
How the runtime should fill the state at allocation time, or none for an unplanned model.
Static verdict on the configuration, checked before anything is allocated.
Verdict on one concrete input, for conditions the shape type cannot express.
The runtime program for a given Mode, scalar-polymorphic in its execution type.
Model label used in summaries and diagnostics.
Semantic initial values for the complete model state.
Gradient flags aligned with stateShapes.
Validate static model configuration before allocation or graph execution.
Instances For
Append an ordinary sequential model after an indexed-input model.
Instances For
Scalar objectives #
Pair an indexed-input model with a scalar loss.
The resulting objective definition has one ordinary target tensor and a separate non-differentiable model-input tensor. Keeping those packs separate ensures that indices cannot receive gradients or be reinterpreted through the model's floating-point element type.
The target shape is independent of the model output shape, so this constructor also supports losses whose labels use a different representation from the prediction. Training mode is the default.
Instances For
Pair an indexed-input model with mean-squared error.
Instances For
A reusable trainable embedding table with vocabularySize rows and vectors of length
embeddingWidth.
Unlike IndexedModel, this definition is independent of the eventual token-tensor shape. Calling
table.model indices specializes it to an input shape with bounded Fin vocabularySize indices.
Instantiating that model produces mutable weight storage; the definition itself remains immutable
so it can be lowered and used in proofs.
Instances For
Construct an embedding table at the runtime-builder boundary.
How the runtime should fill that matrix at allocation time.
Whether the optimizer may update the table, false for a frozen lookup.
Static configuration verdict, including errors from Embedding.Internal.invalid.
Construct a rejected table value without exposing parameter state through Embedding.model.
Instances For
Construction options for a freshly initialized embedding table.
- weightInitialization : Init.Scheme
Initialization scheme for the table.
The default agrees with
torch.nn.Embedding.reset_parameters: independent samples from the standard normal distribution. Language-model constructors normally override this with their architecture-specific initialization, such as GPT-2's standard deviation0.02. - freeze : Bool
Freeze the table by excluding it from reverse-mode parameter gradients.
Instances For
Construct an embedding from an exact initial weight table.
This is the typed counterpart of passing _weight to torch.nn.Embedding. The supplied tensor
fixes both dimensions at compile time and is also recorded as an exact row-major runtime
initializer, so CPU and CUDA module construction start from the same payload.
Instances For
Specialize an embedding table to a concrete index-tensor shape.