Skip to content

npu-pack: the gemma3 1.8 Token .fconst has 6-header layer blocks of two sizes (translategemma-4b-it, Gemma-3-4b 1.8 refused) #2604

Closed

Description

@bong-water-water-bong

npu-pack info on amd/translategemma-4b-it_rai_1.8.0_npu_4K (gemma3_text: hidden 2560, 34 layers, 8 heads / 4 KV, head_dim 256, IM 10240, vocab 262208) reports 340 gaps, all of the form:

model.layers.0.self_attn.q_proj.weight: the layer block has 6 epsilon headers, and this importer reads blocks of 2 (q/k/v/o in one payload) or 4 (q/k/v, two per-head QK norms, o_proj)

The same reader gap blocks Gemma-3-4b_rai_1.8.0_npu_16K.

Measured (scan of the Token .fconst for the bf16 1e-6 epsilon header, 205 headers = 34 x 6 + the tail)

Per layer block, the gaps between its six headers are:

from header to next bytes reading
h0 input_layernorm h1 5,854,272 envelope (64 + 2H = 5,184) + q/k/v tiles
h1 h2 576 64 + bf16[head_dim 256]: a per-head norm
h2 h3 2,959,968 (2,959,936 on layers 5, 11, 17, 23, 29) the other per-head norm + o_proj
h3 post_attention h4 5,184 64 + bf16[H]
h4 pre_feedforward h5 42,921,088 64 + bf16[H] + the MLP
h5 post_feedforward next block 5,184 64 + bf16[H]

So this is the Qwen3 4-header block plus Gemma-3's pre/post-feedforward norms. The block size is not constant: the five global-attention layers (every 6th, Gemma-3's 5:1 local:global pattern) are 32 B shorter, inside the h2→h3 section, so locate_fconst()'s single stride cannot place them. After the last block come the final-norm header and 430,026,304 B of tail (the head).

Needed

Found in the TAMDCOL 1.8 sweep (cl-npuperf).

Activity

  1. bong-water-water-bong commented on Nov 16, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Reproduced the header structure independently before touching the reader -- every number in the issue checks out

    My scan method is a different one from the issue's (I did not look for the eps header alone): a header is eps (bf16 1e-6 = 86 35) followed by 62 zero bytes, which is the envelope pad the reader itself writes. That distinguishes a header from the ~47 800 eps-shaped byte pairs in the payload:

    headers with the 62-byte pad:  205          (issue: 205 = 34 x 6 + 1)   ✓
    blocks of 6 headers:            34          + 1 lone tail header       ✓
    tail after the last block:      430,026,304 B                            ✓
    

    and the gap histogram, grouped per block:

    (h0→h1, h1→h2, h2→h3) blocks
    (5,854,272, 576, 2,959,968) 29
    (5,854,272, 576, 2,959,936) 5

    with h3→h4 = 5,184 and h4→h5 = 42,921,088 on every block (5184 x 68 = two norms per layer, 5,854,272 x 34, 576 x 34, 42,921,088 x 34 in the full histogram). So:

    • the 32-byte difference is real and it is exactly 5 layers, which is Gemma-3's 5:1 local:global pattern -- and it is inside h2→h3, not in any envelope;
    • locate_fconst()'s single stride cannot express this, and no eps-anchor vote will: the anchors repeat with two periods, 32 B apart, and the vote's "one dominant lag" test is structurally the wrong question for this file. That is the same shape as the Qwen2-7B refusal already documented in the code (the epsilon headers do not repeat with a single period), so the fix must be header-driven block starts, not a better vote.

    What I have not determined, and the issue asks: what the 32 B are on the five global layers. They sit in the h2→h3 section, which the issue reads as the other per-head norm + o_proj; 32 B is 16 bf16 values, which is neither a head_dim-256 norm (512 B) nor an envelope (64 B), so it is more likely a shorter q/k/v tile on global layers than a missing tensor. I would want one look at the adjacent bytes on a boundary pair (layer 4 local vs layer 5 global) before naming it, and I would rather leave it explicitly unknown for now than guess it into the layout -- a wrong guess here offsets every subsequent layer, and the issue's own warning applies: "a clean import is not proof."

    Plan for the reader change (next step, on this same file):

    1. locate_fconst() gains a header-driven path: walk the envelope headers (eps + 62 zero pad), group them 6 per block, and use each block's own h0 as its start -- the constant stride stays as the fallback for the 2- and 4-header forms, which is where it is correct today;
    2. the 6-header section map, naming pre_feedforward_layernorm / post_feedforward_layernorm in the container alongside the two existing per-layer norms;
    3. the 32 B left as an explicit "global-layer section is 32 B shorter" fact rather than normalised away, so the tiles are read at their own offsets;
    4. a crafted fixture arm for the two-size pattern (cheap: the header walk is testable on a synthetic file of 3 blocks, 2 of one size and 1 of the other), and npu-pack info on this pack should go 340 gaps → 0.

    The pack is at ~/.cache/scratch-i679/gemma3 (8.0 GB on disk) for anyone who wants to re-run the scan; dd_metastate_Llm_Token_Token_*.fconst is the file, 2,189,399,392 B.

  2. bong-water-water-bong commented on Nov 16, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    The 32 bytes are not a tile: the h2→h3 section holds exactly 578 x 5,120 B tiles on both kinds of layer, and the local layers carry 32 B extra

    I took the one question the issue leaves open ("what the 32 B on the local layers are") and measured it instead of guessing. The section h2→h3 is [64 B header][bf16 gain, head_dim 256 -> 512 B][o_proj tiles], so the tile region is span - 576:

    layers span tile region / 5,120
    29 local 2,959,968 B 2,959,392 B 577.93 -- not integral
    5 global 2,959,936 B 2,959,360 B 578 exactly

    (kImportTileBytes = the q4_1 tile = 5,120 B, kTileRows = 64.) So:

    • the o_proj tile count is 578 on both kinds of layer -- the local:global difference is not a different o_proj width or another tile;
    • the 32 B is a separate field that only the local layers carry, or a 32-byte pad: 16 bf16 values, which is neither a head_dim-256 gain (512 B) nor an envelope (64 B).

    And a byte diff cannot localise it further, which is worth recording so nobody repeats it: aligning layer 4 (local) with layer 5 (global) diverges at +64, i.e. immediately inside the gain values, because the two layers' weights differ from the first byte on. The layout difference has to be found structurally, not by diffing.

    What the reader change therefore needs to do, and the shape I would give it:

    1. read 578 tiles at h2 + 64 + head_dim*2 on a global layer and at that offset +32 or -32 on a local one -- which of the two is still open, and I would settle it by attempting both and taking the one whose 578 tiles all parse (a tile that begins 32 bytes late will fail its own scale/zero sanity check);
    2. never derive the block start from a stride: the block starts are in the headers (my scan puts them at 0x0, 0x595440, ... with 6 headers per block), which is also what makes the local/global difference harmless;
    3. treat the 32 B as a named field on local layers, so the container records what was there rather than the reader normalising it away.

    Method note for whoever picks this up: the discriminator that made the header scan reliable is eps followed by 62 zero bytes (the envelope pad) -- searching for 86 35 alone gives ~47 800 candidates in this 2.19 GB file, 205 of which are headers.

  3. bong-water-water-bong commented on Nov 16, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Where the 32 bytes sit, exactly: between the q-norm gain and the o_proj tiles, on the 29 sliding-attention layers, and it is 2 x 8 heads

    Both spans now reproduce exactly from one formula, which is what makes this a measurement rather than a reading:

    full_attention (5 layers):   64 (header) + 512 (bf16 gain, head_dim 256) + 578 x 5,120 (o_proj tiles) = 2,959,936  EXACT
    sliding (29 layers):         64 + 512 + 32 + 578 x 5,120                                            = 2,959,968  EXACT
    

    So:

    • the 32 B sits after the gain and before the first o_proj tile, not at the end (placing it at the end leaves 577.93 tiles, which is not a value the file can hold);
    • the tile count is 578 on every layer -- the local/global difference is not a different o_proj width;
    • it is 16 bf16 values, and 16 = 2 x 8 = 2 x num_attention_heads (the pack's config: hidden 2560, IM 10240, 34 layers, 8 heads, 4 KV, head_dim 256, sliding_window 1024), i.e. a per-head pair of scalars on the sliding layers -- consistent with Gemma-3 attaching per-head scale/bias on its local attention and not on its global one. That is an inference from the arithmetic, and the reader does not have to decide what they mean: it has to skip them, and now it knows by how much and where.

    And the layer indices cross-check: the config's layer_types is [sliding x5, full, sliding x5, full, ...], so full_attention sits at 5, 11, 17, 23, 29 -- exactly the five layers the issue measured as 32 B shorter (my scan found 2959968 x 29 and 2959936 x 5, and the 5 are at those indices). So the short ones are the full_attention layers and the 32 B field belongs to the sliding ones, which is the opposite of the issue's phrasing ("the five global-attention layers are 32 B shorter") in a way that matters for the reader: the field is present on the 29, absent on the 5.

    What this gives the reader change, with nothing left to guess:

    1. block starts from the headers (eps + 62 zero bytes; 205 headers = 34 x 6 + 1);
    2. the six sections are h0 input | attn tiles | h1 per-head gain | h2 per-head gain [+32 B on sliding] | o_proj tiles + h3 post_attention | h4 pre_feedforward | h5 post_feedforward | MLP;
    3. o_off = h2 + 64 + head_dim*2 + (32 if this layer is sliding else 0), with "sliding" known two ways -- from h3 - h2 (2,959,968 vs 2,959,936) or from the config's layer_types -- and the two must agree, which is a cheap cross-check worth asserting rather than choosing between.
  4. bong-water-water-bong commented on Nov 16, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Attention geometry now reads; the next blocker is the MLP offset, and the refusal's own number says which one it is

    With the 6-header path in place, npu-pack info on translategemma-4b no longer refuses on "the layer block has 6 epsilon headers" -- the attention sections validate against the measured arithmetic. The refusal moved one section on:

    model.layers.0.mlp.{gate,up,down}_proj.weight: the MLP section ends at 94662176 B in a 51746272-byte layer block
    

    That pair of numbers is the whole diagnosis, because it decomposes exactly:

    94,662,176  =  51,746,272 (the block stride)  +  42,915,904 (the true MLP size)
    

    and the true geometry from the header scan is:

    block stride  = 5,854,272 + 576 + 2,959,968 + 5,184 + 5,184 + 42,921,088 = 51,746,272   ✓
    h5 (relative) =                                     8,825,184
    mlp_off       = 8,825,184 + 64 + 2*2560            = 8,830,368
    mlp size      = 51,746,272 - 8,830,368             = 42,915,904  (the number in the message)
    

    So the MLP size the decoder computed is right, and the offset it used was the block stride rather than h5 + kNormOff + 2H -- i.e. it looked for the MLP one block too far along. mlp_off = g.post_attn_hdr() + kNormOff + H * 2 is the same expression the 4-header path uses, so the open question is narrow and checkable: whether hdr holds block-relative offsets on this form or file-absolute ones, which one line of instrumentation answers.

    What is already settled and worth keeping from this attempt:

    • the attention half of the 6-header form reads: s0 = q/k/v tiles, s1 = 64 + head_dim*2, s2 = gains + extra + 578 o-tiles with extra ∈ {0, 32} derived from the span itself rather than from a version or a config;
    • o_off skips the 32 B per-head scalar pair on the sliding layers, which is the part the old reader could not express at all;
    • the refusal message now names all three block forms (2, 4, 6), so the next family that does not fit says so in the terms of the ones that do.

    Not claimed: no gaps count yet, no import, no forward check. This is a partial change against a 340-gap issue, and the honest state is "attention reads, MLP offset wrong by exactly one block".

  5. bong-water-water-bong commented on Nov 16, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    The 6-header geometry now reads end to end: npu-pack info reports 0 gaps, was 340, and the import refuses one layer later on the head

    Two fixes from the same measurement, both in npu/pack_import.cpp:

    1. the attention section of the 6-header form, with o_off skipping the 32 B per-head scalar pair on the 29 sliding-window layers and extra ∈ {0,32} derived from the span itself;
    2. the MLP offset: the block order is h3 post_attention → h4 pre_feedforward → MLP → h5 post_feedforward → next block, so post_attn_hdr() (hdr.back() = h5) lands past the MLP. Measured: h3 8,814,816 · h4 8,820,000 · MLP 42,921,088 · h5 51,741,088. The MLP starts after h4, and its section ends 5,184 B before the block does (h5's own envelope + bf16[2560]) -- passing the full stride made the decoder expect exactly 5,184 B more than the file holds.
    npu-pack info <pack>   ->  gaps: 340  ...  ->  gaps: 0
    

    And the import now fails on something else, which is the useful part. It gets past the whole body and refuses on the head:

    the head correlates with the pack's own embedding (0.996052) but it is a scaled or partially decoded head
    rather than a correct 4-bit one: relative error 0.980355 (allowed 0.124398 = max(0.020, 1.5 x the
    embedding's own 4-bit noise floor 0.082932)), best-fit scale 50.325832 and rms ratio 0.019792 (allowed
    1 +- 0.05). A pack in this state imports cleanly and answers garbage on the device.
    

    That is a scale factor, not a geometry error: rms ratio 0.0198 ≈ 1/50.5 and best-fit scale 50.33 agree, i.e. the tail decodes ~50x too small. The tail is 430,026,304 B for vocab 262208 x hidden 2560 = 0.64 B/value, which is exactly (16 codes + 4 B scale/zero) / 32 = 0.625 -- a q4_1 32-group tile, 2.5 % larger than the bare product. So the tail is q4_1 and the defect is in the scale/zero reading, not the layout -- worth checking whether this genre stores the head's scale as f16 where the decoder assumes bf16, since a bf16 read of an f16 pair (or the reverse) gives precisely a factor in this range rather than garbage.

    State, honestly: geometry done and verified on the real 2.19 GB file; no fixture arm yet, so I have not opened a PR -- a change this size needs one, and the arm needs a crafted 6-header .fconst (the test's fconst() builder emits two envelopes per layer today). The branch is local. Also worth knowing for whoever picks this up: npu-pack info leaves a 1.9 canonical copy under ~/.cache/1bit/fconst19/, and a refused import leaves a partial container under the output dir that must be deleted before retrying (the tool says so itself).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions