Skip to content

Inkling 2 Mini on Metal: a window's grammar masks step by the padded vocabulary, so a structured reply passes its second row - #4635

Closed
sethforprivacy wants to merge 22 commits into
ashhart:mainfrom
sethforprivacy:inkling2-mini-metal-masks
Closed

sethforprivacy wants to merge 22 commits into
ashhart:mainfrom
sethforprivacy:inkling2-mini-metal-masks

Conversation

@sethforprivacy

Copy link
Copy Markdown
Contributor

What this changes

Before: on Metal, a Mini request with a token grammar (response_format with a JSON schema, a required tool call) ends after two or three tokens with the reply's grammar rejected a chosen token, HTTP 500. After: the reply follows its grammar.

This is a proposal on top of #4387, opened as a draft.

The cause. The server sizes a grammar's masks by the checkpoint's vocab_size, 201,024, so a window's masks are 6,282 words a row (grammar.vocabSize, Compiler.open). verifyFn stepped through them by the unembedding's real rows, 200,058, which is 6,252 words. Row 0's mask starts at word 0 either way, so the first token is right; every later row of a window reads its mask 30 words a row early, picks a token the grammar does not allow, and the stream ends in the error above.

The fix. maskWords is the padded vocabulary's words, maskRow takes row r at that stride, and a window whose masks are neither empty nor rows * words long is refused (InvalidInklingMasks) where it was read short.

Checks on this head

  • Head commit: d536e5d05.
  • Lean checker, on the base and on this head: 167 and 167, 0 new.
  • Tests run:
    • backend.zig, new: "a window's masks step by the padded vocabulary's words" (6,282 words; row 2 of three reads the bit set at its own first word and row 1 does not).
    • zig build native -Dcpu=apple_m1: compiles.
    • The six Inkling host steps (test-inkling2-metal-host, test-inkling2-host, test-inkling2-controls-host, test-inkling2-launch-map-host, test-inkling2-metal-capabilities, compile-inkling2-native-host): exit 0.
    • tf-kernel-contract --only inkling2 (-Doptimize=safe): SUMMARY 41 kernels: 41 pass gates 1-4, 0 fail, 0 known findings; 41 controls: 41 red as planted, 0 missed; 0 limit problems, exit 0.
    • zig fmt --check build.zig zig and git diff --check: clean.
  • CI: not yet reported when this was written.
  • Not run, and why: the whole zig build test test-golden on this head (the stack's inherited failures are listed in Inkling 2 Mini on Metal: #4387's native build compiles, its norms write their output, and concurrent streams equal solo #4446). CUDA and HIP are not touched; I did not look at how their Mini backends stride masks.

Receipt

Served, one request each, greedy:

Request Before This head
response_format json_schema (two required strings), "Name the capital of France and its country as JSON." HTTP 500 after 2 tokens {"city":"Paris","country":"France"}
tool_choice required, one tool HTTP 500 after 3 tokens 200; the grammar's <tool_call> text, see below
  • A required tool call now follows its grammar, but that grammar frames a call as <tool_call> text, which is not how Mini writes one (a typed block, as server: split Inkling 2 replies into reasoning, text and tool calls #4124 reads them), so the call comes back as content. That is the tool grammar's style for this family and not this change; I mention it so the second row is not read as a working required call.
  • Speed: none claimed.
  • Licence of any new weights or drafter, or "n/a": n/a.

Checklist

  • The title and description match the head commit, including the receipt and the stack.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency. (The unit test's helpers do not exist before the change; the served rows are the before and after.)
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.
  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off.
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (Not touched for requests without a grammar.)
  • No precision traded for speed. If the bits change, the description says which sums change and why. (No arithmetic is touched.)
  • Decode and prompt processing are no slower than main at one stream and the widest admitted; with --drafter, no slower than without it. (Not touched.)

ashhart and others added 22 commits November 21, 2026 16:05
Derive per-visit cache access and exact arithmetic for the 48 visits so CUDA admission and kernels have a reference before serving is enabled.
Decode stored NVFP4 and MXFP8 expert weights to BF16 and launch them beside the grouped expert/vision kernels, with exact tensor baselines and planted faults.
Launch cross-pass messages, rank-64 gates, residual steps and split QKV with FP32 reductions, BF16 rounding controls and per-launch resource records.
Run all 48 visits with per-visit cache state, prompt snapshots and exact rollback. Refuse TP, vision and DSpark loading until those engines exist.
…y's words, so structured replies pass their second row
gilby added a commit to gilby/TensorFold that referenced this pull request Nov 22, 2026
… mask stride and firstLogprobRow

Fuse Stage-1 argmax into tf_inkling2_logits and add Stage-2 tf_inkling2_reduce_argmax with exact host tie-breaking and NaN-at-0 preservation. Enable gpu_tokens with async GPU-resident decode queueFn and skip unread f32 logits DRAM stores on pure-greedy unmasked no-logprobs batches while keeping mixed batches exact. Fix ashhart#4635 multi-row grammar mask stride from xgrammar padded vocab words, fix firstLogprobRow when called before first(), and add host tests and Metal kernel contracts.
@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Sorry for the noise: this was closed automatically when #4387 landed on main and its base branch was removed. It is reopened and now targets main. We will follow up here on what it needs next; nothing is needed from you yet.

  • Synthena

@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thank you, @sethforprivacy. Every commit this PR adds is now on main inside #4387 with your authorship kept, so it ships with Inkling 2 Mini on Metal in the next release. Closing this one as landed there.

  • Synthena

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants