Skip to content

nemotron hip: add within-path invariance checks for prompt cuts, decode grouping and resume - #3580

Merged
ashhart merged 3 commits into
ashhart:mainfrom
gilby:strix/nemotron-hip-path-invariance
Nov 17, 2026
Merged

ashhart merged 3 commits into
ashhart:mainfrom
gilby:strix/nemotron-hip-path-invariance

Conversation

@gilby

@gilby gilby commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Adds the within-path HIP invariance checks discussed in #3409 as tf-nemotron-hip-test invariance <model dir> [ids.bin] [--no-mtp] (zig/tests/nemotron_hip/invariance.zig), keeping all checks inside Nemotron-H's existing HIP paths without comparing prompt rows against decoded rows or adding cross-engine code:

  1. Prompt chunk cuts + 1-row output head (checkPromptCuts): runs a 193-token prompt in one chunk and in cuts leaving trailing chunks of { 1, 8, 15, 16, 17, 65 } rows, checking Mamba state, every trailing chunk's hidden rows, KV cache pages (replay.kvDiffers), and the single-row e.logits(..., 1) output head (0 differing bits even below 16 trailing rows, matching prompt.zig:44).
  2. Decode window width and stream grouping (checkDecodeGrouping): compares 8 decode steps run as 1-row steps against 2-row and 4-row windows (logits, final Mamba state, KV pages), plus a grouped 2-stream round running 4 rows alongside 3 rows at a different position.
  3. Served prompt-cache resume matches fresh (checkResumePrefix): seeds Hip.prefix at mark 128 of 193, frees the seeding lane, resumes on a fresh lane, finishes the tail, steps 4 decode tokens through Hip.windows + keepRows, and checks Mamba state, last hidden row, KV pages, prompt head logits, 4-step decode logits, and post-decode KV pages against an uncached lane.
  • Also adds a host unit test in zig/src/families/nemotron/hip/prompt_test.zig ("chunk cuts leaving 1, 8, 15, 16, 17 or 65 trailing rows partition every token in order"), exposes KvWhere/kvDiffers from zig/tests/nemotron_hip/replay.zig (synchronizing e.stream before synchronous null-stream page downloads), and wires invariance in zig/tests/nemotron_hip/main.zig.

  • Issue: Refs Nemotron HIP: prompt-pass rows and decoded rows of the same position are not bit-equal (question) #3409.

  • Stacked on: main (6bc82acac).

  • atc overlap --json: incomplete (complete: false, API/time/PR limits) across 5 changed files, reporting 56 overlapping open PRs (4 conflicting, 5 clean, 47 unknown).

Checks on this head

  • Head commit: 1ee29948e (c1dd75b5c plus changelog stamp for nemotron hip: add within-path invariance checks for prompt cuts, decode grouping and resume #3580) on main 6bc82acac.
  • Lean checker (python3 tools/zig/lean_check.py): 221 on 6bc82acac and 221 on 1ee29948e, 0 new findings.
  • python3 tools/pr_check.py --base origin/main --pr 3580: 0 errors, 0 warnings. git diff --check origin/main..HEAD clean, zig fmt --check zig/ clean.
  • Host tests:
    • Mac (zig build hip-host-test -Dhip=true --summary all): 8 of 8 steps succeeded, 80 of 80 passed.
    • Ubuntu HIP host (zig build test -Dhip=true ... --summary all on gfx1151 host with umask 022): 769 of 771 steps succeeded; 6,627 of 6,676 passed, 48 skipped, 1 failed (stage_hip_test, pre-existing on single-GPU APU).
  • GPU device invariance run on gfx1151 (TensorFold/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-MLX-4bit):
    • ./zig-out/bin/tf-nemotron-hip-test invariance ...:
      • invariance: prompt cuts (6 cuts) + 1-row head: 0 bits differ
      • invariance: decode windows (1 vs 2 vs 4) and 2-stream grouping: 0 bits differ
      • invariance: served prompt-cache resume at 128/193 (+4 decode steps): 0 bits differ
      • invariance: PASS
  • Planted 1-ULP failure checks (1 ULP XOR in each check's logits on gfx1151, verified red and reverted):
    • Prompt cut 1-row head: exits non-zero (invariance (prompt cut 1-row head): logits bits differ (max diff 2.3841858e-7) / FAIL LogitsMismatch).
    • Decode window: exits non-zero (invariance (decode window): logits bits differ (max diff 2.3841858e-7) / FAIL LogitsMismatch).
    • Resume decode: exits non-zero (invariance (resume decode): logits bits differ (max diff 2.3841858e-7) / FAIL LogitsMismatch).
  • Note on device download synchronization: e.stream uses hipStreamNonBlocking; adding e.stream.synchronize() before synchronous null-stream DeviceBuffer.download calls in invariance.zig and replay.kvDiffers eliminates a host/device download race caught on the initial run.
  • Raw logs and driver script: https://gist.github.com/gilby/20a0f3d9dcadf5e0c3395160f04b53b3.
  • Not run: other HIP chips (no hardware available; only gfx1151 tested), multi-rank --tp > 1.

Receipt

  • Tests and diagnostic subcommand only: no serving, runtime, weight-loading, kernel, or allocation path changes, so served speed and outputs on main are untouched.
  • Machine and GPU: one Strix Halo (Radeon 8060S, gfx1151, 128 GB unified, HIP 7.1, Zig 0.17.0) with TensorFold/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-MLX-4bit.
  • Exactness: tf-nemotron-hip-test invariance reports 0 differing bits across all three within-path suites (invariance: PASS), and each planted 1-ULP mismatch exits non-zero (FAIL LogitsMismatch).
  • Licence of any new weights or drafter: n/a.

Checklist

  • The title and description match the head commit, including the receipt.
  • New tests fail on planted regressions and pass cleanly on the clean tree.
  • 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.
  • No serving path or precision changed.

@ashhart

ashhart commented Nov 16, 2026

Copy link
Copy Markdown
Owner

Thanks @gilby. The invariance checks for prompt cuts, decode grouping and prompt-cache resume, the stream synchronize before null-stream downloads, and the planted 1-ULP failure on gfx1151 make this solid. HIP is hardware we don't have, so your gfx1151 runs are the device evidence, and they cover it.

The only thing left is a changelog offset, which is ours. Nothing more is needed from you. It's in our landing queue.

  • Synthena

@ashhart
ashhart force-pushed the strix/nemotron-hip-path-invariance branch from 1ee2994 to 2fa4776 Compare November 17, 2026 01:40
@ashhart
ashhart merged commit f0a54bd into ashhart:main Nov 17, 2026
2 of 11 checks passed
ashhart pushed a commit that referenced this pull request Nov 17, 2026
@ashhart

ashhart commented Nov 17, 2026

Copy link
Copy Markdown
Owner

Thank you @gilby. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes.

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