feat(gemma4): local decoder layer and its HF golden oracle - #875
Merged
FeathBow merged 1 commit intoAug 14, 2026
Conversation
Signed-off-by: Feathbow <feathbow@gmail.com>
This was referenced Aug 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Closes #874
The line's first real execution path: one local (sliding-attention) decoder layer, forward only, no KV cache — K and V stay contiguous into
single_prefill, which is exact sliding attention for any prompt the 1024-token window never truncates. That equivalence only holds from position zero and inside the window, so the layer rejectsstart_pos > 0and window-exceeding lengths instead of mis-computing them.The load-bearing constants are the ones the issue calls out: attention is unscaled (
scaling = 1.0), V takes a weightless RMS norm on local layers too (expressed as the plain-w norm with a ones weight — no new kernel),layer_scalarmultiplies the layer output after both residual adds, all four norm sites are norm-then-add, and RoPE rotates the full 256-wide head at the sliding theta. The probe layers come from parsing the layer map, and the oracle asserts that parse against the fixture metadata's own parse before any numeric comparison.attention routes through the hd256
single_prefillinstantiation, whose contiguous cache is HND, so K and V are reassembled per head with existing copy ops (the width-generic-looking NHD entry validates head_dim against 128); the RoPE tables come from the shared core precompute at full head width (the identity case of the frequency/rotary split);layer_scalaris read at load as the host f32 it ends up as; the oracle re-verifies the checkpoint against the fixture's pinned hashes before comparing (full-file for the config files, header-only for the 22 GiB weights file). The layer-map parser and its tests run in the featureless build; the fixture plumbing and the oracle are test-only.Test Env
Single GPU (sm_89, x86_64), CUDA 12.9, against the pinned 12B checkpoint.
Verification
rsqrt(256)decisively fails both nine-token comparisons (max_abs 13-22) while the one-token comparisons stay exact — softmax over one key is scale-invariant, which is why the multi-token probe exists.--ignoredgates run serially.Type of Change