Skip to content

Integrate Rubin wgrad cutedsl kernel and fix an issue in rebased rubin branch - #456

Merged
Anerudhan merged 10 commits into
NVIDIA:developfrom
WanZzzzzz:rubin-wgrad-rebased
Jul 30, 2026
Merged

Integrate Rubin wgrad cutedsl kernel and fix an issue in rebased rubin branch#456
Anerudhan merged 10 commits into
NVIDIA:developfrom
WanZzzzzz:rubin-wgrad-rebased

Conversation

@WanZzzzzz

@WanZzzzzz WanZzzzzz commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Before submitting

  • I agree to license this contribution under the terms of LICENSE.txt.
  • I ran pre-commit run and committed any formatting changes.

Affected area

Summary

Why

Related issues

API and compatibility impact

Testing

Summary by CodeRabbit

  • New Features

    • Added support for Rubin-based grouped GEMM weight-gradient workloads.
    • Added validation for supported FP4/FP8 quantization, scaling-factor formats, accumulation type, and layout requirements.
    • Added support for accumulating results directly into an existing output buffer.
  • Bug Fixes

    • Improved device-aware kernel selection and caching.
    • Updated FP4 and FP8 handling for Rubin configurations and dynamic token sizes.
  • Tests

    • Expanded coverage for Rubin dispatch, quantization validation, invalid configurations, and output accumulation.

@WanZzzzzz WanZzzzzz changed the title Integrate Rubin wgrad cutedsl kernel Integrate Rubin wgrad cutedsl kernel and fix an issue in rebased rubin branch Jul 30, 2026
@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Rubin-specific grouped GEMM Wgrad dispatch and validation were added, alongside an SM107 kernel specialization with TMEM planning and SF-window execution changes. Cache keys now include device type, and tests cover Rubin validation, dispatch, accumulated output, and SM107 configurations.

Changes

Rubin grouped GEMM Wgrad

Layer / File(s) Summary
Rubin API dispatch and validation
python/cudnn/grouped_gemm/grouped_gemm_wgrad/_blockscaled_api.py, python/cudnn/grouped_gemm/grouped_gemm_wgrad/api.py
The block-scaled API selects the Rubin kernel for applicable configurations, validates Rubin quantization and layout constraints, and includes device type in the backend cache key.
Architecture-aware SF-window execution
python/cudnn/grouped_gemm/grouped_gemm_wgrad/moe_blockscaled_grouped_gemm_wgrad.py
The base kernel tracks architecture, constructs discrete epilogue operations inside helper_kernel, and updates TMEM layouts, cluster-leader handling, and MMA loops for SF windows.
SM107 Rubin kernel implementation
python/cudnn/grouped_gemm/grouped_gemm_wgrad/moe_blockscaled_grouped_gemm_wgrad_rubin.py
A Rubin kernel specialization adds quantization checks, TMEM planning, SM107 tiled-MMA constructors, staged layouts, and S2T copy partitioning.
Rubin and accumulation test coverage
test/python/fe_api/grouped_gemm/test_grouped_gemm_wgrad.py, test/python/fe_api/grouped_gemm/test_grouped_gemm_wgrad_utils.py, test/python/fe_api/test_rubin_kernel_dispatch.py
Tests cover Rubin dispatch, quantization and TMEM validation, accumulated FP4/FP8 output, and SM107-specific group-K configurations.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant API
  participant RubinValidation
  participant RubinKernel
  participant TMEM
  API->>RubinValidation: validate dtype, vector size, accumulation, and layout
  RubinValidation->>RubinKernel: construct SM107 kernel
  RubinKernel->>TMEM: create TMEM plan and staged layouts
  RubinKernel->>RubinKernel: execute SF-window MMA accumulation
Loading

Possibly related PRs

Suggested labels: orig-nv-eng, mod-cutedsl

Suggested reviewers: anerudhan

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is just the template placeholders and lacks the required summary, why, related issues, API impact, and testing details. Fill in each template section with the actual change summary, rationale, related issues, API/compatibility impact, and exact testing performed.
✅ Passed checks (4 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title matches the main change: adding Rubin wgrad CuTeDSL kernel support, though the rebased-branch note is extra noise.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

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

🧹 Nitpick comments (4)
python/cudnn/grouped_gemm/grouped_gemm_wgrad/moe_blockscaled_grouped_gemm_wgrad_rubin.py (1)

251-269: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Run Black with the repo's 160-column line length.

These parenthesized single-value assignments (and several call sites above) are wrapped at roughly 80 columns; Black at 160 collapses them, so the file will churn on the next format run.

As per coding guidelines: "Format Python code and notebooks with Black using a line length of 160."

🤖 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
`@python/cudnn/grouped_gemm/grouped_gemm_wgrad/moe_blockscaled_grouped_gemm_wgrad_rubin.py`
around lines 251 - 269, Run Black with the repository’s 160-column line length
on the affected file, allowing parenthesized single-value assignments and nearby
call sites to collapse to Black’s canonical formatting. Do not manually reformat
beyond the formatter’s output.

Source: Coding guidelines

test/python/fe_api/test_rubin_kernel_dispatch.py (1)

183-191: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add uint8 cases to cover the packed-FP4 branch.

_is_supported_rubin_quantization treats torch.uint8 as FP4, but no parameter exercises it.

💚 Suggested params
         ("float4_e2m1fn_x2", "float8_e4m3fn", 16, True),
+        ("uint8", "float8_e4m3fn", 16, True),
+        ("uint8", "float8_e8m0fnu", 32, True),
+        ("uint8", "float8_e4m3fn", 32, False),
         ("float4_e2m1fn_x2", "float8_e8m0fnu", 32, True),
🤖 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 `@test/python/fe_api/test_rubin_kernel_dispatch.py` around lines 183 - 191, Add
uint8 parameter cases to the quantization test parameter list covering the
packed-FP4 branch exercised by _is_supported_rubin_quantization, including the
relevant scale dtypes, block sizes, and expected boolean outcomes. Keep the
existing FP4 and FP8 cases unchanged.
test/python/fe_api/grouped_gemm/test_grouped_gemm_wgrad_utils.py (1)

176-180: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Rubin FP4 K-padding rule is duplicated across two test files. The Rubin FIX_PAD_SIZE = 256 constraint is encoded twice with different spellings (compute_capability == 107 vs torch.cuda.get_device_capability() == (10, 7)) and separate K lists, so a change to the padding granularity has to be found in both places.

  • test/python/fe_api/grouped_gemm/test_grouped_gemm_wgrad_utils.py#L176-L180: extract a helper such as rubin_fp4_group_k_list(ab_dtype, base_list) (or a _requires_rubin_fp4_k_padding(ab_dtype) predicate) that owns the capability check and the 256 granularity, and use it here.
  • test/python/fe_api/grouped_gemm/test_grouped_gemm_wgrad.py#L531-L534: replace the inline (10, 7) / FP4 check with a call to that helper for the runtime K list.
🤖 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 `@test/python/fe_api/grouped_gemm/test_grouped_gemm_wgrad_utils.py` around
lines 176 - 180, The Rubin FP4 K-padding rule is duplicated and uses
inconsistent capability checks. In
test/python/fe_api/grouped_gemm/test_grouped_gemm_wgrad_utils.py:176-180, add a
shared helper or predicate that owns the Rubin capability check, FP4 detection,
and 256-token granularity, then use it to derive the grouped K list. In
test/python/fe_api/grouped_gemm/test_grouped_gemm_wgrad.py:531-534, replace the
inline capability/FP4 condition with that helper while preserving the existing
runtime K-list behavior.
python/cudnn/grouped_gemm/grouped_gemm_wgrad/_blockscaled_api.py (1)

30-36: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Prefer the shared FP4x2 predicate over a bare uint8 dtype check.

torch.uint8 only means packed FP4 when interpret_uint8_as_fp4x2 is set. It happens to hold here (line 80 hardcodes True), but the helper is also called directly from api.py, so the assumption is invisible at the call site. Passing an is_fp4 flag (derived from self._is_fp4x2(self.a_desc)) keeps this aligned with APIBase._is_fp4x2.

♻️ Suggested signature change
-def _is_supported_rubin_quantization(ab_dtype: torch.dtype, sf_dtype: torch.dtype, sf_vec_size: int) -> bool:
-    is_fp4 = ab_dtype in (torch.float4_e2m1fn_x2, torch.uint8)
-    if is_fp4:
+def _is_supported_rubin_quantization(ab_dtype: torch.dtype, sf_dtype: torch.dtype, sf_vec_size: int, is_fp4: Optional[bool] = None) -> bool:
+    if is_fp4 is None:
+        is_fp4 = ab_dtype in (torch.float4_e2m1fn_x2, torch.uint8)
+    if is_fp4:
         return (sf_dtype == torch.float8_e4m3fn and sf_vec_size == 16) or (
             sf_dtype == torch.float8_e8m0fnu and sf_vec_size == 32
         )
🤖 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 `@python/cudnn/grouped_gemm/grouped_gemm_wgrad/_blockscaled_api.py` around
lines 30 - 36, Update _is_supported_rubin_quantization to accept an explicit
is_fp4 flag instead of treating every torch.uint8 ab_dtype as packed FP4; derive
the flag from APIBase._is_fp4x2(self.a_desc) at each relevant caller, including
the API path and the hardcoded configuration path, and preserve the existing
dtype/vector-size checks based on that flag.
🤖 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.

Nitpick comments:
In `@python/cudnn/grouped_gemm/grouped_gemm_wgrad/_blockscaled_api.py`:
- Around line 30-36: Update _is_supported_rubin_quantization to accept an
explicit is_fp4 flag instead of treating every torch.uint8 ab_dtype as packed
FP4; derive the flag from APIBase._is_fp4x2(self.a_desc) at each relevant
caller, including the API path and the hardcoded configuration path, and
preserve the existing dtype/vector-size checks based on that flag.

In
`@python/cudnn/grouped_gemm/grouped_gemm_wgrad/moe_blockscaled_grouped_gemm_wgrad_rubin.py`:
- Around line 251-269: Run Black with the repository’s 160-column line length on
the affected file, allowing parenthesized single-value assignments and nearby
call sites to collapse to Black’s canonical formatting. Do not manually reformat
beyond the formatter’s output.

In `@test/python/fe_api/grouped_gemm/test_grouped_gemm_wgrad_utils.py`:
- Around line 176-180: The Rubin FP4 K-padding rule is duplicated and uses
inconsistent capability checks. In
test/python/fe_api/grouped_gemm/test_grouped_gemm_wgrad_utils.py:176-180, add a
shared helper or predicate that owns the Rubin capability check, FP4 detection,
and 256-token granularity, then use it to derive the grouped K list. In
test/python/fe_api/grouped_gemm/test_grouped_gemm_wgrad.py:531-534, replace the
inline capability/FP4 condition with that helper while preserving the existing
runtime K-list behavior.

In `@test/python/fe_api/test_rubin_kernel_dispatch.py`:
- Around line 183-191: Add uint8 parameter cases to the quantization test
parameter list covering the packed-FP4 branch exercised by
_is_supported_rubin_quantization, including the relevant scale dtypes, block
sizes, and expected boolean outcomes. Keep the existing FP4 and FP8 cases
unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: e1ed2b5a-7b3e-410a-8607-5f3551cf8eb4

📥 Commits

Reviewing files that changed from the base of the PR and between 5235c2b and f1ffafa.

📒 Files selected for processing (7)
  • python/cudnn/grouped_gemm/grouped_gemm_wgrad/_blockscaled_api.py
  • python/cudnn/grouped_gemm/grouped_gemm_wgrad/api.py
  • python/cudnn/grouped_gemm/grouped_gemm_wgrad/moe_blockscaled_grouped_gemm_wgrad.py
  • python/cudnn/grouped_gemm/grouped_gemm_wgrad/moe_blockscaled_grouped_gemm_wgrad_rubin.py
  • test/python/fe_api/grouped_gemm/test_grouped_gemm_wgrad.py
  • test/python/fe_api/grouped_gemm/test_grouped_gemm_wgrad_utils.py
  • test/python/fe_api/test_rubin_kernel_dispatch.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants