Skip to content

fix-bs-quantize-output-alignment-issue - #491

Merged
Anerudhan merged 1 commit into
NVIDIA:developfrom
yanqinz2:develop
Aug 5, 2026
Merged

fix-bs-quantize-output-alignment-issue#491
Anerudhan merged 1 commit into
NVIDIA:developfrom
yanqinz2:develop

Conversation

@yanqinz2

@yanqinz2 yanqinz2 commented Aug 5, 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.
  • I added GitHub labels: one cat-*, one or more mod-*, and one orig-* (see label list).

Affected area

Summary

Fix the FROST engine quantize operation blocked by fixed vector size in epilogue

API and compatibility impact

Testing

Summary by CodeRabbit

  • Bug Fixes

    • Improved validation for block-scale quantization configurations.
    • Prevented epilogue processing from exceeding supported vector widths.
    • Added safeguards against invalid scale-store alignment and oversized accesses.
    • Improved compatibility for dense outputs combined with quantized results.
  • Tests

    • Added regression coverage for FP32 and BF16 dense-output quantization scenarios.

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

FROST GEMM now caps epilogue chunks at 32 elements and applies stricter block-scale quantization validation. Epilogue code generation validates vector groups and element strides. New matmul tests cover FP32 and BF16 dense taps with quantized outputs.

Changes

FROST epilogue quantization

Layer / File(s) Summary
Epilogue chunk sizing
python/cudnn/gemm/frost/dtypes.py
Adds MAX_EPI_CHUNK_ELEMS = 32. Epilogue vector sizing now clamps element counts before converting to per-output byte widths.
Quantization validation and code generation
python/cudnn/gemm/frost/compiler.py, python/cudnn/gemm/frost/epilogue_codegen.py
Validates chunk divisibility against drain subtiles, runtime N dimensions, quantization block sizes, vector lane groups, and auxiliary strides. Rejects oversized chunks with NotImplementedError.
Quantization regression coverage
test/python/gemm/frost/test_matmul.py
Adds tests for FP32 and BF16 dense taps with block-scale quantization, including vector-width, output, scale, and guarded-store checks.

Estimated code review effort: 3 (Moderate) | ~20 minutes

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 includes the summary but omits the affected area, why, compatibility impact, related issues, and testing details. Complete the missing sections, especially the affected area, problem rationale, compatibility impact, and exact test commands with results.
✅ 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 clearly identifies the batch-scale quantization output alignment fix addressed by the changes.
✨ 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.

Actionable comments posted: 2

🤖 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 `@python/cudnn/gemm/frost/epilogue_codegen.py`:
- Line 12: Reformat the import statement from the dtypes module in
epilogue_codegen.py using Black so it complies with the 160-character maximum
line length, without changing the imported symbols or their ordering.

In `@test/python/gemm/frost/test_matmul.py`:
- Around line 1397-1430: Add the repository’s appropriate L0–L4 test-level
marker to both new tests: test_dense_block_scale_quant_with_fp32_dense_tap in
test/python/gemm/frost/test_matmul.py lines 1397-1430 and
test_dense_col_block_scale_quant_with_dense_tap in lines 1433-1474.
🪄 Autofix

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: 4ce6753e-ca0f-4a19-bd2e-b638874c10f5

📥 Commits

Reviewing files that changed from the base of the PR and between 5deb8a5 and ef1f70c.

📒 Files selected for processing (4)
  • python/cudnn/gemm/frost/compiler.py
  • python/cudnn/gemm/frost/dtypes.py
  • python/cudnn/gemm/frost/epilogue_codegen.py
  • test/python/gemm/frost/test_matmul.py

from dataclasses import dataclass, field

from .dtypes import DTYPE_BYTES, DTYPE_TO_CUTLASS, _output_align_reqs, allowed_store_vsize, dense_output_layout, tensor_alignment
from .dtypes import DTYPE_BYTES, DTYPE_TO_CUTLASS, MAX_EPI_CHUNK_ELEMS, _output_align_reqs, allowed_store_vsize, dense_output_layout, tensor_alignment

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.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Format this import with Black.

Line 12 exceeds 160 characters. Format the import with Black.

As per coding guidelines, “Format Python code with Black and a maximum line length of 160 characters.”

Proposed fix
-from .dtypes import DTYPE_BYTES, DTYPE_TO_CUTLASS, MAX_EPI_CHUNK_ELEMS, _output_align_reqs, allowed_store_vsize, dense_output_layout, tensor_alignment
+from .dtypes import (
+    DTYPE_BYTES,
+    DTYPE_TO_CUTLASS,
+    MAX_EPI_CHUNK_ELEMS,
+    _output_align_reqs,
+    allowed_store_vsize,
+    dense_output_layout,
+    tensor_alignment,
+)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
from .dtypes import DTYPE_BYTES, DTYPE_TO_CUTLASS, MAX_EPI_CHUNK_ELEMS, _output_align_reqs, allowed_store_vsize, dense_output_layout, tensor_alignment
from .dtypes import (
DTYPE_BYTES,
DTYPE_TO_CUTLASS,
MAX_EPI_CHUNK_ELEMS,
_output_align_reqs,
allowed_store_vsize,
dense_output_layout,
tensor_alignment,
)
🤖 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/gemm/frost/epilogue_codegen.py` at line 12, Reformat the import
statement from the dtypes module in epilogue_codegen.py using Black so it
complies with the 160-character maximum line length, without changing the
imported symbols or their ordering.

Source: Coding guidelines

Comment on lines +1397 to +1430
def test_dense_block_scale_quant_with_fp32_dense_tap() -> None:
"""The chunk stays pinned to the quant block even when the widest dense
output is 4 bytes: 32 elements x 4 B = 128 B, split into four 32 B stores."""
cfg, cta_group, scheduler = _resolve("CONFIG_sm100_128x128x128_128x128x32_cluster1x1_1ctamma")
M = N = K = 128
block_size = 32
g = cudnn.pygraph(
io_data_type=cudnn.data_type.BFLOAT16,
intermediate_data_type=cudnn.data_type.FLOAT,
compute_data_type=cudnn.data_type.FLOAT,
)
A = g.tensor(name="A", dim=[1, M, K], stride=_a_stride_batched(M, K, "k"))
B = g.tensor(name="B", dim=[1, K, N], stride=_b_stride_batched(N, K, "k"))
C = g.matmul(A=A, B=B, name="mm")
C.set_output(True).set_data_type(cudnn.data_type.FLOAT)
Q, QS = g.block_scale_quantize(input=C, block_size=block_size, name="q")
Q.set_output(True).set_data_type(cudnn.data_type.FP8_E4M3)
QS.set_output(True).set_data_type(cudnn.data_type.FP8_E8M0)

compiled = _plan(g, config=cfg, cta_group=cta_group, scheduler=scheduler)
assert _epi_vec_bytes(compiled.chain, cfg, cta_group) == block_size * 4

a, b, _ = _mkdata(M, N, K, "bf16", "bf16")
tap = torch.empty(1, M, N, dtype=torch.float32, device="cuda")
q = torch.empty(1, M, N, dtype=torch.float8_e4m3fn, device="cuda")
q_scale = torch.empty(1, M, N // block_size, dtype=torch.float8_e8m0fnu, device="cuda")
compiled(_vp(compiled, a, b, [tap, q, q_scale]))
torch.cuda.synchronize()

ref = torch.einsum("bmk,bnk->bmn", a.to(torch.float32), b.to(torch.float32))
q_ref, scale_ref = _block_quant_reference(ref, block_size, torch.float8_e4m3fn, torch.float8_e8m0fnu)
torch.testing.assert_close(tap, ref, atol=0, rtol=0)
torch.testing.assert_close(q_scale.float(), scale_ref.float(), atol=0, rtol=0)
torch.testing.assert_close(q.float(), q_ref.float(), atol=0, rtol=0)

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.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Add a test-level marker to each new test.

Apply the repository L0-L4 marker mechanism to both tests.

  • test/python/gemm/frost/test_matmul.py#L1397-L1430: Mark test_dense_block_scale_quant_with_fp32_dense_tap.
  • test/python/gemm/frost/test_matmul.py#L1433-L1474: Mark test_dense_col_block_scale_quant_with_dense_tap.

As per coding guidelines, “Mark every new Python test with a level from L0 through L4.”

📍 Affects 1 file
  • test/python/gemm/frost/test_matmul.py#L1397-L1430 (this comment)
  • test/python/gemm/frost/test_matmul.py#L1433-L1474
🤖 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/gemm/frost/test_matmul.py` around lines 1397 - 1430, Add the
repository’s appropriate L0–L4 test-level marker to both new tests:
test_dense_block_scale_quant_with_fp32_dense_tap in
test/python/gemm/frost/test_matmul.py lines 1397-1430 and
test_dense_col_block_scale_quant_with_dense_tap in lines 1433-1474.

Source: Coding guidelines

@Anerudhan

Copy link
Copy Markdown
Collaborator

@cudnn-ci-bot run

@cudnn-ci-bot

Copy link
Copy Markdown

🚀 Running mirror pipeline

Branch: cudnn-gh/pr-491-ef1f70c
Pipeline: 61291489

@Anerudhan
Anerudhan self-requested a review August 5, 2026 22:09
@Anerudhan Anerudhan added cat-bug Reports of incorrect behavior, crashes, regressions, or unexpected results. orig-nv-eng Reported or requested by NVIDIA engineering. mod-frost labels Aug 5, 2026
@Anerudhan Anerudhan added this to the Frontend 1.27.0 milestone Aug 5, 2026
@Anerudhan
Anerudhan merged commit ecd9f32 into NVIDIA:develop Aug 5, 2026
1 check passed
@Anerudhan Anerudhan mentioned this pull request Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cat-bug Reports of incorrect behavior, crashes, regressions, or unexpected results. mod-frost orig-nv-eng Reported or requested by NVIDIA engineering.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants