Skip to content

feat(xla): add sigmoid grouped MoE routing - #3411

Draft
inureyes wants to merge 5 commits into
mainfrom
feature/issue-3345-sigmoid-moe-router
Draft

inureyes wants to merge 5 commits into
mainfrom
feature/issue-3345-sigmoid-moe-router

Conversation

@inureyes

@inureyes inureyes commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Add grouped sigmoid MoE selection with correction bias, lower-index tie-breaking, uncorrected sigmoid combine weights, unconditional flag-controlled normalization, and routed scaling.
  • Add relu2 routed/shared expert schemas and exact Nemotron-H E-block masking while preserving existing softmax SwiGLU graph schemas.
  • Validate recurrent E-block checkpoints against their complete routed/shared tensor schema, including affine-packed companion shapes, instead of requiring dense MLP tensors.
  • Lower sigmoid routing argmax through compiler-compatible single-result reductions while preserving first-NaN and lower-index tie semantics; the production CUDA compiler now accepts the complete hybrid graph.
  • Reject grouped configurations whose top-k exceeds selectable capacity, zero-width shared experts, and unsupported non-null latent projections.
  • Add a Transformers fp32 oracle runnable on IREE local-task or HIP, plus an untied-head tokenizer-backed tiny M*EM- checkpoint generator for full-model handoff.

Validation

PR head: bf8188d20177cde215ca1b54c6444b86396bd8bd. Runtime and numerical gates ran at its immediate executable-code parent 8466cabbfb596a15dfe7a2c912ed3d32670b54ae; the head adds only the test-only environment-variable allowlist correction described below.

  • cargo fmt --all -- --check and git diff --check
  • Targeted cargo clippy --profile test-fast -p mlxcel-xla --lib -- -D warnings
  • Complete host library suite: 543 passed, 0 failed, 21 ignored
  • Environment-variable documentation guard and its 15 focused Python tests pass at the PR head
  • Existing registered MoE goldens remain byte-exact
  • Seven local-task oracle cases pass, including grouped top-2 and normalized/raw top-1 sigmoid routing
  • Complete synthetic E-block checkpoint loads and malformed router, correction-bias, routed-expert, and shared-expert tensors are rejected
  • Guarded CUDA hybrid runtime suite: 5 passed, 0 failed
  • Guarded CUDA tokenizer CLI continuation matches the independent HF fp32 oracle 12/12: [26, 2, 26, 26, 16, 27, 15, 27, 19, 15, 2, 15]; reserved EOS 31 is absent
  • ROCm HIP oracle, hybrid, CLI, and B4/N8 gates at the exact source above
  • Real Nemotron-H-4B feat(xla): Nemotron-H hybrid with dual KV + recurrent state carry #3344 oracle/CLI40, B4/N8, hybrid, and Mamba2 regression gates at the exact source above

The earlier ROCm result at c6ecdabc proves its seven primitive oracle cases and inherited regressions, but it also found the now-fixed E-checkpoint loader defect. It does not establish acceptance for the corrected source, so all HIP/full-model gates remain pending.

The synthetic gates do not establish 30B resident precision, memory usage, selected-expert execution cost, or throughput. Whole-f32 upload and dense all-expert execution are inherited implementation limits for the later #3350 hardware acceptance.

Refs #3345

@inureyes inureyes added status:in-progress Currently being worked on type:enhancement New features, capabilities, or significant additions priority:medium Medium priority area:architecture Architecture and code structure changes area:inference Generation, sampling, decoding (incl. speculative, DRY) labels Nov 24, 2026
@inureyes

Copy link
Copy Markdown
Member Author

ROCm validation preflight at HEAD 3513d13a9d16ad9f4a2eca6f66a30662c0754ffb: XLA library tests fail (538 passed, 1 failed, 21 ignored). Existing golden checks, formatting, and focused XLA-library clippy pass.

Reproducer: scripts/rocm_gpu_guard.sh --hold -- cargo test --profile test-fast -p mlxcel-xla --lib emitter::nemotron_h_tests::nemotron_h_block_aliases_and_rejections -- --exact.

The first failure is nemotron_h_tests.rs:116. Its hybrid_override_pattern="ME" case still expects an error containing #3345. The new parser accepts E and requires MoE configuration fields instead; this fixture lacks n_routed_experts. Please update the rejection coverage and add positive E-block coverage in the implementation branch.

Hardware acceptance is NOT RUN: spike/openxla/moe_oracle.py still covers only the four softmax families and hardcodes llvm-cpu/local-task. No sigmoid oracle/HIP path or synthetic Nemotron-H-MoE checkpoint gate was added in this HEAD; the existing hybrid fixture uses M*-M- without E blocks. Please provide those acceptance artifacts before handing this SHA back for sigmoid numerical validation and the #3344 hardware regressions.

Logs and command files: /home/devops/Development/mlxcel/acceptance/pr3411/3513d13a9d16ad9f4a2eca6f66a30662c0754ffb/. No common code modified. #3408 ROCm acceptance is recorded separately in its PR; it does not validate this changed emitter.

@inureyes
inureyes force-pushed the feature/issue-3344-nemotron-h-hybrid branch from e145049 to a6ccf54 Compare November 24, 2026 17:04
Add configurable softmax or sigmoid routing and SwiGLU or relu2 expert schemas to the OpenXLA MoE primitive. Parse Nemotron-H E blocks into an exact layer mask, load correction-bias and relu2/shared tensors, and preserve existing softmax graph schemas.

Validated with the mlxcel-xla library compile check and targeted test-fast MoE suite.

Refs #3345
Match Transformers normalization semantics, reject impossible grouped routing and unsupported latent shapes, and exercise the E block through local-task and ROCm-capable oracles.

Add a tokenizer-backed tiny full-model fixture for external HIP acceptance without claiming 30B memory or throughput validation.

Refs #3345
@inureyes
inureyes changed the base branch from feature/issue-3344-nemotron-h-hybrid to main November 24, 2026 17:06
@inureyes
inureyes force-pushed the feature/issue-3345-sigmoid-moe-router branch from e2334fb to c6ecdab Compare November 24, 2026 17:06
@inureyes

inureyes commented Nov 24, 2026 •

Copy link
Copy Markdown
Member Author

UPDATED HANDOFF: the E-checkpoint loader and production-fusion compiler failures reported at c6ecdabc are fixed in 8466cabbfb596a15dfe7a2c912ed3d32670b54ae. The exact PR head for the rerun is bf8188d20177cde215ca1b54c6444b86396bd8bd; its only additional change classifies the test-only golden-freeze switch for the CI environment-variable guard. Please discard the earlier ecdc/c6 acceptance commands and rerun every gate below at this head.

Local runtime evidence at executable-code parent 8466cabb: host library 543 passed / 21 ignored; seven local-task MoE oracle cases pass; guarded CUDA xla_hybrid_nemotron_h is 5/5; the tokenizer-backed CLI matches its independent HF fp32 oracle 12/12 with IDs [26, 2, 26, 26, 16, 27, 15, 27, 19, 15, 2, 15], and reserved EOS 31 is absent. At the exact PR head, the environment-variable guard and its 15 focused Python tests pass. This is CUDA/local evidence only and does not replace HIP acceptance.

Set the HIP device before every build/test so the integration target cannot silently use local-task:

test "$(git rev-parse HEAD)" = bf8188d20177cde215ca1b54c6444b86396bd8bd
eval "$(scripts/iree/setup-rocm.sh --env)"
export MLXCEL_XLA_DEVICE=hip MLXCEL_XLA_ROCM_TARGET=gfx1151 MLXCEL_XLA_PRECISION=f32
export OPENSSL_INCLUDE_DIR=/usr/include OPENSSL_LIB_DIR=/usr/lib/x86_64-linux-gnu CARGO_BUILD_JOBS=6
export MLXCEL_ORACLE_PYTHON=spike/openxla/.venv/bin/python
scripts/rocm_gpu_guard.sh --hold -- cargo build --release --features xla-iree --bin mlxcel --example xla_oracle_check --example xla_batch_bench

Run the primitive HIP oracle and the corrected E-bearing M*EM- fixture:

scripts/rocm_gpu_guard.sh --hold -- "$MLXCEL_ORACLE_PYTHON" spike/openxla/moe_oracle.py --device hip --rocm-target gfx1151
"$MLXCEL_ORACLE_PYTHON" spike/openxla/nemotron_h_moe_fixture.py --out /tmp/nemotron-h-moe-tiny
scripts/rocm_gpu_guard.sh --hold -- cargo test --release --features xla-iree,test-utils --test xla_hybrid_nemotron_h -- --ignored --test-threads=1
scripts/rocm_gpu_guard.sh --hold -- target/release/examples/xla_oracle_check --model /tmp/nemotron-h-moe-tiny/mlx --oracle /tmp/nemotron-h-moe-tiny/hf-f32-oracle.json --device hip
scripts/rocm_gpu_guard.sh --hold -- target/release/examples/xla_batch_bench --model /tmp/nemotron-h-moe-tiny/mlx --prompts /tmp/nemotron-h-moe-tiny/hf-f32-oracle.json --device hip --batch 4 --requests 8 --maxcap 12
scripts/rocm_gpu_guard.sh --hold -- env MLXCEL_BACKEND=xla MLXCEL_PRINT_TOKEN_IDS=1 target/release/mlxcel generate -m /tmp/nemotron-h-moe-tiny/mlx -p 'tok4 tok17 tok5 tok29 tok11 tok8' -n 12 --temp 0 --no-chat-template

Require the primitive max-absolute differences to stay below 5e-5, all five hybrid cases to pass, every B4/N8 request to match its single-sequence reference, and the CLI continuation to equal all 12 HF IDs above. If the ROCm Python environment still lacks the IREE runtime module, reuse the previously recorded native-runtime adapter from the c6 validation; it changes only transport through the installed iree-run-module, not the oracle or emitted graph.

Because the corrected SHA changes the emitter, rerun the #3344 real Nemotron-H-4B and Mamba2 gates from spike/openxla/NEMOTRON_H_VALIDATION.md; the earlier #3408 result is not acceptance for this source:

scripts/rocm_gpu_guard.sh --hold -- target/release/examples/xla_oracle_check --model models/hf/nemotron-h-4b --oracle spike/openxla/nemotron_h_reference/hf-f32-oracle.json --device hip
scripts/rocm_gpu_guard.sh --hold -- target/release/examples/xla_batch_bench --model models/hf/nemotron-h-4b --prompts spike/openxla/nemotron_h_reference/hf-f32-oracle.json --device hip --batch 4 --requests 8 --maxcap 24
scripts/rocm_gpu_guard.sh --hold -- env MLXCEL_BACKEND=xla MLXCEL_PRINT_TOKEN_IDS=1 MLXCEL_XLA_CONTEXT_CAPACITY=256 target/release/mlxcel generate -m models/hf/nemotron-h-4b -p 'The capital of France is' -n 40 --temp 0 --no-chat-template
scripts/rocm_gpu_guard.sh --hold -- cargo test --release --features xla-iree,test-utils --test xla_hybrid_nemotron_h -- --ignored --test-threads=1
scripts/rocm_gpu_guard.sh --hold -- cargo test --release --features xla-iree,test-utils --test xla_ssm_single_seq -- --ignored --test-threads=1
scripts/rocm_gpu_guard.sh --hold -- cargo test --release --features xla-iree,test-utils --test xla_ssm_state_carry -- --ignored --test-threads=1

Require the real-model oracle and CLI to match all 40 committed independent HF IDs, B4/N8 to remain reference-exact, and all hybrid/Mamba2 cases to pass. Please report counts and token IDs separately from source-only checks. The prior ROCm investigation and artifact location remain recorded in #3411 (comment).

@inureyes inureyes added status:review Under review and removed status:in-progress Currently being worked on labels Nov 24, 2026
Reserve EOS at a unique token ID and fail fixture generation if the fixed reference emits it, so the CLI and oracle share the same max-token stop policy.

Validate the tokenizer ID bijection and require the manual eager oracle to match Transformers native greedy generation.

Refs #3345
@inureyes

Copy link
Copy Markdown
Member Author

ROCm validation at exact HEAD c6ecdabc1898bb481e20e31cc687f7b8f2aa5bd5: library 541 passed / 21 ignored, goldens, fmt and focused clippy pass. All seven MoE oracle cases pass on both local-task and HIP; HIP worst max-absolute difference is 1.043e-7 (normalized top-1), below 5e-5.

BLOCKER: whole-model loading rejects the new E-block fixture with checkpoint has no tensor backbone.layers.2.mixer.up_proj.weight. CLI, oracle check, B4/N8 batch, cancellation, server CLI reference preparation, and all five hybrid integration tests fail before model inference. The same integration failure occurs on CPU and HIP. There is no token mismatch to report because model loading never completes.

Cause: Config::validate_recurrent_checkpoint in src/lib/mlxcel-xla/src/emitter/recurrent_checkpoint.rs treats every MixerKind::None block as dense MLP (around line 274), including E blocks. It requires dense up/down weights instead of checking is_moe_layer(li) and the routed/shared expert schema. Please fix and add checkpoint-validation coverage in the implementation branch; ROCm validation has made no production changes.

Reproducer after generating spike/openxla/nemotron_h_moe_fixture.py --out <fixture>: scripts/rocm_gpu_guard.sh --hold -- env MLXCEL_BACKEND=xla MLXCEL_XLA_DEVICE=hip MLXCEL_XLA_ROCM_TARGET=gfx1151 MLXCEL_XLA_PRECISION=f32 target/test-fast/mlxcel generate -m <fixture>/mlx -p 'tok4 tok17 tok5 tok29 tok11 tok8' -n 12 --temp 0 --no-chat-template. Integration reproducer: scripts/rocm_gpu_guard.sh --hold -- cargo test --profile test-fast --features xla-iree,test-utils --test xla_hybrid_nemotron_h -- --ignored --test-threads=1.

Environment note: direct MoE script invocation initially stopped at missing IREE Python modules. The successful oracle runs use a validation-only adapter /tmp/pr3411-moe-native-runtime.py invoking the installed, matching IREE compiler and native HIP-enabled iree-run-module with NPY inputs/outputs. Oracle calculations and emitted graphs are unchanged. Logs, command files and fixture: /home/devops/Development/mlxcel/acceptance/pr3411/c6ecdabc1898bb481e20e31cc687f7b8f2aa5bd5/. Mamba2 synthetic regression passes and real dense Nemotron-4B still matches its HF oracle 40/40; remaining regression gates are running. Full acceptance is FAILED pending the loader fix.

Validate Nemotron-H E blocks against their routed and shared expert schema instead of dense MLP names, including affine-packed companion tensors.

Lower grouped sigmoid routing argmax through compiler-compatible single-result reductions while preserving NaN and lower-index tie semantics. Keep the end-to-end acceptance fixture's independent output head and cover checkpoint loading with a complete synthetic model directory.

Refs #3345
@inureyes

inureyes commented Nov 24, 2026 •

Copy link
Copy Markdown
Member Author

Follow-up to the ROCm blocker report in #3411 (comment): the E-checkpoint loader and grouped-router compiler failures are fixed in 8466cabbfb596a15dfe7a2c912ed3d32670b54ae. The exact PR head for rerun is bf8188d20177cde215ca1b54c6444b86396bd8bd; its only additional change is the test-only environment-variable allowlist correction found by the canceled hosted run.

At the executable-code parent, the host library suite is 543 passed / 21 ignored, the seven local-task MoE oracle cases pass, guarded CUDA hybrid runtime is 5/5, and the tokenizer-backed CLI matches all 12 independent HF fp32 IDs. At the PR head, the environment-variable guard and its 15 focused Python tests pass. The corrected exact-head ROCm commands, including the required #3344 real-4B and Mamba2 reruns, are in the updated handoff: #3411 (comment).

The earlier c6 HIP results remain useful diagnosis but are not acceptance for the changed emitter. HIP validation remains pending, and the PR stays draft.

Classify the opt-in Nemotron-H golden rewrite switch with the existing fixture-authoring environment variables so the documentation guard does not treat it as an operator setting.

Refs #3345
@inureyes

Copy link
Copy Markdown
Member Author

ROCm rerun PASS at exact HEAD bf8188d20177cde215ca1b54c6444b86396bd8bd. The upstream loader/emitter fixes resolve the previously reported E-block failure; no additional production patch was needed.

Library 543 passed / 21 ignored, goldens, fmt and focused clippy pass. All seven primitive oracle cases pass on CPU and HIP. Hybrid integration is 5/5 on each device. The E-bearing fixture matches HF and parsed CLI IDs 12/12: [26, 2, 26, 26, 16, 27, 15, 27, 19, 15, 2, 15]. B4/N8, cancellation/recycling and four concurrent server completions pass. Real Nemotron-H-4B HF/CLI 40/40 and B4/N8 pass; Mamba2 synthetic and real-model oracle/batch regressions pass.

The initial server comparison was a harness false failure: re-decoding CLI IDs omitted <unk> and leading spacing. Comparing actual CLI stdout yields four exact matches; both logs are retained. This checks rendered HTTP text, not HTTP token IDs. The primitive oracle uses the previously documented native-runtime transport adapter.

Evidence: /home/devops/Development/mlxcel/acceptance/pr3411/bf8188d20177cde215ca1b54c6444b86396bd8bd/summary.json and adjacent commands/scripts/logs. Guarded sequential execution, optimized test-fast binaries, no performance or 30B capacity claim. No merge or issue closure performed.

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

area:architecture Architecture and code structure changes area:inference Generation, sampling, decoding (incl. speculative, DRY) priority:medium Medium priority status:review Under review type:enhancement New features, capabilities, or significant additions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant