feat(mega): add fused shared side-LoRA kernels - #9
Conversation
There was a problem hiding this comment.
Stale comment
Risk: high. Not approving: Cursor Bugbot finished skipped/neutral with 2 unresolved high-severity findings (undersized MXFP4 ready buffer; unsafe down-unweighted scratch reuse), and this ~16k-line fused side-LoRA CUDA change exceeds the low-risk auto-approval threshold. Human review is required for the MXFP4 buffer contract and backward scratch aliasing.
Sent by Cursor Approval Agent: Pull Request Approver
There was a problem hiding this comment.
Stale comment
Risk: high. Not approving: Cursor Bugbot completed skipped/neutral with 2 unresolved high-severity findings (undersized MXFP4 ready buffer; unsafe down-unweighted scratch reuse), and this ~16k-line fused side-LoRA CUDA change exceeds the low-risk auto-approval threshold. Human review is required; existing reviewer requests were left in place.
Sent by Cursor Approval Agent: Pull Request Approver
There was a problem hiding this comment.
Stale comment
Risk: high. Not approving: Cursor Bugbot passed with prior findings resolved and Security Agent was not running, but this large fused side-LoRA CUDA training change exceeds the low-risk auto-approval threshold. Human review is required; existing reviewer requests were left in place.
Sent by Cursor Approval Agent: Pull Request Approver
f323595 to
3e45539
Compare
There was a problem hiding this comment.
Stale comment
Risk: high. Left a non-blocking comment and did not approve: Cursor Bugbot completed as skipped with 2 unresolved findings (MXFP4 GeGLU backward; missing post-down fail-fast), and this fused side-LoRA CUDA training change exceeds the low-risk auto-approval threshold. Human review is required; existing reviewer requests were left in place.
Sent by Cursor Approval Agent: Pull Request Approver
There was a problem hiding this comment.
Stale comment
Risk: high. Left a non-blocking comment and did not approve: Cursor Bugbot completed as skipped with an unresolved medium finding (inconsistent MXFP4
fast_mathdefault), and this fused side-LoRA CUDA training change exceeds the low-risk auto-approval threshold. Human review is required; existing reviewer requests were left in place.Sent by Cursor Approval Agent: Pull Request Approver
There was a problem hiding this comment.
Stale comment
Risk: high. Left a non-blocking comment and did not approve: Cursor Bugbot passed with prior findings resolved and Security Agent was not running, but this fused side-LoRA CUDA training change exceeds the low-risk auto-approval threshold. Human review is required; existing reviewer requests were left in place.
Sent by Cursor Approval Agent: Pull Request Approver
1e1b4f7 to
ccaa442
Compare
There was a problem hiding this comment.
Risk: high. Left a non-blocking comment and did not approve: Cursor Bugbot completed as skipped with 1 unresolved high-severity finding (BF16 adapter grads use wrong planes), and this fused side-LoRA CUDA training change exceeds the low-risk auto-approval threshold. Human review is required; existing reviewer requests were left in place.
Sent by Cursor Approval Agent: Pull Request Approver
|
Acceptance audit at exact head
No additional full-model runtime sweep is required for this kernel acceptance seal. |
|
Repeatability attribution is now covered at head
This isolates the small replay drift to the shared atomic dispatch ordering rather than the side-LoRA backward contractions. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 1b92209. Configure here.
|
Accepted backward stack is now on this PR branch at Validation: host contracts 4/4; clean SM100 wheel; exact 4xB300 BF16 EP4 oracle at 262,144 total tokens/top-k 6/rank 128 is finite with min adapter-grad cosine 0.999942746, native-boundary shared-grad cosine 0.999999075, and grad-x cosine 0.999986239. FireTitan integration additionally passed two repeated 3-step BF16 F/B+AdamW trials bitwise exactly after production shared-factor gradient synchronization. |



Summary
Correctness coverage
The numerical harness checks BF16 and MXFP4 forward/backward against independent references and checks every adapter contraction again at the exact saved native kernel boundaries. Coverage includes:
The exact DSV4 Flash production-width sweep uses H=4096, I=2048, 256 experts, top-k 6, remote routing, and 20% masked routes. BF16 and MXFP4 cover all 15 token counts per rank:
1, 15, 16, 17, 90, 91, 176, 177, 346, 347, 688, 689, 1029, 1030, 2048These straddle every relevant BLOCK_M scheduling transition. The exact native-boundary adapter contractions remain above 0.9999 cosine. The independently dequantized PyTorch graph is retained as a separate approximate end-to-end quantization reference and is not substituted for the native-boundary gate.
At the exact 262,144-token EP4 FireTitan control shape:
All fused tensors are finite. Zero-scale BF16 and MXFP4 outputs remain bitwise identical to original MegaMoE.
Performance
B300 exact DSV4 Flash shape: EP4, 65,536 tokens/rank, 262,144 total, H=4096, I=2048, 256 experts, top-k 6. Control and candidate both use side-LoRA and include shared-factor EP reductions.
With the identical non-reentrant whole-MoE checkpoint wrapper:
Timing provenance remains the previously recorded B300 production-shape run; no old timing is relabeled as a post-rebase measurement.
Bounded MXFP4 scale storage
The symmetric arena now sizes scale-factor rows only for BLOCK_M regimes reachable at each live-token count and asserts the launch-time requirement. DSV4 EP4 one-wave provisioning uses 350,208 scale rows rather than the unreachable BLOCK_M=8 worst case. Together with the FireTitan one-wave token ring, the exact production arena falls from 10.794 GiB to 5.606 GiB without changing kernel arithmetic. Direct EP2 repeatability is bitwise exact for fused output and for all gradients when the saved forward boundary is held fixed.
Integration stack
This PR owns the standalone kernel ABI, edge-case correctness, and kernel-level performance contract. The private integration remains disabled by default and requires a trainer image containing this revision.
Historical validation (before the headroom update)
main/ fix(layout): support strided PSUM scale packing #114 passedHistorical source head:
b56ba1f57c89e1b6ac228bb9db4d409960e04484(acceptedc4d23b1+ff3ca21stack). The numerical/performance tables above are retained historical measurements, not a new headroom-on benchmark.2026-09-10: synchronize with main and cover side-LoRA headroom
Current source head:
d6fbae484c4cc7068aec00fe77ace9b1e273eb43.0913be4(including feat(mega): capture MXFP4 L1 pool across ring wraps #12 capture changes and mega_moe: configurable SM headroom on cooperative mega grids (DG_MEGA_MOE_SM_HEADROOM) #13 configurable SM headroom), preserving the accepted side-LoRA stack.DG_MEGA_MOE_SM_HEADROOMdefaults to 0 and rounds up to an even reservation; the explicitDG_BF16_MEGA_MOE_NUM_SMSforward override retains precedence. Ordinary dense adapter GEMMs are not indiscriminately capped.python tests/test_mega_moe_headroom.py -v— 4 tests passed, including 11 host-policy cases compiled from the actual C++ helper and launch-wiring checks.test_mega_moe_native_side_lora.py+test_mega_moe_headroom.py, CUDA hidden).Headroom remains a deployment-configured coexistence measure, not a guarantee against arbitrary concurrent kernels. This update does not claim a new NCCL overlap stress-test or full-model performance result.
Private trainer integration and trainer-dependent E2E sources remain outside this public repository.
Note
High Risk
Large new GPU training paths (distributed symmetric buffers, MXFP4 quantization, backward aliasing/memory modes) touch core MoE forward/backward; regressions would show up as silent wrong grads or OOM from buffer sizing.
Overview
Adds fused MegaMoE + rank-128 shared side-LoRA paths on SM100 for BF16 and MXFP4 base / BF16 adapters, exposed through new C++/pybind entry points and Python
megaAPIs (forward, backward, weight transform, and an extra symmetric-bufferside_lora_sourceplane for the MXFP4 specialization while keeping the legacy buffer ABI).The backward stack is a multi-phase native pipeline (persistent dgrad wave plus grouped/dense GEMMs, grad-x publish, adapter wgrads, padding clears) that returns grad-x, router grads, and six adapter gradients without full-width side scratch or frozen expert W13/W2 wgrads in the side-LoRA contract.
MXFP4 scale-factor ring storage no longer assumes every candidate
BLOCK_Mfills the full token ring; sizing follows reachable live-batch regimes viaget_num_max_required_sf_ring_tokens_for_mega_moe, with a launch-time assert in heuristics—reducing symmetric arena footprint for production shapes.JIT builds also pick up an extra CUTLASS include path, and
sm100_bf16_mega_moe_wgrad_1smgains optional row-strided inputs and a custom kernel name for side-LoRA wgrad reuse.Reviewed by Cursor Bugbot for commit b56ba1f. Bugbot is set up for automated code reviews on this repo. Configure here.