Skip to content

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

Merged
inureyes merged 6 commits into
mainfrom
feature/issue-3345-sigmoid-moe-router
Nov 25, 2026
Merged

inureyes merged 6 commits into
mainfrom
feature/issue-3345-sigmoid-moe-router

Conversation

@inureyes

@inureyes inureyes commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Add grouped sigmoid routing, correction-bias selection, relu2 routed/shared experts, and validated Nemotron-H E-block checkpoint loading. Compiler-compatible single-result reductions preserve first-NaN and lower-index tie semantics. Existing softmax MoE goldens remain byte-identical.

Runtime source 8466cab passed 543 library tests (21 ignored), seven local-task oracle cases, CUDA hybrid 5/5, and independent HF/CLI 12/12. Head bf8188d adds only a test-switch allowlist correction, with guard and 15 Python tests passing.

ROCm acceptance at bf8188d passes CPU/HIP primitive and hybrid gates, HF/CLI 12/12, B4/N8, cancellation/recycling, and concurrent HTTP rendered-text comparisons. Real Nemotron-H-4B HF/CLI 40/40 and batch plus Mamba2 synthetic/real-model regressions pass. HTTP token IDs were not exposed. Evidence: #3411 (comment).

Hosted CI was intentionally canceled; merge relies on local and reported hardware validation. The final documentation commit changes no executable source. Whole-f32 uploads, dense all-expert execution, real 30B capacity and throughput remain #3350 concerns.

Closes #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.

@inureyes
inureyes marked this pull request as ready for review November 25, 2026 07:03
@inureyes
inureyes merged commit aec5eb1 into main Nov 25, 2026
26 of 33 checks passed
@inureyes
inureyes deleted the feature/issue-3345-sigmoid-moe-router branch November 25, 2026 07:04
@inureyes inureyes added status:done Completed and removed status:review Under review labels Nov 25, 2026
inureyes added a commit that referenced this pull request Nov 25, 2026
## Summary

- add an f32 diagonal selective scan and Mamba1 mixer for prefill and batched decode
- keep prefill chunk-bounded and compile-efficient with a log-depth affine prefix scan inside each 128-row chunk
- parse and validate Mamba and Falcon-Mamba configs, legacy bias aliases, checkpoint tensors, weight names, and threaded `[L,D,N]` state
- extend the independent Transformers oracle and whole-model IREE harness, including synthetic Falcon-Mamba B/C/dt RMS normalization
- register a compact whole-model Mamba decode golden and add English and Korean technical reports

## Correctness and integration fixes

- honor the original `bias` / `conv_bias` aliases while giving canonical `use_bias` / `use_conv_bias` keys precedence
- reject unsupported `rms_norm = false` configs and require every active block or mixer epsilon to be finite and positive
- replace the row-by-row prefill unroll with a chunk-local, log-depth associative affine scan
- construct `log_a` and `bx` inside the mixer chunk loop, so capacity 4096 never creates a full `[4096,D,N]` producer
- preserve the merged Nemotron-H compact KV indexing, grouped normalization, hybrid state carry, MoE paths, and registered Mamba2/Nemotron-H golden bytes
- document `MLXCEL_FREEZE_MAMBA1` and remove the duplicate Nemotron-H allowlist entry that caused the hosted environment-variable documentation jobs to fail

## Integrated validation

The executable source for the final integrated checks is `abd1520fd669624cb668bd558b98e332d0955093`, based on merged PR #3411. The final branch adds only the bilingual reports after that source commit.

- `cargo fmt --all -- --check`
- `cargo clippy -p mlxcel-xla --lib -- -D warnings`
- `cargo test -p mlxcel-xla --lib -- --test-threads=4` (555 passed, 21 ignored)
- `cargo test -p mlxcel-xla --lib validation::tests::registered_fixtures_are_byte_exact -- --exact --test-threads=1` (Mamba1, Mamba2, and Nemotron-H registered goldens byte-exact)
- `python3 scripts/ci/check_env_var_docs.py` (396 discovered, 265 documented, 131 allowlisted)
- `python3 -m unittest discover -s tests -p 'test_check_env_var_docs.py' -v` (15 passed)
- official `state-spaces/mamba-130m-hf@1e76775f628fbf1350fbe4dbb3d971ba64af25a1` on IREE local-task: whole prefill, split prefill, and decode match the independent Transformers 5.12.1 CPU fp32 reference; worst max-abs `1.488e-4`, same argmax
- seeded synthetic `FalconMambaForCausalLM` on IREE local-task: whole prefill, split prefill, and decode match the independent reference; worst max-abs `3.725e-7`, same argmax
- capacity 4096, `D=1536`, `N=16`: no `[4096,D,N]` tensor; 3,116-line / 320-KiB StableHLO; direct CPU compile 10.64 s at 228.2 MiB peak RSS; run 0.862 s

## Exact integrated CUDA acceptance

On NVIDIA GB10, source `abd1520fd669624cb668bd558b98e332d0955093` passed the capacity-4096 CUDA probe under `gpu-lock`:

- compile 5.03 s, run 0.319 s
- process peak RSS 203200 KiB
- independent oracle max-abs: output `3.651e-7`, recurrent state `1.141e-8`, convolution state `1.371e-6`
- timing log: `/tmp/epic564-plan/3348-cuda-cap4096-integrated-abd1520f-time.log`
- result bundle: `/tmp/issue3348-cap4096-integrated-abd1520f`

This establishes correctness and compile footprint, not a throughput claim.

## ROCm acceptance and source boundary

External ROCm gfx1151 acceptance passed at exact source `3a1688f7daaf9bae8bea09997b804e6509357c25`:

- library tests, formatting, clippy, and registered goldens
- 12 local-task and HIP mixer-probe cases, including capacity 4096
- real Mamba and synthetic Falcon reference and CLI parity (40/40 tokens)
- B4/N8 batching, cancellation, slot recycling, and four concurrent server requests
- five hybrid tests, Mamba2 synthetic and real regressions, and real Nemotron-H 4B integration checks

All ROCm device/build work used the ROCm guard. Server checks compare rendered text because the HTTP API does not expose token IDs. Optimized `test-fast` binaries make no performance claim. Full commands and provenance are in the [ROCm acceptance record](#3413 (comment)).

The later rebase onto PR #3411 did not change the blobs for the Mamba1 scan, parser, recurrent emitter, or Python oracle. It added disjoint Nemotron-H MoE integration and the CI allowlist correction. Full library, golden, lint, environment-variable, and CUDA gates were rerun on the integrated source; ROCm was not rerun after this source-neutral integration, so the exact-SHA evidence boundary is retained here.

## Reports

- `TECHNICAL_REPORTS/3413-mamba1-falcon-mamba-selective-scan-20261125.en.md`
- `TECHNICAL_REPORTS/3413-mamba1-falcon-mamba-selective-scan-20261125.ko.md`

Closes #3348
inureyes added a commit that referenced this pull request Nov 25, 2026
Add original-HF Falcon-H1 execution with parallel attention/Mamba2 followed by a separately normalized MLP. Preserve HF muP placement, optional SSM normalization, independent head widths/biases, and dual KV/recurrent state across prefill, single decode, and ragged decode. Integration retains #3411 MoE and #3413 Mamba1 behavior.

Fix plain CLI completion display losing trailing whitespace: an explicit flush mode preserves raw text while default chat and structured reasoning/tool/Harmony/Muse cleanup remain unchanged. The portable replay compares actual stdout with concurrent non-streaming HTTP and SSE responses; earlier CUDA HTTP evidence compared raw token decoding, not displayed stdout.

Validation at integrated runtime source `8c7b4412d37b91807f8d688ba2f3febbc7a7e41f` (base `2e46fc09`):

- Full XLA crate: 560 passed / 22 ignored; byte-exact goldens, every-family layouts, fmt, and narrow clippy pass. Environment-docs checker + 15 Python tests pass after classifying two test-only controls.
- All 7 display tests and 146 filter tests pass; all 5 CUDA hybrid tests and all 6 Mamba2 tests pass.
- CPU/CUDA synthetic norm/ragged/recycle gates and real HF40/40 pass; CUDA CLI40/40 passes.
- Strict displayed stdout: 4/4 nonstream + 4/4 SSE text/count matches, including Germany's exact trailing whitespace; overlapping requests and server cleanup verified.

External HIP acceptance at `852129eb` passed numerical, real 40-token CLI, batching/recycling, regression, and release architecture gates. Strict displayed CLI/SSE parity was 3/4 because Germany ended in `"  \n"`; all four raw token decodes matched. That evidence predates this fix and merged shared recurrent plumbing. Request a final-head ROCm replay with explicit `hip`, `gfx1151`, and `f32` under the ROCm guard; no new HIP run is claimed.

Oracle, provenance, logs, portable replay, and instructions are in `spike/openxla/falcon_h1_reference` and `FINDINGS_falcon_h1.md`; bilingual reports document the exact evidence boundaries. HTTP exposes text/counts, not output IDs. Hosted CI is canceled under the local-validation policy.

Refs #3346
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:done Completed type:enhancement New features, capabilities, or significant additions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(xla): sigmoid score-correction MoE router and relu2 experts

1 participant