Skip to content

[None][feat] Update CuTeDSL MegaMoE kernels - #16190

Merged
Barry-Delaney merged 10 commits into
NVIDIA:mainfrom
Barry-Delaney:user/jinshik/dsv4-megamoe-cutedsl-adaptive-maxt
Jul 29, 2026
Merged

[None][feat] Update CuTeDSL MegaMoE kernels#16190
Barry-Delaney merged 10 commits into
NVIDIA:mainfrom
Barry-Delaney:user/jinshik/dsv4-megamoe-cutedsl-adaptive-maxt

Conversation

@Barry-Delaney

@Barry-Delaney Barry-Delaney commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Dev Engineer Review

  • Large CuTeDSL MegaMoE NVFP4 update refactors host/kernel ABI around a JSON-friendly 8-tuple tactic format driven by a token-bucket (num_tokens), with new default_/enumerate_/validate_megamoe_tactic(num_tokens) and stricter 8-field validation (including flag_batch/epi_flag_batch).
  • Introduces opt-in tactic autotuning (tactic_autotune + explicit AutoTuner.choose_one) while default execution remains deterministic (tactic=-1), including updated runner/op caching and workspace behavior for CUDA-graph capture safety (fenced-reset tracking with capture guards; reduced/targeted workspace zeroing; safer workspace caching keyed to tactic).
  • Adds/threads new correctness/perf knobs across the stack:
    • in_kernel_fc2_reduce and combine_format (including symmetric memory contract updates such as combine_output shape and symm provider combine_k=1).
    • Pointer-based workspace contracts (cute.Pointer/byte-base view) and revised region sizing/zero-prefix logic.
  • Token communication and token-back:
    • Adds CombineFormat + packed TokenSrcMetadata, reworks token-back scheduling with batching via GpuReleaseFlagBatchTracker, new combine/scratch buffers (combine_sf/fc2_output_sf), and updated NVLink barrier + tail-reset ordering.
    • Adds PTX helper wrappers and refactors FC1/FC2 epilogue routing/quantization to centralize combine/quant logic and simplify contract plumbing.
  • Kernel/scheduler and fused-API changes:
    • Updates scheduler/token-validity fields to use valid_tokens_in_cta_tile (swap-AB vs non-swap paths) and adjusts related counters/sentinels.
    • Changes outputs to return output_activation (internally collapsing the combine/topk dimension) and aligns multi-rank launch token bucketing via set_adaptive_launch_tokens.
  • Backend/API/config surface:
    • Adds MEGAMOE_CUTEDSL backend support across LLM API config, microbenchmark backend registry, and fused-comm scheduling candidate logic.
    • Updates developer docs (tactic representation guidance; distributed tuning strategy guidance).
  • NVFP4 weight lifecycle:
    • Disables hot weight reloading; implements streamed-weight source freeing and tight validation for partial auxiliary-scale coverage; adds/uses streamed transient locking during rematerialization.

Key review focus areas:

  • CUDA-graph fencing/capture guards correctness (reset/ABA tracking keyed by workspace pointers and world size).
  • Tactic layout compatibility across custom-op wrapper, runner, and kernel; ensure validate_megamoe_tactic enforces the intended field order everywhere.
  • Combine-format compatibility end-to-end (combine_format → symm provider sizing/contracts → kernel epilogue/quant/dequant paths).
  • Token-back scheduling (metadata packing/unpacking, tracker batching, NVLink barrier + tail counter reset ordering, and multi-rank routing expectations).
  • Workspace pointer arithmetic and region contracts (local/shared views, zero-prefix sizing, reduced zeroing correctness).
  • Distributed invariants introduced for CuteDSL EP/WORLD sizing and rendezvous init consistency (MPI-aware bootstrapping).

QA Engineer Review

Tests list changes (test-db/)

  • Modified: tests/integration/test_lists/test-db/l0_b200.yml
    • Added entry: unittest/_torch/modules/moe/test_megamoe_streaming_load.py

Verdict: needs follow-up (CBTS/CI coverage data for the newly added backend/unit tests is not provided here; however the streaming-load test is explicitly added to test-db.)

Test code changes (outside test-list)

  • Modified/added: tests/unittest/_torch/modules/moe/test_megamoe_streaming_load.py

    • Added tests:
      • test_initial_streaming_load_layer_atomic
      • test_partial_load_rejected_before_source_materialization
    • Coverage in test-db/qa/ lists: covered by tests/integration/test_lists/test-db/l0_b200.yml (added entry above).
    • Verdict: sufficient for this module.
  • Modified/added: tests/unittest/_torch/modules/moe/test_moe_backend.py

    • Added tests:
      • Verifies launch-max token bucket selection behavior under tuning mode
      • Verifies moe.tactic_autotune defaulting when env var unset
      • Verifies enumerate_megamoe_candidate_tactics/default_megamoe_tactic/validate_megamoe_tactic (including invalid tactic error)
    • Coverage in test-db/qa/ lists: not listed in the provided test-db change.
    • Verdict: needs follow-up (to confirm CI inclusion for these unit tests, and to validate distributed/CUDA graph/token-back paths under CI coverage).

@Barry-Delaney Barry-Delaney self-assigned this Jul 9, 2026
@Barry-Delaney
Barry-Delaney force-pushed the user/jinshik/dsv4-megamoe-cutedsl-adaptive-maxt branch 11 times, most recently from d4cb10a to 5cded49 Compare July 17, 2026 04:39
@Barry-Delaney Barry-Delaney added the api-compatible Accepted LLM API contract change that is backwards-compatible label Jul 17, 2026
@Barry-Delaney
Barry-Delaney force-pushed the user/jinshik/dsv4-megamoe-cutedsl-adaptive-maxt branch from 06e6965 to 468c64a Compare July 17, 2026 09:57
@Barry-Delaney
Barry-Delaney marked this pull request as ready for review July 17, 2026 09:57
@Barry-Delaney
Barry-Delaney requested review from a team as code owners July 17, 2026 09:57
@Barry-Delaney
Barry-Delaney removed the request for review from litaotju July 27, 2026 09:09
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61875 [ run ] triggered by Bot. Commit: bea62a0 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61839 [ run ] completed with state ABORTED. Commit: bea62a0

Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61875 [ run ] completed with state FAILURE. Commit: bea62a0
/LLM/main/L0_MergeRequest_PR pipeline #50066 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

…Seek-V4

Add the MegaMoE-CuteDSL MoE backend (moe_config.backend=MEGAMOE_CUTEDSL):
a pure cute.compile JIT integration of the MegaMoE NVFP4 swap-AB kernel
(vendored under cute_dsl_kernels/mega_moe_nvfp4) for DeepSeek-V4 DEP
serving on Blackwell.

- Vendored kernel package: dispatch/combine token communication with
  NVLink sense-reversing barriers, swap-AB FC1/FC2 scheduling, NVFP4
  epilogue with E8M0 scale conversion, adaptive grid sizing.
- Custom op wrapper: workspace/fence lifecycle keyed on symmetric-buffer
  identity with storage-weakref liveness (a recycled allocation address
  can never skip the barrier-reset fence; capture-safe eviction, latched
  tuning workspaces, lazy profiling scratch released after autotuner
  warmup), adaptive max-tokens bucket ladder.
- Tactic autotuning is an explicit opt-in (tactic_autotune backend
  constructor parameter, default OFF): serving always uses the
  deterministic heuristic tactic even under global autotuner warmup;
  the microbenchmark's --autotune enables the sweep, which then runs
  through the standard AutoTuner (tuning mode only). The curated
  reduced space is the only tuning space.
- Cross-rank combine wire format is an explicit, validated backend
  constructor parameter (bf16 default; 32e4m3xe8m0 / 16e2m1xbf16 for
  benchmarking, threaded create_moe -> backend -> op and part of the
  workspace/provider cache keys; quantized formats use separate-reduce
  and disable the incompatible in-kernel reduce). No environment
  variables besides MEGAMOE_MPI_INIT_TORCH_DIST (opt-out of the
  process-level torch.distributed bootstrap).
- Backend module wires the staged post-load hooks (transform_weights /
  cache_derived_state), free-port MPI bootstrap for multi-rank tuning,
  and fail-fast guards for unsupported configs (EPLB reload, pure-DEP
  requirement).
- moe_config.backend gains the MEGAMOE_CUTEDSL literal (golden manifest
  regenerated); model_engine releases the profiling scratch at the end
  of autotuner warmup.

Signed-off-by: Barry Kang <43644113+Barry-Delaney@users.noreply.github.com>
… MegaMoE-CuteDSL

- DSv4 model wiring: swiglu clamp forwarded in tensor form, fused-A /
  kv_b_proj atomic weight groups with module-state-keyed required sets,
  cross-RPC partial-group stash with covering-resend audit
  (bucket keys pre-registered per cycle, aborts union them into a
  tainted set that only a covering sweep clears), and a sticky
  abort-cycle protocol exposed as the duck-typed abort_reload_cycle
  hook.
- attn_sink is a module-owned parameter (graph-stable storage created
  at construction, in-place refresh on load, value-preserving staged
  hooks) so checkpoint sinks survive CUDA-graph capture, dummy init and
  direct-transport loads; dummy weight init skips .attn_sink and
  memory-tagged allocation preserves constructor values.
- Streaming source load for the MegaMoE-CuteDSL quant method: 0-element
  placeholders materialized per load, eager per-module finalize once
  coverage completes (CPU staging on partial reloads keeps the GPU peak
  order-independent), per-expert-row streamed coverage guard, and
  cycle-start purge of per-cycle quant transients
  (_RELOAD_TRANSIENT_ATTRS) so an aborted cycle's scales can never
  surface in the recovery cycle's finalize.
- Reload correctness guards shared by Linear/MoE: per-unit
  reload-coverage debt recorded before pre-reload re-registration and
  consumed only by keys actually rewritten, with finalize refusing
  while units are outstanding; a side-effect-free
  check_reload_capability preflight refuses EPLB/non-partial-capable
  quant methods before the destructive walk; the update_weights
  exception boundary aborts the cycle (latch cleared, duck-typed model
  hook) and abort_update_weights lets a coordinator broadcast the same
  abort to every rank.

Signed-off-by: Barry Kang <43644113+Barry-Delaney@users.noreply.github.com>
Self-contained kernel microbench over the public create_moe/forward
path: synthetic NVFP4 weights, EP/DEP via mpirun, sweeps
tokens-per-rank / combine wire format (passed explicitly to the
backend constructor), --autotune opting into the MegaMoE tactic sweep
through the standard AutoTuner (eager and --cuda-graph timing modes),
free-port bootstrap and between-point workspace reset so repeated
points are independent.

Signed-off-by: Barry Kang <43644113+Barry-Delaney@users.noreply.github.com>
Signed-off-by: Barry Kang <43644113+Barry-Delaney@users.noreply.github.com>
Signed-off-by: Barry Kang <43644113+Barry-Delaney@users.noreply.github.com>
Signed-off-by: Barry Kang <43644113+Barry-Delaney@users.noreply.github.com>
Signed-off-by: Barry Kang <43644113+Barry-Delaney@users.noreply.github.com>
Signed-off-by: Barry Kang <43644113+Barry-Delaney@users.noreply.github.com>
Signed-off-by: Barry Kang <43644113+Barry-Delaney@users.noreply.github.com>
Signed-off-by: Barry Kang <43644113+Barry-Delaney@users.noreply.github.com>
@Barry-Delaney
Barry-Delaney force-pushed the user/jinshik/dsv4-megamoe-cutedsl-adaptive-maxt branch from bea62a0 to 6283748 Compare July 27, 2026 17:17
@Barry-Delaney

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61953 [ run ] triggered by Bot. Commit: 6283748 Link to invocation

@coderabbitai coderabbitai 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.

Actionable comments posted: 7

🧹 Nitpick comments (8)
tensorrt_llm/_torch/cute_dsl_kernels/mega_moe_nvfp4/epilogue_refactor.py (5)

1233-1244: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Nit: docstring grammar and _frozen_ naming.

"Froze at the point calling _freeze()" reads as a typo — e.g. "Attributes become read-only once _freeze() is called." Also _frozen_ (trailing underscore) is unidiomatic; _frozen matches the rest of the file.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tensorrt_llm/_torch/cute_dsl_kernels/mega_moe_nvfp4/epilogue_refactor.py`
around lines 1233 - 1244, Update _ImmutableAfterInit’s docstring to clearly
state that attributes become read-only when _freeze() is called, and rename the
internal _frozen_ flag to _frozen consistently in __setattr__ and _freeze.

49-74: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low value

has_side_effects=True on a pure conversion blocks CSE/hoisting.

cvt_f32_to_ue8m0_to_f32 is a value-in/value-out conversion with no memory or state effects, yet it is marked as having side effects; the sibling max_abs helpers in QuantImpl correctly pass False. It is invoked once per scale block in the mxfp8 loops, so marking it pure lets the compiler dedupe/schedule it.

♻️ Proposed change
         asm_tmpl,
         "=r,f",
-        has_side_effects=True,
+        has_side_effects=False,
         is_align_stack=False,
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tensorrt_llm/_torch/cute_dsl_kernels/mega_moe_nvfp4/epilogue_refactor.py`
around lines 49 - 74, Update the llvm.inline_asm call in cvt_f32_to_ue8m0_to_f32
to mark the conversion as side-effect-free by passing False for
has_side_effects, matching the pure max_abs helper usage in QuantImpl.

2708-2725: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Nit: packed_i32 is recast to Float32, not Int32.

The name says i32 while the recast (and the reg_tensor fed to the transposes) is cutlass.Float32 used purely as a 32-bit bit-carrier for bf16x2. In bit-manipulation code that mismatch is easy to trip over — packed_b32 or packed_bf16x2 would read truer.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tensorrt_llm/_torch/cute_dsl_kernels/mega_moe_nvfp4/epilogue_refactor.py`
around lines 2708 - 2725, Rename packed_i32 to a name that reflects its Float32
bit-carrier role, such as packed_b32 or packed_bf16x2, throughout the transpose
setup and autovec_copy calls. Preserve the existing cutlass.Float32 recast and
tensor behavior.

97-99: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Annotate lane_idx with its real type instead of Any.

The comment already documents it as Int32; Optional[cutlass.Int32] makes the field self-describing and the across-lane precondition in __post_init__ easier to read.

As per coding guidelines: "avoid Any and unnecessary type ignores".

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tensorrt_llm/_torch/cute_dsl_kernels/mega_moe_nvfp4/epilogue_refactor.py`
around lines 97 - 99, Update the lane_idx annotation in the relevant dataclass
to use Optional[cutlass.Int32] instead of Optional[Any], preserving its optional
default and existing across-lane behavior. Remove any now-unused Any import if
applicable.

Source: Coding guidelines


1828-1833: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low value

Consider asserting the single-block assumption behind sfc_regs[0].

sfc_regs has cute.size(weighted) // sf_vec_size entries; taking [0] is only correct while that is exactly 1 (true today: 16 regs / 16). A one-line const_expr check documents and enforces it.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tensorrt_llm/_torch/cute_dsl_kernels/mega_moe_nvfp4/epilogue_refactor.py`
around lines 1828 - 1833, In the quantization flow around `quant(weighted,
norm_const=norm_const)`, add a `const_expr` assertion that `cute.size(weighted)
// sf_vec_size` equals 1 before accessing `sfc_regs[0]`. Preserve the existing
single-block behavior while enforcing the assumption explicitly.
tensorrt_llm/_torch/cute_dsl_kernels/mega_moe_nvfp4/kernel_fc12.py (2)

350-366: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Initialize combine_format in __init__ instead of lazily in _setup_attributes.

_setup_attributes() runs per __call__, so the hasattr guard is doing double duty as both "subclass injected it" and "already defaulted". Setting self.combine_format = getattr(self, "combine_format", None) or CombineFormat.parse("bf16") in the constructor (after the subclass hook point) keeps the externally visible member owned by __init__ and drops the trace-time hasattr.

As per coding guidelines: "initialize externally visible class members in the constructor".

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tensorrt_llm/_torch/cute_dsl_kernels/mega_moe_nvfp4/kernel_fc12.py` around
lines 350 - 366, Move the default initialization of combine_format from
_setup_attributes into the constructor, after the MegaMoE subclass injection
hook, using the existing value when present and parsing bf16 only when absent or
unset. Then remove the hasattr-based fallback from _setup_attributes while
continuing to pass self.combine_format to SwapABSwigluFp4Epilogue.

Source: Coding guidelines


799-812: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Validation reads well; consider cute.round_up for the local helper.

cute.round_up is already used elsewhere in this class (_setup_attributes), so the local round_up is a small duplicate. Also, the two nested cutlass.const_expr guards could collapse into one and.

Also applies to: 846-869

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tensorrt_llm/_torch/cute_dsl_kernels/mega_moe_nvfp4/kernel_fc12.py` around
lines 799 - 812, Replace the local round_up helper in the enclosing kernel
method with the existing cute.round_up utility, matching its use in
_setup_attributes. Simplify the nested cutlass.const_expr guards in the affected
sections around the tensor layout and related validation into a single guard
using and, while preserving the current compile-time conditions and behavior.
tensorrt_llm/_torch/modules/fused_moe/mega_moe/mega_moe_cute_dsl.py (1)

774-782: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Narrow the bootstrap exception.

except Exception here also swallows programming errors from the import/attribute path and downgrades them to a debug log, leaving torch.distributed silently uninitialized so the failure resurfaces later as an opaque rendezvous error. Catch the concrete failures instead.

As per coding guidelines: "Catch specific exceptions rather than using broad or bare exception handling such as except:".

♻️ Proposed change
-        except Exception as e:  # not under MPI either -> leave uninitialized
+        except (ImportError, RuntimeError, AttributeError) as e:
+            # not under MPI either -> leave uninitialized
             logger.debug(
                 f"[MegaMoECuteDsl] MPI rank query failed ({e!r}); "
                 "skipping torch.distributed bootstrap."
             )
             return
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tensorrt_llm/_torch/modules/fused_moe/mega_moe/mega_moe_cute_dsl.py` around
lines 774 - 782, Update the MPI query exception handling around mpi_world_size()
and mpi_rank() to catch only the concrete exceptions those calls use to indicate
that MPI is unavailable, rather than broad Exception. Preserve the debug log and
early return for that expected non-MPI case, while allowing programming or
import/attribute errors to propagate.

Sources: Coding guidelines, Linters/SAST tools

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tensorrt_llm/_torch/cute_dsl_kernels/mega_moe_nvfp4/epilogue_refactor.py`:
- Around line 2312-2323: Extract the shared STG alignment calculation into a
cached router property named _data_stg_align_bytes, using the existing
data_output element width formula without the redundant nested min. Update both
prefetch and get_data_dst to pass this property as byte_align and assumed_align
respectively, removing their duplicated inline calculations.
- Around line 1045-1048: Update epi_flag_batch handling in the epilogue
initialization and Sm100SwapABSwigluFp4Fc12Kernel.name() so the value used for
kernel behavior matches the cache-key value. Reject values outside [1, 32]
before storing or naming them, or normalize them before name() reads them; do
not silently retain raw out-of-range values that generate distinct keys for
identical kernels.
- Around line 2288-2294: Remove the unreachable self.metadata is None branch
from the destination-pointer logic after prefetch, and de-indent the remaining
metadata-dependent body accordingly. Keep destination address computation
centralized through get_data_dst and preserve the existing metadata path
behavior.
- Around line 491-502: Update _amax_lane’s sf_vec_size == 16 path so all lanes
execute both warp reductions: compute separate masked maxima for the lower and
upper 16-lane halves, then select the result based on first_half. Remove the
divergent if (!first_half) reduction and ensure each block’s amax only includes
its own 16 lanes.
- Around line 2942-2948: Update the copy_bytes calculation in the epilogue copy
path so 4-bit combine formats round the byte count up when copy_elems is odd,
preserving the trailing half-byte element; keep the existing calculation
unchanged for byte-aligned formats and retain the valid_hidden_this_cta_tile
bounds behavior.
- Around line 1976-1997: Add an explicit constructor precondition in
SwapABFc2Epilogue.__init__ (or SwapABSwigluFp4Epilogue.__init__) requiring
token_comm_args when combine_format.is_quantized is true. Reject the invalid
combination before tracing so accesses to token_comm_args.fc2_output_sf and
fc2_done_counter remain safe.

In `@tensorrt_llm/_torch/cute_dsl_kernels/mega_moe_nvfp4/kernel_fc12.py`:
- Around line 912-941: Rename the later `intermediate_downproj_padded` binding
used for the fc2 weight-SF view to a distinct descriptive symbol, while
preserving the earlier value used by `fc1_output_sf_gemm_for_fc2_load`. Update
all references in the `tile_atom_to_shape_SF` arguments and the `ValueError`
message to use the new symbol.

---

Nitpick comments:
In `@tensorrt_llm/_torch/cute_dsl_kernels/mega_moe_nvfp4/epilogue_refactor.py`:
- Around line 1233-1244: Update _ImmutableAfterInit’s docstring to clearly state
that attributes become read-only when _freeze() is called, and rename the
internal _frozen_ flag to _frozen consistently in __setattr__ and _freeze.
- Around line 49-74: Update the llvm.inline_asm call in cvt_f32_to_ue8m0_to_f32
to mark the conversion as side-effect-free by passing False for
has_side_effects, matching the pure max_abs helper usage in QuantImpl.
- Around line 2708-2725: Rename packed_i32 to a name that reflects its Float32
bit-carrier role, such as packed_b32 or packed_bf16x2, throughout the transpose
setup and autovec_copy calls. Preserve the existing cutlass.Float32 recast and
tensor behavior.
- Around line 97-99: Update the lane_idx annotation in the relevant dataclass to
use Optional[cutlass.Int32] instead of Optional[Any], preserving its optional
default and existing across-lane behavior. Remove any now-unused Any import if
applicable.
- Around line 1828-1833: In the quantization flow around `quant(weighted,
norm_const=norm_const)`, add a `const_expr` assertion that `cute.size(weighted)
// sf_vec_size` equals 1 before accessing `sfc_regs[0]`. Preserve the existing
single-block behavior while enforcing the assumption explicitly.

In `@tensorrt_llm/_torch/cute_dsl_kernels/mega_moe_nvfp4/kernel_fc12.py`:
- Around line 350-366: Move the default initialization of combine_format from
_setup_attributes into the constructor, after the MegaMoE subclass injection
hook, using the existing value when present and parsing bf16 only when absent or
unset. Then remove the hasattr-based fallback from _setup_attributes while
continuing to pass self.combine_format to SwapABSwigluFp4Epilogue.
- Around line 799-812: Replace the local round_up helper in the enclosing kernel
method with the existing cute.round_up utility, matching its use in
_setup_attributes. Simplify the nested cutlass.const_expr guards in the affected
sections around the tensor layout and related validation into a single guard
using and, while preserving the current compile-time conditions and behavior.

In `@tensorrt_llm/_torch/modules/fused_moe/mega_moe/mega_moe_cute_dsl.py`:
- Around line 774-782: Update the MPI query exception handling around
mpi_world_size() and mpi_rank() to catch only the concrete exceptions those
calls use to indicate that MPI is unavailable, rather than broad Exception.
Preserve the debug log and early return for that expected non-MPI case, while
allowing programming or import/attribute errors to propagate.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: c4ea1b52-e5a8-4e6a-80d6-e1511658bf39

📥 Commits

Reviewing files that changed from the base of the PR and between bea62a0 and 6283748.

📒 Files selected for processing (32)
  • tensorrt_llm/_torch/custom_ops/cute_dsl_megamoe_custom_op.py
  • tensorrt_llm/_torch/cute_dsl_kernels/mega_moe_nvfp4/__init__.py
  • tensorrt_llm/_torch/cute_dsl_kernels/mega_moe_nvfp4/contract.py
  • tensorrt_llm/_torch/cute_dsl_kernels/mega_moe_nvfp4/custom_ext.py
  • tensorrt_llm/_torch/cute_dsl_kernels/mega_moe_nvfp4/epilogue_refactor.py
  • tensorrt_llm/_torch/cute_dsl_kernels/mega_moe_nvfp4/fc1_fc2_fuse_sched.py
  • tensorrt_llm/_torch/cute_dsl_kernels/mega_moe_nvfp4/flag_batch.py
  • tensorrt_llm/_torch/cute_dsl_kernels/mega_moe_nvfp4/grid_sync.py
  • tensorrt_llm/_torch/cute_dsl_kernels/mega_moe_nvfp4/kernel_fc12.py
  • tensorrt_llm/_torch/cute_dsl_kernels/mega_moe_nvfp4/megamoe_constants.py
  • tensorrt_llm/_torch/cute_dsl_kernels/mega_moe_nvfp4/megamoe_kernel.py
  • tensorrt_llm/_torch/cute_dsl_kernels/mega_moe_nvfp4/moe_utils.py
  • tensorrt_llm/_torch/cute_dsl_kernels/mega_moe_nvfp4/ptx_helpers.py
  • tensorrt_llm/_torch/cute_dsl_kernels/mega_moe_nvfp4/sym_buffer.py
  • tensorrt_llm/_torch/cute_dsl_kernels/mega_moe_nvfp4/token_comm.py
  • tensorrt_llm/_torch/cute_dsl_kernels/mega_moe_nvfp4/topk_reduce.py
  • tensorrt_llm/_torch/modules/fused_moe/MOE_DEVELOPER_GUIDE.md
  • tensorrt_llm/_torch/modules/fused_moe/create_moe.py
  • tensorrt_llm/_torch/modules/fused_moe/mega_moe/mega_moe_cute_dsl.py
  • tensorrt_llm/_torch/modules/fused_moe/moe_scheduler.py
  • tensorrt_llm/_torch/modules/fused_moe/quantization.py
  • tensorrt_llm/_torch/pyexecutor/model_engine.py
  • tensorrt_llm/llmapi/llm_args.py
  • tensorrt_llm/usage/llm_args_golden_manifest.json
  • tests/integration/test_lists/test-db/l0_b200.yml
  • tests/microbenchmarks/bench_moe/backend.py
  • tests/microbenchmarks/bench_moe/build.py
  • tests/microbenchmarks/bench_moe/search.py
  • tests/microbenchmarks/bench_moe/timing/autotune.py
  • tests/microbenchmarks/bench_moe/utils.py
  • tests/unittest/_torch/modules/moe/test_megamoe_streaming_load.py
  • tests/unittest/_torch/modules/moe/test_moe_backend.py
🚧 Files skipped from review as they are similar to previous changes (26)
  • tests/integration/test_lists/test-db/l0_b200.yml
  • tests/microbenchmarks/bench_moe/search.py
  • tensorrt_llm/llmapi/llm_args.py
  • tensorrt_llm/_torch/cute_dsl_kernels/mega_moe_nvfp4/grid_sync.py
  • tensorrt_llm/usage/llm_args_golden_manifest.json
  • tensorrt_llm/_torch/modules/fused_moe/moe_scheduler.py
  • tests/microbenchmarks/bench_moe/build.py
  • tensorrt_llm/_torch/cute_dsl_kernels/mega_moe_nvfp4/moe_utils.py
  • tensorrt_llm/_torch/modules/fused_moe/create_moe.py
  • tensorrt_llm/_torch/cute_dsl_kernels/mega_moe_nvfp4/megamoe_constants.py
  • tests/unittest/_torch/modules/moe/test_moe_backend.py
  • tests/microbenchmarks/bench_moe/utils.py
  • tests/microbenchmarks/bench_moe/backend.py
  • tensorrt_llm/_torch/modules/fused_moe/MOE_DEVELOPER_GUIDE.md
  • tests/microbenchmarks/bench_moe/timing/autotune.py
  • tensorrt_llm/_torch/cute_dsl_kernels/mega_moe_nvfp4/flag_batch.py
  • tensorrt_llm/_torch/pyexecutor/model_engine.py
  • tests/unittest/_torch/modules/moe/test_megamoe_streaming_load.py
  • tensorrt_llm/_torch/cute_dsl_kernels/mega_moe_nvfp4/sym_buffer.py
  • tensorrt_llm/_torch/cute_dsl_kernels/mega_moe_nvfp4/init.py
  • tensorrt_llm/_torch/cute_dsl_kernels/mega_moe_nvfp4/contract.py
  • tensorrt_llm/_torch/cute_dsl_kernels/mega_moe_nvfp4/fc1_fc2_fuse_sched.py
  • tensorrt_llm/_torch/cute_dsl_kernels/mega_moe_nvfp4/custom_ext.py
  • tensorrt_llm/_torch/cute_dsl_kernels/mega_moe_nvfp4/ptx_helpers.py
  • tensorrt_llm/_torch/cute_dsl_kernels/mega_moe_nvfp4/topk_reduce.py
  • tensorrt_llm/_torch/modules/fused_moe/quantization.py

Comment thread tensorrt_llm/_torch/cute_dsl_kernels/mega_moe_nvfp4/kernel_fc12.py
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61953 [ run ] completed with state SUCCESS. Commit: 6283748
/LLM/main/L0_MergeRequest_PR pipeline #50142 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@Barry-Delaney

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62094 [ run ] triggered by Bot. Commit: 6283748 Link to invocation

@sunnyqgg sunnyqgg left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62094 [ run ] completed with state FAILURE. Commit: 6283748
/LLM/main/L0_MergeRequest_PR pipeline #50277 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@Barry-Delaney

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62249 [ run ] triggered by Bot. Commit: 6283748 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62249 [ run ] completed with state SUCCESS. Commit: 6283748
/LLM/main/L0_MergeRequest_PR pipeline #50418 completed with status: 'SUCCESS'

CI Report

Link to invocation

@Barry-Delaney
Barry-Delaney enabled auto-merge (squash) July 29, 2026 02:43
@Barry-Delaney
Barry-Delaney merged commit 7e8eb8f into NVIDIA:main Jul 29, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api-compatible Accepted LLM API contract change that is backwards-compatible

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants