Skip to content

npu-pack: the 1.7 Gemma-3-4b-it-mm embedding is an f32 table named lm_head.weight, and its 0-D embed_scale is taken as the 4-bit scales #2663

Closed

Description

@bong-water-water-bong

Gemma-3-4b-it-mm-onnx-ryzenai-npu (Ryzen AI 1.7) stops in npu-pack info with:

the pack has no model.embed_tokens.weight, and embedding.onnx has no embed_tokens table + scales

Measured from the pack, as published:

  • genai_config.json declares decoder: model.onnx, embedding: gemma-3-embedding.onnx, vision: gemma-3-vision-npu.onnx, type gemma3. The reader does follow that declaration.
  • gemma-3-embedding.onnx is a Gather (plus the image-token ScatterND path). Its initializers are:
    • lm_head.weight [262208, 2560] f32, 2.68 GB in gemma-3-embedding.onnx.data;
    • model.language_model.embed_tokens.embed_scale [] f32;
    • four int64 scalars.
  • The decoder model.onnx is the 1.9 external-data genre: 238 com.ryzenai:MatMulNBitsBf (34 layers x 7), 34 GroupQueryAttention, q_norm/k_norm, and global + local cos/sin caches. The importer already reads MatMulNBitsBf.

Two causes, both in read_embedding's table selection (npu/pack_import.cpp, the loop before the engine#1725 f32 branch):

  1. The table is named lm_head.weight, not *embed_tokens*, so it is never selected.
  2. The scalar ...embed_tokens.embed_scale matches embed_tokens + scale, so it is taken as the 4-bit table's scales. A 0-D tensor can never be those (they are 2-D [V, groups]).

The fix should select the Gather's data input when it is a 2-D f32 [V, H], which reaches the existing #1725 f32 path, and never take a 0-D tensor as scales. embed_scale must be checked against the forward's own sqrt(H) gemma scaling (sqrt(2560) = 50.596), so it is neither applied twice nor dropped. Rows past this point (intermediate_size from the graph, the sliding/global RoPE split) are not yet reached. Text-only; the vision encoder is separate. Found in the TAMDCOL 1.7 sweep (cl-npuperf).

^Owner: pi-pkg (claimed 11-16 11:2xZ)

Activity

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

    @bong-water-water-bong
    CollaboratorAuthor

    Claimed (pi-pkg). The refusal comes from two independent assumptions in one function, and both are visible in read_embedding's decision tree (npu/pack_import.cpp ~1560-1600).

    1. The f32 branch keys on the table's NAME, not on the graph's declaration. The branch above reads an embed_tokens table when it finds one, with a good reason recorded (engine#1725: "only f32 is read here"). A tied Gemma-3 pack names that same table lm_head.weight — 262208 x 2560 f32, 2.68 GB — and there is no embed_tokens initializer at all, so the branch is never entered and control falls to:

    if (!table || !scales) { if (why) *why = "embedding.onnx has no embed_tokens table + scales"; return {}; }

    That is the message in this issue. Nothing is wrong with the table; it is named after the tensor it is tied to. The graph is gemma3 and declares embedding: gemma-3-embedding.onnx, so the reader already knows which file to open — what it does not use is what that file means for a tied model.

    2. The 0-D embed_scale is accepted as scales. The next line is

    if (table->dims.size() != 2 || scales->dims.size() != 2) { *why = "embed_tokens dims are not 2-D"; return {}; }

    so a 0-D initializer reaching scales would produce that message instead. The issue reports the first message, so in this pack scales is null and the pair check fires — but the two failures are one edit apart, and a fix for (1) alone would immediately expose (2) as the next refusal. Both need to be handled in the same change, or the issue reappears with a different message and looks unfixed.

    What the fix looks like, minimally:

    • accept lm_head.weight as the embedding table when the graph declares a tied/gemma3 embedding and no embed_tokens exists — the condition matters: an untied model whose LM head is a different shape must still be refused, and the shape check (Vf, Hf against the dims) is exactly what distinguishes them;
    • require scales to be 2-D before it is treated as 4-bit scales, so a scalar embed_scale is read as the scalar it is (the semantics comment at ~2694 already says a tied model divides the LM-head output by sqrt(hidden)), not as a per-group table.

    What I have not done, and why: no code this tick. Disk is at 157 GB, below the 160 GB floor for a build, and this file has already produced two compile-breaking edits today from string surgery — both caught only by a compiler. The next tick starts with npu_pack_import_test built in a worktree and a fixture for both refusals, then the edit.

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

    @bong-water-water-bong
    CollaboratorAuthor

    The cause is narrower than "two assumptions", and I have the fix building

    The table scan is name-driven:

    for (const auto& t : em.tensors) {
        const bool emb = t.name.find("embed_tokens") != std::string::npos;
        if (!emb) continue;
        ...
    }

    A tied-embedding graph (the gemma3 family) ships no embed_tokens node at all — its token table is the output
    projection, named lm_head.weight — so the loop binds nothing, table stays null, and the refusal fires:

    embedding: no embed_tokens table + scales
    

    That sentence is true about a name and false about the pack. The pack has an embedding; it just does not use the word I was
    searching for. Same failure as #2713, in a different file: an instrument reporting the absence of its own query as a fact about
    the artifact.

    Fix (built, existing suite green, not pushed): accept lm_head.weight as the token table only when the component carries
    no embed_tokens tensor whatsoever
    and only when it is 2-D. Two conditions, each doing a specific job:

    • no embed_tokens anywhere — every pack that has one keeps byte-identical behaviour, so this cannot regress a shipping family;
    • 2-D — a 4-bit tied table would need scales, and treating the 0-D embed_scale scalar beside it as a quantisation scale
      is exactly the guess this issue was filed about. Refusing to make that guess is the point.

    ./build-2663/npu_pack_import_test → rc 0 (pack leg skipped, no pack dir), ninja incremental rebuild clean.

    Not pushed, deliberately: it has no arm. My rule is that a fix ships with a fixture proven able to fail, and the fixture here
    needs the crafted-pack leg extended with (a) a tied lm_head.weight that must read, and (b) a tied pack that must still be
    refused — the embed_scale-as-scales shape. Landing the code first would be the same "unverified artifact on a saturated queue"
    I have been refusing all evening; the local commit (7f2876830) records the work so it cannot be lost.

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