|
Mila
Deep Neural Network Library
|
Gemma 4 decoder block (inference: prefill + decode), one type per attention kind. More...
#include <memory>#include <vector>#include <string>#include <format>#include <sstream>#include <stdexcept>#include <optional>#include <type_traits>import Dnn.Quantization.KvCache.Policy;import Serialization.Tensor;import Dnn.CompositeComponent;import Compute.GqaState;import Dnn.Component;import Dnn.Components.Residual;import Dnn.ComponentType;import Dnn.Components.Gqa;import Compute.Device;import Dnn.Components.Linear;import Compute.ExecutionContext;import Dnn.TensorTypes;import Compute.DeviceId;import Dnn.TensorOps;import Dnn.ITensor;import Serialization.SafeTensors;import Compute.ExecutionContextFactory;import Dnn.Components.Rope;import Dnn.TensorDataType;import Dnn.TensorDataTypeTraits;import Dnn.Tensor;import Dnn.Components.Swiglu;import Dnn.Quantization.Weight.Policies;import Dnn.ActivationType;import Serialization.ModelArchive;import Dnn.Components.IDecoderLayer;import Compute.DeviceType;import Compute.DeviceTypeTraits;import Dnn.Components.GemmaConfig;import Compute.IExecutionContext;import Compute.CpuMemoryResource;import Dnn.Components.RmsNorm;import Serialization.Mode;Classes | |
| struct | Mila::Dnn::GemmaBlock< TDeviceType, TPrecision, kGlobal, TWeightQuant, TKvPolicy >::BlockBuildContexts |
| The per-child build contexts and split-scratch geometry this block implies. More... | |
| class | Mila::Dnn::GemmaBlock< TDeviceType, TPrecision, kGlobal, TWeightQuant, TKvPolicy > |
| One Gemma 4 decoder block; kGlobal selects the global (full-attention) geometry. More... | |
| struct | Mila::Dnn::GemmaBlockWorkspace< TDeviceType, TPrecision > |
| Transformer-owned shared activation workspace for GemmaBlock (pooling). More... | |
Namespaces | |
| namespace | Mila |
| Mila main API namespace. | |
Gemma 4 decoder block (inference: prefill + decode), one type per attention kind.
Modeled on LlamaBlock, with the Gemma 4 deltas:
Inference-only (Gemma is an inference target): implements IDecoderLayer's prefill/decode; no training forward/backward. Gemma RMSNorm is x_norm * (1 + weight) (HF Gemma3RMSNorm): the converter writes the weights RAW (zero-centered) and the +1 is applied at the kernel via RmsNormConfig::withUnitOffset(1.0) on every norm – so the stored weights stay identical to the source checkpoint and the shared RmsNorm kernel stays Llama-safe (offset 0 = raw).
HF reference forward order (Gemma4TextDecoderLayer): res0 = x a = self_attn( input_layernorm(x) ) [qkv_proj, q_norm/k_norm, RoPE, GQA, o_proj] x = res0 + post_attention_layernorm(a) res1 = x f = mlp( pre_feedforward_layernorm(x) ) [GeGLU] x = res1 + post_feedforward_layernorm(f)