Skip to content

Flash Next CUDA: structured output and required tool calls - #1062

Closed
Mirrdhyn wants to merge 1 commit into
ashhart:mainfrom
hygurlabs:flashnext-cuda-structures
Closed

Mirrdhyn wants to merge 1 commit into
ashhart:mainfrom
hygurlabs:flashnext-cuda-structures

Conversation

@Mirrdhyn

@Mirrdhyn Mirrdhyn commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Flash Next on the native CUDA engine refused response_format, the guided_* fields and tool_choice: "required" or a named function with HTTP 400 (backend 'cuda' cannot enforce tool_choice "required" or a named function: it has no token grammar support), because its lane backend had no first_masked hook. This adds the hook and masks every draw the backend makes on the host: the first token, each verify window's rows (draws) and the shared one-row rounds (tokenAt). A disallowed token's score becomes bf16 -inf, then the existing keyed draw runs unchanged; with no grammar the code path is the one before. Follows #564 and #596.

1 commit, 5 files, +56/-11: zig/src/families/flashnext/cuda_lanes.zig, cuda_mtp.zig, cuda_mtp_ops.zig, cuda_mtp_check.zig (the new draws argument) and one line in docs/api.md.

Receipt

  • Environment: TensorFold main d1018b31 + this commit (first measured on d46d17a7; after the rebase the six constrained cases and the unconstrained --alone --serial checks were run again, same results); NVIDIA DGX Spark, GB10 sm_121, driver 595.84, nvcc 13.2.86; checkpoint Flash Next MLX 4-bit with MTP (qwen4_exp), drafts on; libtfgrammar built with zig build grammar -Dxgrammar= from xgrammar v0.2.8.

  • Before (main): tool_choice: "required" and a json_schema response_format both return HTTP 400.

  • After, --parallel 4, six constrained cases (tool_choice: "required" with two tools, a named function, a json_schema with string and integer fields; each at T=0 and at T=1 with a seed), each sent alone, with "draft": false, and as four concurrent copies:

    • 6 of 6 valid (finish_reason: "tool_calls" with offered tools and parseable arguments; the named one only; the schema's fields and types);
    • 6 of 6 equal to their "draft": false reply;
    • 24 of 24 concurrent copies equal to the reply alone.
  • Unconstrained output unchanged: bench_concurrent.py --alone --serial, T=0 levels 1/4 and T=1 levels 1/2: 0 unequal, 0 failed, and the same token_sha256 per prompt as 1.1.0's receipt (code and chat, T=0 and T=1).

  • Decode speed (bench_openai.py, 256 tokens, 3 reps, T=0, --parallel 2 --context 131072, chunk 16384), tok/s:

    1.1.0 this branch
    fibonacci-raw 81.7 82.3
    gpu-chat-no-think 68.7 69.6
  • Prompt speed: n/a, the change only touches token draws after the prompt.

  • Tests run: zig fmt --check, zig build native, test, test-cuda-host pass (152 of 152 and 80 of 80 build steps, 0 failed); lean check 444 problems, main's count. New test cuda_mtp.zig "a masked row draws only allowed tokens, greedy the best of them": with the mask made a no-op it fails (expected 64, found 4).

  • Not run, and why:

    • Two ranks: Flash Next's CUDA loader takes its ranks from --tp (cuda_lanes_load.zig), and the CUDA build does not serve --tp (native/cuda.zig:31 lists --mtp-drafts and --mtp-confidence), so serve cannot start that path; GLM and Nemotron take theirs from TF_GLM_RANK / TF_NEMOTRON_RANK. Rank 0 draws every token there, so these masks would apply as they are; is Flash Next at TP=2 on CUDA meant to be reachable from serve?
    • Metal: no Mac here, and no Metal file is touched.

Checklist

  • 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 (not exercised with a grammar), and concurrent equals solo.
  • No precision traded for speed. Unconstrained bits are unchanged.
  • No GPU kernel is new or changed.
  • Prompt processing is no slower than the last release (not reached by the change).
  • CUDA GB10 run; Metal not run (no Mac, no Metal file touched).
  • New tests fail before the change, pass after it, and skip cleanly without their dependency (a host test, no GPU).
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths. No AI attribution lines.

@ashhart ashhart mentioned this pull request Oct 19, 2026
@Mirrdhyn
Mirrdhyn force-pushed the flashnext-cuda-structures branch from 42cafee to 2621d12 Compare October 19, 2026 13:07
@ashhart

ashhart commented Oct 19, 2026

Copy link
Copy Markdown
Owner

Thanks @Mirrdhyn. Masking each draw, rather than gating requests, is the right shape: drafts that break the grammar are rejected by the masked target draw, so constrained replies equal "draft": false, and unconstrained requests keep the GPU greedy path.

We've rerun it on our GB10 with Flash Next MLX 4-bit and MTP drafts, --parallel 4, two servers each way. Without the change, all 36 constrained requests (required, named and json_schema, at temperature 0 and 1) return 400. With it, all 36 return valid replies, and in every case the reply alone, "draft": false and four concurrent copies share one token hash on both servers. Unconstrained token hashes are identical with and without it, drafted equal to plain. It's on the 1.1.2 line under your name.

Posted by Ash's AI Assistant Synthena

ashhart added a commit that referenced this pull request Oct 21, 2026
…dits

The 1.1.2 section had no entries for the contributed pull requests carried into this release, so neither their
changes nor their authors reached the release notes. Add an entry for each, written from its commits: Flash Next's
CUDA prompt tiles and structured output (#1046, #1062), --thinking-reserve, the long-loop guard and the --vision
template diagnostic (#1064, #1075, #1076), GLM's Metal eh_proj tile and CUDA waiting ranks (#1066, #1053), M1's
simdgroup cap (#1055), Nemotron's CUDA image and shared-window fixes (#1057, #1058), Qwen's live-row expert routing
(#1047), the shared CUDA operators and contract fixture (#1056, #1068, #1070, #1071, #1073), the ROCm receipt,
drafter and draft-count work (#1043, #1044, #1045), the ModelOpt recipe numbers (#1042), the Windows host build
(#1034) and the session store's allocation-free rollback (#637). Thank #643's and #1060's reporters as the other
entries thank theirs.
@ashhart

ashhart commented Oct 21, 2026

Copy link
Copy Markdown
Owner

Flash Next CUDA structured output and required tool calls are included in 1.1.2 (https://github.com/ashhart/TensorFold/releases/tag/v1.1.2), with your original authorship retained. The grammar masks the first draw and each draw in a verification window. Closing this as carried, and thank you.

It landed as 8afbd14.

- Synthema, Ash's AI Assistant.

@ashhart ashhart closed this Oct 21, 2026
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