Skip to content

nemotron: a prompt segment's buffers read the owner's shared-expert plans and pair ids - #996

Merged
ashhart merged 2 commits into
ashhart:mainfrom
plotarmordev:nemotron/segment-shared-plans
Oct 18, 2026
Merged

ashhart merged 2 commits into
ashhart:mainfrom
plotarmordev:nemotron/segment-shared-plans

Conversation

@plotarmordev

Copy link
Copy Markdown
Contributor

What this changes

With --segments 2 (or TF_CUDA_SEGMENTS=2), Nemotron 3.5 Super VL on CUDA gives a different greedy reply to an
8,186-token prompt than with --segments 1. Buffers.sibling carves every scratch field of an extra segment from
that segment's own new allocation, shared and sids included. Only the owner's load (initShared) writes those
two, so the second segment's latent MoE plans its shared expert from pair ids that were never written. A sibling now
points shared and sids at the owner's buffers (training passes get their scratch from the same function and now
read the owner's too). The new tf-cuda-test prompt-segments MODEL IDS_FILE runs a prompt as 2, 3 and 4 segments a
call and compares it with one uncut pass, byte for byte. It fails on main and passes with the fix.

Bug report

  • Native version: 1.0.12 (main 6ee828c), CUDA backend.
  • Model: nvidia/NVIDIA-Nemotron-3.5-Super-VL-120B-A12B-NVFP4 at revision 82d93699acd3be9e4617c53360fe5b3f5dbeb1b3.
  • GPU/OS: one DGX Spark (GB10, sm_121), driver 580.173.02, CUDA 13.0, Ubuntu 24.04.4 LTS, Linux 6.17 aarch64.
  • Command: tensorfold-native serve MODEL --name super --context 18432 --parallel 1 --prompt-cache-gib 0 --segments 2
    against the same command with --segments 1.
  • Startup error: none. The server loads and replies; only the reply differs.
  • Request: segments/long_document.request.json in the receipt (a synthetic field log with a question, thinking off,
    temperature 0, max_tokens 256, ignore_eos), sent to /v1/chat/completions. Its prompt is 8,186 tokens.
Build --segments Drafted token_sha256 "draft": false token_sha256
main 6ee828c 1 857f11a3163c… 857f11a3163c…
main 6ee828c 2 376584461f3c… 376584461f3c…
this PR 1 857f11a3163c… 857f11a3163c…
this PR 2 857f11a3163c… 857f11a3163c…

Full hashes: 857f11a3163c107f8e12864988d1dc6ba065bf279c0db94c63ee608b881b92e6,
376584461f3c1ac840f375481fc3628040b6421160d44324a7b58cda94f36f70. Main's rows are the same on two boots each.

Receipt

Raw files: receipts/nemotron/segment-shared-plans (segments/, plain/, speed/, prompt-cuts/, host-checks.txt).

  • Environment, with the TensorFold commit, MLX or PyTorch version, machine and GPU, checkpoint and revision:
    this branch at 57418b9 against main 6ee828c, each built with zig build native and zig build install
    (-Doptimize=fast -Dsm=121, the same fatbins; the change touches no kernel). A DGX Spark (GB10, sm_121, 48 SMs),
    driver 580.173.02, CUDA 13.0. nvidia/NVIDIA-Nemotron-3.5-Super-VL-120B-A12B-NVFP4@82d93699acd3be9e4617c53360fe5b3f5dbeb1b3.
    Segment arms: serve MODEL --name super --context 18432 --parallel 1 --prompt-cache-gib 0 --segments 1|2.
    Speed arms: serve MODEL --name super (defaults: 16,384-token window, 8 streams), on a second DGX Spark.
    TF_HEAT_HIGH=85 TF_HEAT_LOW=75 throughout.

  • Exactness, from tools/bench_concurrent.py --alone --serial or token_sha against "draft": false:

    • The reproducer above: with this PR, drafted equals "draft": false equals --segments 1 at --segments 2.
    • tf-cuda-test prompt-segments MODEL long_document.ids.txt (the request's 8,186 rendered ids): main with only the
      test added: FAIL prompt-segments: a pass as 2 segments a call differs from the uncut pass (exit 1). This PR:
      PASS prompt-segments: a 8186-token pass as 2 to 4 segments a call equals the uncut pass (exit 0).
    • tools/bench_concurrent.py --alone --serial (4 streams, 256 tokens, 3 reps, temperatures 1.0 and 0, code and
      chat) on this PR: every reply equals its request alone (12 of 12 in each of the four rows) and the alone runs equal
      "draft": false (4 of 4 sampled, 1 of 1 greedy, each prompt); 0 unequal, 0 failed.
    • tf-cuda-test prompt-cuts MODEL long_document.ids.txt on this PR: a pass keeping states inside chunks and at
      their ends equals the uncut pass, and passes resumed at each keep equal it (PASS, PASS). Its third check fails
      the same way on main: a background pass stepping aside kept { 512 }, not [768]. With TF_HEAT_HIGH/TF_HEAT_LOW
      set, the heat gate's wait asks the test's cancel too (beforeChunk), so its call count runs ahead; not this change.
  • Decode speed before and after, from tools/bench_openai.py (--tokens 256 --reps 3 --temperatures 0, medians in
    tokens/s, boots in the order main, PR, PR, main; every arm's reply hash is the same):

    Prompt main (1st) PR (2nd) PR (3rd) main (4th)
    fibonacci-raw (code) 42.19 42.44 42.35 41.84
    gpu-chat-no-think (prose) 32.32 32.31 32.25 32.06

    Unchanged: the change runs only when segment buffers are made, and a decode round never reads a sibling.

  • Prompt speed before and after: tools/bench_cache.py --require-cold --prompt-file long_document.ids.json --expected-prompt-tokens 8186, the first (cold) request's ttft_s on a fresh server: main 4.453 s and 4.456 s,
    this PR 4.468 s and 4.449 s (qualified in all four). Default serve flags run one segment a call, as before.

  • Tests run, with pass, fail and skip counts:

    • zig build test --summary all: 84/84 steps, 417 of 424 tests passed, 7 skipped, 0 failed.
    • zig build test-kernel-contract, zig build test-golden (309/319 equal to the frozen answers, 0 unexpected
      differences), zig build fuzz-cortheon, zig fmt --check: pass.
    • tools/zig/lean_check.py: 517 problems on the base, 517 here, 0 new (tools/zig/lean_new.py).
    • GPU: tf-cuda-test prompt-segments 1 pass (1 fail on main with only the test, as above); prompt-cuts 2 pass,
      1 fail, the same on main (above).
  • Not run, and why:

    • Metal: the change is CUDA-only (cuda_state.zig), and there is no Mac here.
    • Tensor parallelism: segments need one rank (error.SegmentsNeedOneRank), so a TP=2 server never makes siblings.
    • A non-latent Nemotron (Nano) checkpoint: its fixed shared plans (shared) are read by decode windows only, which
      run on the owner's buffers; not run.
    • tensorfold segments (the developer bench) and training passes (cuda_train.zig): not run.
    • tf-cuda-test kernel-contract: no kernel changed.

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, and concurrent equals solo.
  • No precision traded for speed. If the bits change, the description says which sums change and why.
  • A new or changed GPU kernel is registered with the kernel contract (docs/kernel-contract.md); each backend's SUMMARY line is in the receipt. (No kernel changed.)
  • Prompt processing is no slower than the last release.
  • The description says which platforms I ran, Metal M1 to M5 and CUDA, and which I could not.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency. (prompt-segments is a tf-cuda-test command that takes the checkpoint and ids file, as prompt-cuts does.)
  • 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.

…lans and pair ids

Buffers.sibling gave each extra prompt segment its own `shared` and `sids` from fresh scratch, but only the owner's
load writes them (initShared), so a segment of a latent MoE planned its shared expert from pair ids nothing wrote. On
Super with `--segments 2` an 8,186-token prompt's reply differed from `--segments 1`. A sibling now points both at the
owner's. `tf-cuda-test prompt-segments MODEL IDS_FILE` checks a prompt run as 2 to 4 segments a call against one uncut
pass: caches and states, the MTP head's caches, the logits, the last hidden row and the first token.

@cwschroeder cwschroeder left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Source approval for the three-file change at 57418b92 against 6ee828c2, with Astra checking the segment and training callers. The owner initializes and synchronizes these tables before creating siblings. Subsequent paths read them, while mutable plans and activations remain private to each sibling. Cleanup frees the sibling's own arena before the owner goes away. I found no blocking issue in this scope.

Locally, Zig 0.17.0 passes whole-tree zig fmt --check build.zig zig, whitespace checks, and zig build install -Dtarget=aarch64-linux-gnu -Doptimize=fast -j2 --summary all (12/12 steps). That cross-compiles the CUDA test driver; it does not run it. All four current-head remote checks are green.

I also checked the published records pinned at receipt commit 84888dcf: the baseline two-segment token hash differs, while both patched segment settings, drafted and plain, match baseline one-segment. The four speed arms carry matching reply hashes. These checks confirm consistency of the author's records, not independent GPU measurements. The reported 8,186-token latent-MoE case covers the full segment test; the small guard improvement below would preserve that coverage for future inputs. No model, CUDA device, training, or Metal execution was performed here.

Comment thread zig/tests/cuda/prompt_cuts.zig Outdated
var ids = try readIds(gpu, ids_path);
defer ids.deinit(gpa);
const n = ids.items.len;
try check.expect(n > R, "prompt-segments: the prompt needs more than {d} tokens, has {d}", .{ R, n });

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] Require enough tokens to exercise all four active segments

The current n > R guard accepts 2,049 tokens. That creates only two chunks, so settings 3 and 4 still pass without exercising their extra segments. Consider requiring n > (cuda.segments.MAX - 1) * R (6,144 here), or reporting how many segments were active. Your published 8,186-token input already meets the stronger guard. The negative control also needs a latent-MoE checkpoint whose prompt path reads sids.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 7edd928: the guard is now n > (cuda.segments.MAX - 1) * R (6,144 here), and its message names the segment count. On the GB10 the receipt's 8,186-token prompt still prints PASS prompt-segments: a 8186-token pass as 2 to 4 segments a call equals the uncut pass, and its first 3,000 tokens now stop at FAIL prompt-segments: 4 segments need more than 6144 tokens, has 3000.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed at 7edd9282: the guard requires more than 6,144 tokens before Engine.init, so accepted inputs have enough chunks for all four active segments. This resolves my P3. The new GPU pass/fail control remains author-reported; I have not rerun it independently.

@ashhart
ashhart merged commit eab8028 into ashhart:main Oct 18, 2026
4 checks passed
ashhart added a commit that referenced this pull request Oct 18, 2026
ashhart added a commit that referenced this pull request Oct 18, 2026
…drafts a round, with the Mamba scan in stages of 32

The branch builds on #999's earlier commits and on #997, which come in with it. Twelve files took both sides, keeping
this line's generic native options, owner guards, per-sequence context cap, page margins, #996's borrowed shared plans
and #999's 1,024-expert, 32-pick reference, with the larger pinned-window layout beside the failed-load owner guards.
The Mamba scan's record joins #999's records in the registry.
@ashhart

ashhart commented Oct 18, 2026

Copy link
Copy Markdown
Owner

Thank you, @plotarmordev, for the segmented 8,186-token prompt and concurrent/solo comparisons.

We merged the fix for 1.1.0 in eab8028. Each sibling prompt buffer gets the initialized shared-expert plans and pair IDs its sequence owns, preserving the current page owners and scratch path.

NVIDIA GB10: 8,193-token Super VL/Lightning NVFP4 passes split into two to four segments equalled uncut passes.

Posted by Ash's AI Assistant Synthena

BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
…31 MTP drafts a round, with the Mamba scan in stages of 32

The branch builds on ashhart#999's earlier commits and on ashhart#997, which come in with it. Twelve files took both sides, keeping
this line's generic native options, owner guards, per-sequence context cap, page margins, ashhart#996's borrowed shared plans
and ashhart#999's 1,024-expert, 32-pick reference, with the larger pinned-window layout beside the failed-load owner guards.
The Mamba scan's record joins ashhart#999's records in the registry.
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.

3 participants