Skip to content

cuda families: refuse a token id at or past the embedding table before the lookup - #3044

Draft
ashhart wants to merge 4 commits into
mainfrom
security/token-ids-cuda
Draft

ashhart wants to merge 4 commits into
mainfrom
security/token-ids-cuda

Conversation

@ashhart

@ashhart ashhart commented Nov 12, 2026

Copy link
Copy Markdown
Owner

What this changes

Before: on these paths a token id reached the embedding lookup unchecked, and no embedding kernel bounds its ids, so an id at or past the table read device memory past it. After: each path refuses such an id on the host before the ids are uploaded, and the loaders that took the embedding table as stored refuse one whose rows are not the vocabulary's. CUDA paths: nemotron, gemma4, glm, flashnext on one rank, minimax_m3, the qwen3_5 MTP drafter, lfm2, lfm2_moe, spark25, dory and kolibri1.

  • Issue: n/a. SECURITY.md asks for private reports, so there is no public issue.
  • Stacked on: main.
  • atc overlap --json: not run.

Checks on this head

  • Head commit: 1037c729e83b46e6c15a69662acf8fbd03f8fe2f
  • Lean checker, python3 tools/zig/lean_check.py, on the base and on this head: 345 on the base, 345 on this head, 0 new.
  • Tests run, with the command and pass, fail and skip counts:
    • zig fmt --check on 26 files: passes
    • git diff --check: passes
    • zig build native: 66/66 steps succeeded
    • zig build check-native-cuda-host compile-flashnext-mtp-parity-host compile-glm-native-open: 11/11 steps succeeded
    • zig build -Dhip=true check-native-hip-host test-native-hip-host test-environment-hip-host test-hip-family-offers-host test-qwen3-hip-host: 19/19 steps succeeded
    • zig build xpu-native with stand-ins for Intel's ocloc and nGEN headers: 47/47 steps succeeded
    • zig build test-lfm2-load-host test-step5-host test-lfm3-host test-lfm3-prefill-host test-minimax-info-host test-minimax-cuda-host test-xpu-refusal-host test-draft-xpu-host test-qwen27-config-xpu-host test-nemotron-round-depth-host test-nemotron-prefill-widths-host test-nemotron-mtp-policy-host test-nemotron-restored-head-host test-nemotron-subset-head-host test-nemotron-grants-host test-nemotron-copies-host test-gemma4-load-parts-host test-gemma4-owners-host test-gemma4-contract-host test-gemma4-prompt-head-host test-gemma4-tower-host test-glm-window-contract-host test-glm-contract-host test-glm-formats-host test-glm-copies-host test-flashnext-host test-flashnext-batch-host test-flashnext-mtp-plan-host test-flashnext-driver-host test-flashnext-single-session-host test-flashnext-scheduling-host test-flashnext-constraint-host test-flashnext-prefill-pairs-host test-flashnext-contract-host test-qwen35-rounds-host test-qwen35-verify-host test-qwen35-prefill-host test-qwen35-draft-frames-host: 197/197 steps succeeded; 841/847 tests passed (6 skipped)
    • zig build test-cuda-host: 391/391 steps succeeded; 6231/6269 tests passed (38 skipped)
    • zig build test-golden test-server-security test-pull-security: 76/76 steps succeeded; 31/31 tests passed
  • New tests:
    • security: a token or label past the embedding table is refused before upload
  • CI: runs on this push.
  • Not run, and why: One new unit test, in lfm2. The other checks are covered by the compiles and by reading. zig build test and every step that runs on a GPU were not run: this Mac's GPU was serving a model, and no CUDA, ROCm or Intel hardware was available.

Receipt

  • Main against branch: could not be run. It needs a CUDA device, and none was run.
  • Boxes it reaches: CUDA serving of the families listed above.
  • New switch? Default, accepted values, profile row: none.
  • Environment, with the TensorFold commit, Zig and backend toolchain, machine and GPU, checkpoint and revision: this head on Zig 0.17.0, on an Apple silicon Mac, CPU-only steps. No GPU and no checkpoint was used.
  • Paths and platforms the change reaches, which I ran and which I could not: all four servers (Metal, CUDA, ROCm, XPU) compile with this change. The CUDA host suite ran on macOS. Nothing ran on a GPU.
  • Exactness: not measured. The change adds host comparisons before an upload and changes no kernel and no arithmetic, so a valid prompt takes the same path as on main.
  • Main against this branch, same machine and checkpoint: not run, for the reason above.
  • Decode speed before and after: not measured.
  • Prompt speed before and after: not measured.
  • Licence of any new weights or drafter: 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. Each new test was shown to fail without its fix on the earlier base b38a4dd02. On this base only the passing side was rerun.
  • 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.

For a change that reaches inference:

  • 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 measured: no served run.
  • No precision traded for speed.
  • Decode and prompt processing are no slower than main. Not measured: no served run.

Notes for the reviewer

  • A request that carries such an id now fails with an error where it used to read past the table.
  • A checkpoint whose embedding table does not match its configured vocabulary is refused at load. Most of these checks want an exact match, so a table with more rows than the vocabulary is refused too.
  • Not changed here: the training paths, the dev and timing tools, and output heads that are loaded unshaped.
  • Three pinned serving sources change, so zig/tests/fixtures/gradient-serving.tsv needs their lines re-pinned after merge (hashes below).
  • New hashes for the pinned sources: zig/src/families/flashnext/cuda_batch.zig 12d5aec256867e50bb2619217f2c06660b0862f6f4aa1172e7d00a308fcddbe0; zig/src/families/flashnext/cuda_prompt.zig 91cdf7ec539635390ef4ffa9045dafcf14ee63cccf83e6f0d54d2a9d7578915e; zig/src/families/flashnext/cuda_rows.zig 15d41f522a76e5c0617800914ddc92e1a506ee9071b73749bdeb623f6ea895cc.

Suggested changelog line

CUDA: nemotron, gemma4, glm, flashnext, minimax_m3, qwen3_5's MTP drafter, lfm2, lfm2_moe, spark25, dory and kolibri1 refuse a token id at or past the embedding table before the lookup.

@ashhart

ashhart commented Nov 12, 2026

Copy link
Copy Markdown
Owner Author

Review fixes pushed (0e9944a):

  • cuda_dense/pass.zig (dots.mocr on CUDA) staged its chains' ids with no bound. It now refuses an id at or past the vocabulary with the same TokenOutsideVocabulary the other families use.
  • flashnext/cuda_round_graph.zig: a decode-graph replay writes the round's ids in prepare and never reaches Pass.stage. The n-gram hash folds any id into its table, so nothing caught a bad one there. prepare now refuses it first. Both checks are host-side compares, with no added sync.
  • gradient-serving.tsv: the pins for cuda_batch, cuda_prompt, cuda_rows and cuda_round_graph now match this branch. The cuda/experts.zig row is already stale on main; ci: the serving pins run on every PR; re-pin experts.zig after #2843 #3011 fixes it.

Results:

  • check-native-cuda-host and compile-cuda-tests for Linux: 16/16 steps.
  • test-cuda-dense-host, test-dots-mocr-cuda-host and test-cuda-host: 393/393 steps; 6316 tests passed, 39 skipped.

Next: GB10 runs, main against this branch. We'll check exactness on the families it reaches, and that a bad id beside a live stream fails only its own request.

  • Synthena (Ash's Agent)

@ashhart

ashhart commented Nov 12, 2026

Copy link
Copy Markdown
Owner Author

GB10 results so far, main against 0e9944a (CELLS pp, sweep and chat):

  • Qwen3.8-Flash-Next NVFP4: GREEN.
  • Qwen3.8-27B: GREEN.
  • Nemotron: GREEN.
  • GLM-5.3-Flash NVFP4 at TP=2 on two GB10s: token hashes equal in all 52 cells. Prompt speed and chat are level. One-stream code was −7.3% on the medians, but that comes from one new run with two slow repeats (63 and 65 tok/s). The other new run was level with both base runs (73.2 against 73.9 and 74.8), and the change is a host-side compare, so we read it as noise.

Gemma 4 12B, LFM2.5 and Spark 2.5 are next on another GB10. This lands once those are in.

  • Synthena (Ash's Agent)

@ashhart

ashhart commented Nov 14, 2026

Copy link
Copy Markdown
Owner Author

The other three GB10 models, main against 0e9944a:

  • Gemma 4 12B: GREEN.
  • Spark 2.5: GREEN.
  • LFM2.5: prompt speed and decode are level at every size from 2K to 32K, and prompt tokens are identical across all runs. The verdict says RED only because the chat resume cell never reached the prompt cache, on base and new alike, so that cell didn't run for this model; that isn't the change.

Every model is in, so this goes into the landing queue. It lands after the 1.2.9 cut.

  • Synthena (Ash's Agent)

…e the lookup

The embedding kernels read the table at the id they are given and none of them bounds it, so the host check
is the only one. Each path now refuses an id at or past the vocabulary before it uploads the ids, and the loaders
that took the table as stored refuse one whose rows are not the vocabulary's.
… the decode graph

The dense pass (dots.mocr on CUDA) staged its chains' ids with no bound; it now refuses one at or past
the vocabulary with the other families' TokenOutsideVocabulary. A Flash Next decode-graph replay writes the
round's ids in prepare and never reaches Pass.stage, and the n-gram hash folds any id into its table, so
prepare refuses one at or past the vocabulary first. The serving pins for cuda_batch, cuda_prompt, cuda_rows
and cuda_round_graph take this branch's bytes.
@ashhart
ashhart force-pushed the security/token-ids-cuda branch from 1b7c583 to 1020ec7 Compare November 22, 2026 05:04

This branch has not been deployed

No deployments
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.

1 participant