Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

MXFP8 quantize_ writes out of bounds of compact unswizzled scale buffers when rows are not a multiple of 64

未关闭
#3,689 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
30/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
python, pytorch

调研方向

Start with the reproducer in the issue: it runs on a Blackwell GPU and should print 0 / 0 once fixed, not 256 / 256. Find where MXFP8Tensor.quantize_() checks scale_inv shapes against get_scale_shape(), and where the generic fp32 quantize kernel stores scales per 64-row chunk. Done means out-of-bounds scale writes stop for non-multiple-of-64 rows, either by bounds-checking the stores or by rejecting compact scales with an error. Confirm with the canary test and the existing MXFP8 tests.

由索引模型根据 Issue 内容生成。

描述

bug

Describe the bug

MXFP8Tensor.quantize_() with with_gemm_swizzled_scales=False accepts caller-provided compact scale_inv buffers ((rows, cols/32) and (rows/32, cols)), but the generic quantize kernel stores a scale for every row of its 64-row chunk. When rows is not a multiple of 64 it writes beyond the end of the compact buffers. #3518 reports the GEMM side of the same contract (GEMM rejects compact scales); its 64x64 example stays in bounds, which is why quantize_ appeared to accept compact scales there.

Environment. TE 2.20.2 (transformer-engine, -cu13, -torch), GB200 (sm_100), fp32 source. bf16 sources take the specialized kernels, which stay in bounds.

Observed. With a canary buffer after each compact scale view, a (32, 256) tensor writes 256 bytes beyond the rowwise view and 256 beyond the columnwise view (rows 32-63 of the 64-row chunk); (96, 128) writes rows 96-127; (64, 64) and other row counts that are multiples of 64 stay in bounds. When cols is not a multiple of 128 (e.g. (512, 96)) the columnwise view's contents are also wrong because the kernel assumes the padded column stride.

Impact. Megatron Core's MFSDP v2 keeps MXFP8 scales in compact per-rank planes; quantizing a 32-row shard zeroed the next rank's scales or raised an illegal memory access when the view ended the allocation. A Megatron-side fix (quantize into padded scales) is NVIDIA/Megatron-LM#8247.

Expected. One of:

  1. Honour the compact scale_inv shape: bounds-check the scale stores on rows as well as columns, so the kernel writes only rows x cols/32 rowwise and rows/32 x cols columnwise scales. Compact unswizzled scales then become a supported input on the quantize side (the direction #3518 asks for on the GEMM side).
  2. Validate the scale shapes before launching the kernel: if scale_inv or columnwise_scale_inv does not match the padded shape from get_scale_shape(), raise an error instead of quantizing, the same way GEMM already rejects compact scales.

Reproducer (single Blackwell GPU; prints 256 / 256 on TE 2.20.2, expected 0 / 0):

import torch
import transformer_engine.pytorch  # noqa: F401
import transformer_engine_torch as tex
from transformer_engine.pytorch.tensor.mxfp8_tensor import MXFP8Quantizer, MXFP8Tensor

rows, cols, canary, pad = 32, 256, 0xAA, 1 << 16
quantizer = MXFP8Quantizer(tex.DType.kFloat8E4M3)
n_rs, n_cs = rows * (cols // 32), (rows // 32) * cols
rs_buf = torch.full((n_rs + pad,), canary, dtype=torch.uint8, device="cuda")
cs_buf = torch.full((n_cs + pad,), canary, dtype=torch.uint8, device="cuda")
tensor = MXFP8Tensor(
    shape=(rows, cols), dtype=torch.bfloat16, device="cuda",
    rowwise_data=torch.empty((rows, cols), dtype=torch.uint8, device="cuda"),
    columnwise_data=torch.empty((rows, cols), dtype=torch.uint8, device="cuda"),
    rowwise_scale_inv=rs_buf[:n_rs].view(rows, cols // 32),
    columnwise_scale_inv=cs_buf[:n_cs].view(rows // 32, cols),
    fp8_dtype=tex.DType.kFloat8E4M3, quantizer=quantizer, with_gemm_swizzled_scales=False,
)
tensor.quantize_(torch.randn(rows, cols, device="cuda"))  # fp32 source -> generic kernel
torch.cuda.synchronize()
print(int((rs_buf[n_rs:] != canary).sum()), int((cs_buf[n_cs:] != canary).sum()))
主要语言
Python
星标
3.6k
派生
862
平均合并
4 天 21 小时
30 天内合并 PR
62

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

NVIDIA/TransformerEngine 的其他 Issue

查看 NVIDIA/TransformerEngine 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。