Skip to content

chain: the Nemotron-H walk, plans and reader live in crates/chain (redo of #848) - #1192

Merged
midagedev merged 1 commit into
mainfrom
nemolift
Nov 11, 2026
Merged

midagedev merged 1 commit into
mainfrom
nemolift

Conversation

@midagedev

Copy link
Copy Markdown
Owner

Nemotron-H의 디코드 순서, 레이어 계획, 리더를 crates/chain으로 옮깁니다(#848을 오늘 main에서 다시 함). 코드만 옮겼고 커널과 launch는 그대로입니다.

What and why

The Nemotron-H decode walk, its layer plans and its GGUF reader move out of crates/gpu into crates/chain, the
backend-neutral owner that the qwen3moe walk already uses (and that the Metal backend shares). chain::hybrid holds
the trunk a Mamba-2 + attention model shares: HybridOps (the op list a backend implements), LayerPlan, the
header reader and Walk (embed, each layer's in/core/out, head, over runtime::sched). chain::arch::nemotron_h
holds only its MLP layer. In crates/gpu, mamba_layer and gqa_layer split into in/core/out parts with their
wrappers unchanged (nemotron_h_moe still calls them), and nemotron_h::Program implements HybridOps.
NoLeg and the test header builder move to chain::noleg / chain::test_file, shared with qwen3moe.

Supersedes #848 (1168 commits behind, not rebasable); this redoes it on today's main and carries the imatrix,
NVFP4 and out-gate sites hybrid.rs gained since.

Release notes: internal — a second backend can run the Nemotron-H walk; no behaviour change.

Code shape

  • No second copy. The walk order has one owner (chain::hybrid::walk).
  • Model code holds only architecture facts. Nemotron-H's own chain module is its MLP layer (relu², no gate).
  • Dead code is gone. Not yet: Names::mamba/attn (crates/gpu/src/arch/hybrid.rs) stay for
    nemotron_h_moe beside the plan-driven Names::mamba_of/attn_of. They become one when the MoE family moves
    to the same walk (the next round).
  • No silent failure. A layer whose plan names another kind is a named error; the readers refuse by name.
  • Comments state what is true now. tools/check-comments.sh rc 0.
  • No relaxed gate.
  • cargo fmt and cargo clippy are clean; lint ^warning: 0 = the ratchet 0.

Duplication found or removed: the two name resolvers above (crates/gpu/src/arch/hybrid.rs Names::mamba /
Names::mamba_of), kept until nemotron_h_moe moves.

What I ran

Move proof, just narrow bde0145ef on the box (--no-jit both sides), every kernel carrier of the change:

narrow: ptx-scan bloomery-serve: identical (JIT skipped: --no-jit both)
narrow: ptx-scan gate_gpu_device: identical (JIT skipped: --no-jit both)
narrow: ptx-scan gate_kquant: identical (JIT skipped: --no-jit both)
narrow: ptx-scan gate_swap: identical (JIT skipped: --no-jit both)

The new mod.rs files have no gate-paths row, so the list stayed full. Fixture union batch (box, both cards):

DONE total=138 red=0 tier=fixture skipped=0 wall=2885s deferred=223 real_only=24 real_file=14 needs_env=4

gate-gpu-nemotron-e2e (real tier, A6000), this branch and main bde0145 give the same structure line and the same
logits deltas on all four prompts:

structure: layers mamba=21 attn=4 mlp=17, graph_nodes=380 host=0, entries (got/want) mamba2_step=21/21 relu_sqr=17/17 gqa_flash_seg_g5=4/4 gqa_flash_merge=4/4 kv_append_pos_buf=64/64 embed_rows_q5_0=1/1 group8_entries=0 (want 0) PASS
eager_equals_replay: walk16 16 tokens, ids [1046, 6013, 1046, 5963], logits bit-identical true, finite true PASS
logits_near_mainlines: prose512 512 tokens, max |delta| 0.3773, cosine 0.999685 (floor 0.999) …   (base: the same)

Mac: cargo test -p bloomery-chain 78 passed (13 new, each with its mutant under .mutants/nemolift-*.patch).
Not run: the 38 real-tier gates the fixture batch deferred (they run in the release batch and weekly).

The implementation was written by a GLM-5.3 round and reviewed and gated by Claude Code.

🤖 Generated with Claude Code

https://claude.ai/code/session_01CjHkkjGpdUeLi6Z7fiwRXH

…ain::hybrid, chain::arch::nemotron_h); the gpu body implements HybridOps (nemotron_h::Program) and its step is the walk

The hybrid trunk (Mamba-2 and NoPE attention) gets the shape qwen3moe has: HybridOps is the op list a backend
implements, LayerPlan the per-layer plan read from the file's header, Walk the one order (embed, each layer's
in/core/out, head) over runtime::sched. Nemotron-H's MLP layer is the family's Ffn. crates/gpu's mamba_layer and
gqa_layer split into in/core/out parts; the wrappers keep their signatures, so nemotron_h_moe is unchanged.
The body resolves its layers from the plans (Names::mamba_of, attn_of). NoLeg and the test header builder move to
chain::noleg and chain::test_file, shared with qwen3moe.

A move: the same launches in the same order. Redo of #848 on today's main (the imatrix, NVFP4 and out-gate
sites of hybrid.rs carried over). 13 chain tests, each with its mutant under .mutants/nemolift-*.patch.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01CjHkkjGpdUeLi6Z7fiwRXH
@github-actions github-actions Bot added gpu The card engine: crates/gpu*, crates/app needs-gpu Changes code a card must check, and carries no gate run on a card tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo labels Nov 11, 2026

@github-actions github-actions Bot 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.

Verdict: MUST_FIX: the move is equivalent and its proof holds, but the diff ships one dead public type and the same test fixtures three times.

The move was checked against the old enqueue: sched::walk calls front per layer and end once, so embed → layers → head and the in_head flip per *_out are unchanged; the in/core/out splits keep the enqueue order; the layers are built from the plans, so kinds cannot disagree.

Must fix

1. Counts is dead production code

crates/chain/src/hybrid/plan.rs:62 pub struct Counts and Counts::of (:71) have no production caller in any crate; the only caller is a test, crates/chain/src/arch/nemotron_h/read.rs:217, whose assertion is implied by the kind-sequence assertion above it ("mpampa" ⇒ 2/2/2). .mutants/nemolift-read-counts.patch exists to guard it, pub with no production caller (R13). Cost: deleting now is three edits; later it is an API removal.
Fix: delete the Counts struct and its impl block in plan.rs, the Counts import and the assert_eq!(Counts::of(&got), …) block in the nemotron_h read test, and .mutants/nemolift-read-counts.patch; the remaining assert_eq!(got.iter().map(kind).collect::<String>(), "mpampa") pins the same fact per layer, strictly stronger.

2. The same test fixtures three times in one diff

crates/chain/src/hybrid/read.rs:168 fn mamba(), nemotron_h/read.rs:115 fn mamba() and the Mamba2 literal inside walk.rs:188 hold the same seven widths; hybrid/read.rs:279 fn gqa() and nemotron_h/read.rs:130 fn attn() hold the same Gqa literal. R14: a second copy gets a common core; a third is forbidden. The diff already adds the owner, chain::test_file. Cost: a width a test varies becomes three edits that must agree. Fix: in crates/chain/src/test_file.rs, beside decl/header (add use model::arch::models::{Gqa, Mamba2, OutGate, Rope, RopeMode};):

pub(crate) fn mamba2() -> Mamba2 {
    Mamba2 {
        d_inner: 512,
        d_state: 128,
        n_heads: 8,
        head_dim: 64,
        n_groups: 2,
        d_conv: 4,
        d_in_proj: 1544,
    }
}

/// The NoPE attention the kernels take: 10 query heads over 2 key heads.
pub(crate) fn gqa() -> Gqa {
    Gqa {
        heads: 10,
        kv_heads: 2,
        head_dim: 128,
        value_dim: 128,
        rope: Rope { mode: RopeMode::None, dims: 0, base: 0.0, yarn: None, factors: false },
        qk_norm: false,
        o_norm: false,
        out_gate: OutGate::None,
        select: None,
        window: None,
        sinks: false,
        value_scale: None,
    }
}

Each module then wraps: hybrid's mamba()/gqa() call these, nemotron_h's are layer(Mixer::Mamba2(mamba2()), none()) and layer(Mixer::Gqa(gqa()), none()), walk.rs's plan takes shape: mamba2(). About 90 lines of literals removed for ~35 added.

Non-blocking

⚠ R13 pub ahead of a caller: no_block, mamba_plan, nope_gqa_plan (crates/chain/src/hybrid/read.rs:24, :31, :118) are called only inside crates/chain, and at/layer (crates/chain/src/hybrid/walk.rs:20, :93) only inside their own module. pub(crate) (private for at/layer) until a second backend calls them.

⚠ The header is read twice at load: crates/gpu/src/arch/nemotron_h/body.rs:63 reads Hparams, then spec::read at :95 re-reads it inside and also runs roles::classify, whose tensors the body drops. Load-time only; a spec entry point taking &Hparams would read once — classify's side effect, a new named refusal of files whose tensors disagree with the arrays, is in the safe direction.

Checked

Duplicates: 12 new items checked (types, readers, NoLeg, test_file); hits are findings 1 and 2; mamba_layer/gqa_layer and Names::mamba/attn keep real callers in nemotron_h_moe (placed.rs:565, body.rs:316), so the PR's "not yet" note is accurate.
Complexity: crapper did not run; by hand the splits shrink gqa_layer and mamba_layer, and layer_plans is an even four-arm match.
Silent failure: 7 sites followed (conv_b Option, empty plans, m outside 1..=rows, wrong-kind ops, no_block, nope_fits, d_in_proj); each ends in a named error, and the new d_in_proj/classify checks refuse at load where the old path ran mixed geometry silently.
Tests: 13 new tests each with a .mutants/ patch; 5 mutants read each turn an assertion red; the A6000 e2e structure line and bit-identical eager/replay are in the body.
Gates: none moved or relaxed; ptx-scan identical on the four kernel carriers per the body.
Escape catalog: no shell in the diff; C1–C4 not matched.

Notes

dryer and crapper both failed to run (ModuleNotFoundError); duplication and complexity were read by hand. The body's card evidence names the card and base hash but lacks the nvidia-smi line, head hash and model file of CONTRIBUTING's evidence list.

Card check: needs-gpu. This pull request changes crates/gpu/src/arch/hybrid.rs, crates/gpu/src/arch/nemotron_h/body.rs, crates/gpu/src/arch/nemotron_h/mod.rs … and carries no gate run on a card (CONTRIBUTING's evidence list); a maintainer adds gpu-verified after one.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)


/// Whether `ffn` is the description's "no feed-forward block" of a Mamba-2 or attention layer.
#[must_use]
pub fn no_block(ffn: &Ffn) -> bool {

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.

R13: no caller outside crates/chain — pub(crate) until a backend crate calls it.

Suggested change
pub fn no_block(ffn: &Ffn) -> bool {
pub(crate) fn no_block(ffn: &Ffn) -> bool {

/// Layer `l`'s Mamba-2 plan over a `hidden`-value row: the description's widths checked against
/// the scan's (state 128, a conv of four taps, widths that divide, an input projection of the
/// widths' columns), and the two projections' types from `file`'s header at one of `allowed`.
pub fn mamba_plan(

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.

R13: called only by the nemotron_h family reader in this crate — pub(crate).

Suggested change
pub fn mamba_plan(
pub(crate) fn mamba_plan(


/// Layer `l`'s attention plan over a `hidden`-value row, its four sites' types from `file`'s
/// header at one of `allowed`.
pub fn nope_gqa_plan(

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.

R13: called only by the nemotron_h family reader in this crate — pub(crate).

Suggested change
pub fn nope_gqa_plan(
pub(crate) fn nope_gqa_plan(

@midagedev
midagedev merged commit 8d24747 into main Nov 11, 2026
7 checks passed
@midagedev
midagedev deleted the nemolift branch November 11, 2026 03:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gpu The card engine: crates/gpu*, crates/app needs-gpu Changes code a card must check, and carries no gate run on a card tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant