Summary
Wires four Gemma-family ModelConfig fields through the dense CPU forward path in TransformerModel (both RunLayersAndFinalNormCore and the batched RunLayersAndFinalNormBatched), completing the CPU-side Gemma 3 forward implementation on top of the architecture detection / config plumbing landed in #208 and the CPU Attention.Execute softCap parameter landed in #255.
What gets wired
-
PerLayerSlidingWindow[layer] — per-layer override for the sliding-window mask. Gemma 3's sliding_window_pattern produces an interleaved local/global pattern (Gemma 3 ships a 5:1 local:global ratio; e.g. with pattern=2, layers 0/2 are sliding, 1/3 are full). A new GetLayerSlidingWindow(int) helper resolves per-layer-override (with null for full attention) and falls back to the model-wide SlidingWindowSize. No-op on every architecture without the per-layer field set.
-
AttnLogitSoftcap — passed as the new softCap argument to Attention.Execute so the post-scale soft-cap fires in the CPU kernel exactly as in the Vulkan FA shader (attention_flash_f32.comp). Gemma 2 ships 50.0; Gemma 3 leaves the field null but the plumbing is wired regardless.
-
FinalLogitSoftcap — applied in-place via a new ApplyFinalLogitSoftcap helper after RunLmHead's GEMM and before the result-tensor copy; mirrored in the batched lm_head path inside ForwardBatch. Uses TensorPrimitives.Multiply + TensorPrimitives.Tanh for the SIMD-accelerated kernel.
-
QueryPreAttnScalar (QPAS) — overrides the default 1/sqrt(headDim) attention scale with 1/sqrt(QueryPreAttnScalar) when non-null. Routed via the existing scale-providing Attention.Execute overloads. Gemma 3 ships 256.
All four mechanisms are no-ops on every existing architecture (default field values are null), so this is purely additive plumbing.
Dependencies
Test plan
Files touched
src/DotLLM.Models/Architectures/TransformerModel.cs (+74/-8)
Summary
Wires four Gemma-family
ModelConfigfields through the dense CPU forward path inTransformerModel(bothRunLayersAndFinalNormCoreand the batchedRunLayersAndFinalNormBatched), completing the CPU-side Gemma 3 forward implementation on top of the architecture detection / config plumbing landed in #208 and the CPUAttention.ExecutesoftCapparameter landed in #255.What gets wired
PerLayerSlidingWindow[layer]— per-layer override for the sliding-window mask. Gemma 3'ssliding_window_patternproduces an interleaved local/global pattern (Gemma 3 ships a 5:1 local:global ratio; e.g. with pattern=2, layers 0/2 are sliding, 1/3 are full). A newGetLayerSlidingWindow(int)helper resolves per-layer-override (withnullfor full attention) and falls back to the model-wideSlidingWindowSize. No-op on every architecture without the per-layer field set.AttnLogitSoftcap— passed as the newsoftCapargument toAttention.Executeso the post-scale soft-cap fires in the CPU kernel exactly as in the Vulkan FA shader (attention_flash_f32.comp). Gemma 2 ships 50.0; Gemma 3 leaves the field null but the plumbing is wired regardless.FinalLogitSoftcap— applied in-place via a newApplyFinalLogitSoftcaphelper afterRunLmHead's GEMM and before the result-tensor copy; mirrored in the batchedlm_headpath insideForwardBatch. UsesTensorPrimitives.Multiply+TensorPrimitives.Tanhfor the SIMD-accelerated kernel.QueryPreAttnScalar(QPAS) — overrides the default1/sqrt(headDim)attention scale with1/sqrt(QueryPreAttnScalar)when non-null. Routed via the existing scale-providingAttention.Executeoverloads. Gemma 3 ships 256.All four mechanisms are no-ops on every existing architecture (default field values are null), so this is purely additive plumbing.
Dependencies
Architecture.Gemma3enum value and the fourModelConfigfields (PerLayerSlidingWindow,AttnLogitSoftcap,FinalLogitSoftcap,QueryPreAttnScalar).softCapparameter on everyAttention.Executeoverload (span / pointer / parallel / scalar reference paths).Test plan
dotnet build src/DotLLM.Models/DotLLM.Models.csprojis clean.dotnet build tests/DotLLM.Tests.Unit/DotLLM.Tests.Unit.csprojis clean.Files touched
src/DotLLM.Models/Architectures/TransformerModel.cs(+74/-8)