GLALanguageModel<T>
Models & Types · AiDotNet.NeuralNetworks
Implements a full GLA (Gated Linear Attention) language model: embedding + N GLA blocks + RMS norm + LM head.
Inheritance: NeuralNetworkBase<T> → DeclaredModelLayoutBase<T> → TokenLanguageModelLayoutBase<T> → GLALanguageModel<T>
For Beginners
GLA is an efficient attention mechanism that uses gates to control information flow, achieving Transformer-level quality with much lower computational cost.
How It Works
GLA introduces hardware-efficient gated linear attention with data-dependent gating and chunk-wise parallel computation. It matches Transformer quality with sub-quadratic complexity.
Reference: Yang et al., “Gated Linear Attention Transformers with Hardware-Efficient Training”, 2024.
Example
var architecture = new NeuralNetworkArchitecture<float>(inputFeatures: 8, outputSize: 4);
var tokens = Tensor<float>.CreateRandom(new[] { 1, 128 });
var trainX = Tensor<float>.CreateRandom(4, 8);
var trainY = Tensor<float>.CreateRandom(4, 2);
var result = new AiModelBuilder<float, Tensor<float>, Tensor<float>>()
.ConfigureModel(new GLALanguageModel<float>(architecture))
.Build(trainX, trainY);
var logits = result.Predict(tokens);
Constructors
| Constructor | Summary |
|---|---|
GLALanguageModel(NeuralNetworkArchitecture<T> architecture, GLAOptions options, ILossFunction<T> lossFunction, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer) |
Properties
| Property | Summary |
|---|---|
bool SupportsTraining { get; } |
|
int ModelDimension { get; } |
Gets the model dimension (d_model). |
int NumLayers { get; } |
Gets the number of GLA blocks. |
int VocabSize { get; } |
Gets the vocabulary size. |
Methods
| Method | Summary |
|---|---|
ModelMetadata<T> GetModelMetadata() |