fix-bs-quantize-output-alignment-issue - #491
Conversation
📝 WalkthroughWalkthroughFROST 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. ChangesFROST epilogue quantization
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (4)
python/cudnn/gemm/frost/compiler.pypython/cudnn/gemm/frost/dtypes.pypython/cudnn/gemm/frost/epilogue_codegen.pytest/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 |
There was a problem hiding this comment.
📐 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.
| 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
| 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) |
There was a problem hiding this comment.
📐 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: Marktest_dense_block_scale_quant_with_fp32_dense_tap.test/python/gemm/frost/test_matmul.py#L1433-L1474: Marktest_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
|
@cudnn-ci-bot run |
|
🚀 Running mirror pipeline Branch: cudnn-gh/pr-491-ef1f70c |
Before submitting
pre-commit runand committed any formatting changes.cat-*, one or moremod-*, and oneorig-*(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
Tests