← Back to Pull requests

feat(moe_ep): SM120 Cake MegaMoE on any NCCL 2.30.7 or newer #9808

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Nov 21, 2026 03:14 UTC
Author

<!-- .github/pull_request_template.md -->

📌 Description

The SM120 Cake MegaMoE (moe_ep backend sm120_mxfp4_mxfp8_bf16_cake) and the nosync MegaMoE's GIN builds, which share its loader (flashinfer/moe_ep/shims/sm120/cake_mxfp4/cake_jit.py), only accept exactly NCCL 2.30.7. Projects that use NCCL 2.31+ elsewhere in the same process (DeepEP needs ≥ 2.31, for example) cannot use Cake at all. This PR replaces the exact pin with a version floor and checks for the conditions the kernel actually depends on.

Why 2.32.3 failed. With 2.32.3 headers the kernel compiles, but with a 128-byte stack frame (2.30.7: none), so the spill check (LOCAL_BYTES_LIMIT = 8) refuses it. This is not register pressure. NCCL 2.32 adds the EFA GDA GIN backend, enabled by default, and GIN_BACKENDS switches off only the three backends 2.30.7 knows, so every GIN call keeps an EFA branch.

| headers | GDAKI build, m128 / m64 | stack |
|---|---|---|
| 2.30.7 | 162 / 149 regs | 0 B |
| 2.32.3, current GIN_BACKENDS | 148 / 136 regs | 128 B (refused) |
| 2.32.3, + -DNCCL_GIN_EFA_GDA_ENABLE=0 | 164 / 148 regs | 0 B |

Changes

  • GIN_BACKENDS also passes -DNCCL_GIN_EFA_GDA_ENABLE=0. Before 2.32 the macro does not exist, so the flag is a no-op there.

  • Floor instead of a pin: NCCL 2.30.7 or newer (MIN_NCCL_VERSION_INTEGER; EXPECTED_NCCL_VERSION_INTEGER stays as an alias). The device code inlines the Device API and reads the ncclDevComm the library fills in, so what has to hold is "headers == the library in use", whatever its version.

  • - nccl_installation() now finds the libnccl.so.2 that defines ncclGetVersion (dladdr; torch's copy or an LD_PRELOAD one). Several copies can be mapped at once, because torch maps its wheel's copy by path.
    - It then takes headers of exactly that version: next to the library (<lib>/../include, the wheel layout), then under NCCL_HOME and the nvidia-nccl-cu13 wheel, skipping headers of other versions. Without matching headers, the error names the nvidia-nccl-cu13 version to install.
    - The binding's kExpectedNcclVersion is now NCCL_VERSION_CODE, so it refuses a library other than its own headers.
  • New hand-written header cake_sm120_megamoe_nccl_check.cuh. The loader force-includes it with nvcc -include into the device passes of Cake's instances and of the nosync GIN kernel. It asserts the version floor and that exactly one GIN backend is compiled in. A backend that a future NCCL adds therefore fails the build with a message naming GIN_BACKENDS, instead of a "spill" refusal at load time.

  • - The generated sources and the manifest's device section are untouched. Only the hand-written binding's digest changes.
    - The checks are device-pass only, because the nosync kernel includes the Device API in its device pass only.
    - Compiled with the header, the SASS is identical to the stock generated source on both NCCL versions.
  • JIT module names now include the NCCL (headers' path and version): the Cake binding, the nosync GIN kernel, and megamoe_sm120_gin_session. Without this, a shared JIT cache would reuse a module built against another NCCL. The session module has no runtime version check, so that reuse would go unnoticed.

  • README (runtime requirements, header lookup, GIN backend builds, file table), the host test's GIN_BACKENDS expectation (3 flags, EFA included), and two "2.30.7" messages updated.
  • Validation. 8× RTX PRO 6000 (SM120), PCIe + 4× 400G NICs, on this branch (rebased on ceb7af38) and on the earlier base 046ec14:

    | | NCCL 2.32.3 | NCCL 2.30.7 |
    |---|---|---|
    | tests/moe_ep/test_sm120_w4a8_cake_host.py | 43 passed | 43 passed |
    | tests/moe_ep/test_moe_ep_sm120_w4a8_cake_mega.py, all_gin (8 ranks) | 16 passed each | 16 passed each |
    | same, lsa_where_reachable (8 ranks) | 16 passed each | 16 passed each |
    | tests/moe_ep/test_moe_ep_sm120_w4a8_nosync_mega.py, FLASHINFER_TEST_MEGAMOE_SM120_NIC=1 | 39 passed, 2 skipped | 39 passed, 2 skipped |

  • Stock FlashInfer (046ec14) on NCCL 2.30.7 gives the same nosync result: 39 passed, 2 skipped.

  • Cake per-layer latency (DeepSeek-V4.1-Flash, EP8, lsa_where_reachable, graph replay, same node, 3 alternating rounds) is unchanged between 2.30.7 and 2.32.3 at 384 / 1024 / 2048 tokens per rank: within 1%. At 4096 tokens the round-to-round spread of each version (~11–20%) exceeds the difference between them.

  • Header lookup was checked for these layouts:

  • - the wheel only;
    - a stale NCCL_HOME;
    - an LD_PRELOADed 2.30.7 with headers next to it;
    - a library without headers, with NCCL_HOME set to matching headers and to mismatched ones.
  • With the old 2-flag GIN_BACKENDS on 2.32.3, the new assert fails the build.
  • Follow-up suggestions (not in this PR)

  • Optionally, an init-time known-answer self-test (one small dispatch/combine across ranks), and a CI matrix over the floor and the latest NCCL. Version checks cannot catch semantic changes in the Device API; these would.

  • The README says the device sources are generator output. If the maintainers prefer, the two asserts can move into the generator's template instead of the force-included header.

  • NCCL's ncclGin_BackendOne<backend> would remove the need for GIN_BACKENDS, but it currently cannot be used here: ncclGinBarrierSession and the signal/counter helpers (ncclGin_getSignalDescriptor, ncclGin_getCounterId) only accept the full ncclGin type, in both 2.30.7 and 2.32.3.
  • This PR was written with AI assistance (Claude Code). I reviewed the changes and the validation above.

    🔍 Related Issues

    None filed. Motivation: running Cake MegaMoE in a process that also uses NCCL 2.31+ (DeepSeek-V4.1-Flash serving on RTX PRO 6000).

    🚀 Pull Request Checklist

    Thank you for contributing to FlashInfer! Before we review your pull request, please make sure the following items are complete.

    ✅ Pre-commit Checks

  • I have installed pre-commit by running pip install pre-commit (or used your preferred method).

  • I have installed the hooks with pre-commit install.

  • I have run the hooks manually with pre-commit run --all-files and fixed any reported issues.

  • (Ran pre-commit run --files on every file this PR changes, not --all-files; all hooks pass.)

    If you are unsure about how to set up pre-commit, see the pre-commit documentation.

    🧪 Tests

  • Tests have been added or updated as needed.

  • All tests are passing (unittest, etc.).

  • This PR requires full-scope CI, not targeted tests (expensive; justify below).

  • Reason: <!-- e.g. cross-cutting change to shared infrastructure -->

    Suggested CI test targets (optional; paths under tests/, whitespace-separated — a starting
    point for @flashinfer-bot run <targets> / /bot run <targets>, reviewers may adjust): tests/moe_ep/test_sm120_w4a8_cake_host.py tests/moe_ep/test_moe_ep_sm120_w4a8_cake_mega.py tests/moe_ep/test_moe_ep_sm120_w4a8_nosync_mega.py

    🔬 Experimental Track

    <!-- Only for PRs submitted under the experimental policy (CONTRIBUTING.md → "Experimental APIs and Backends").
    Leave this section untouched for normal PRs. -->

  • This PR is experimental: it adds or changes code under flashinfer/experimental/ and/or an @flashinfer_experimental_api. Tracking issue: #

  • - [ ] The tracking issue names an owner, the reason for the experimental path, and a graduation plan with a target release.
    - [ ] Core changes are limited to a thin entry point (signature, shared validation, feature-gate check, backend selection, handoff).
    - [ ] Tests live in tests/experimental/ and were validated on the intended hardware; a runnable example is included.
    - [ ] Nothing is registered in flashinfer/aot.py, and no experimental backend is reachable from backend="auto" without FLASHINFER_ALLOW_EXPERIMENTAL_AUTO_BACKENDS=1. (Calling an @flashinfer_experimental_api or naming a backend explicitly is itself the opt-in and needs no environment variable.)
    - [ ] Test scope declared below. The experimental CI lane runs exactly these targets, so keep them as narrow as the change allows.

    <!-- Required for experimental PRs. Replace the commented lines below with your targets.
    Do not delete the fence or change its experimental-tests tag — the experimental-track
    watcher reads it verbatim to decide which targets to ask CI for. -->

    ``experimental-tests

    One target per line: a directory or a file. (A pytest ::selector is not


    supported -- the sharding runner cannot consume one.) Must be under


    tests/experimental/ and must exist. Delete these comment lines and add yours, e.g.


    # tests/experimental/test_my_backend.py


    tests/experimental/my_backend/


    # Declaring the whole tree (tests/experimental/) is allowed but means every


    experimental PR pays for every other feature's tests, in every matrix cell.


    `

    Reviewer Notes

  • The generated device sources (cake_sm120_megamoe_kernel.cuh, instance wrappers, geometry) and the manifest's device section are byte-identical to main. Only the hand-written binding, the loader, the new hand-written check header and the binding digest change.

  • Please check the header lookup order in nccl_installation() and the dladdr approach in loaded_nccl_library()`.
  • 🤖 Generated with Claude Code

    <!-- This is an auto-generated comment: release notes by coderabbit.ai -->
    <!-- coderabbit-ai-generated:v1 -->

    Summary by CodeRabbit

    New Features
    MegaMoE on SM120 now supports NCCL 2.30.7 and newer when the installed library and headers match.
    NCCL GIN builds support selecting among available backends, including EFA GDA, and reject configurations with multiple backends enabled.

    Bug Fixes
    NCCL-specific build artifacts now account for NCCL installation identity, reducing conflicts between installations.
    Version mismatch errors identify the build and runtime versions.

    Documentation
    * Updated NCCL requirements, backend options, and build checks.
    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: lucifer1004 Review duration: 22053m
    All Vouch review confidence checks passed
    Residual risk 0.30 = Change Risk (0.52) × (1 − Review Confidence (0.43)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    42%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #9808"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 43.0% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 43.0% · Lower = rushed or shallow review
    43.0%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 29.7% · Safe to merge
    29.7%