MagnetoDecoderLayer<T>
Layers · AiDotNet.NeuralNetworks.Layers
KOSMOS’s MAGNETO causal language model (reference Kosmos2TextTransformer + tied lm_head). It runs these steps:
- Token embeddings are looked up, image embeddings are written into their slots, and everything is
scaled by sqrt(d).
- Positions: fairseq sinusoidal positions starting at 2, or xPos inside attention.
- Pre-LN blocks, where attention carries a Sub-LN on its output before
out_proj, and the FFN
is fc1, GELU, a Sub-LN, then fc2.
- A final LayerNorm, then logits from the tied embedding matrix.
Inheritance: LayerBase<T> → MagnetoDecoderLayer<T>
Implements: IShapeContract
For Beginners
This is the language model that writes text one token at a time, reading the image’s embeddings as if they were words at the start of the sentence.
How It Works
The single-input forward takes token ids [S] and returns next-token logits [S, vocab].
Constructors
| Constructor | Summary |
|---|---|
MagnetoDecoderLayer(int vocabSize, int dim, int numLayers, int numHeads, int ffnDim, int maxPositions, KosmosPositionEncoding positions) |
Creates the decoder. |
Properties
| Property | Summary |
|---|---|
IReadOnlyList<LayerPort> InputPorts { get; } |
Generated from [TensorPort] declarations. |
IReadOnlyList<LayerPort> OutputPorts { get; } |
Generated from [TensorPort] declarations. |
bool SupportsTraining { get; } |
|
int Dim { get; } |
Model width. |
int VocabSize { get; } |
Vocabulary size (logit width). |
Methods
| Method | Summary |
|---|---|
Dictionary<string, string> GetParameterRoles() |
Returns parameter roles for per-role optimizer configuration (e.g., weight decay exemption for biases). |
IReadOnlyList<ILayer<T>> GetSubLayers() |
|
IReadOnlyList<OutputAxisContract> OutputAxesFor(int inputRank) |
|
IReadOnlyList<Tensor<T>> GetTrainableParameters() |
Returns all trainable parameter tensors marked with [TrainableParameter]. |
LayerInputDomain GetInputDomain(int[] inputShape) |
Generated from the primary [TensorPort] declaration. |
void ResetState() |
|
void SetTrainableParameters(IReadOnlyList<Tensor<T>> parameters) |
Replaces trainable parameter tensors (e.g., with ParameterBuffer views). |
void ZeroGrad() |
Clears all gradient fields discovered by convention ({paramName}Gradient). |