[Bug] group_quantize_fp8_blockwise: mbarrier invalidated before other threads finish waiting on it
维护者通常 2 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 82/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- python
- 领域
- performance
调研方向
阅读 transformer_engine/common/cast/fp8_blockwise/group_quantize_fp8_blockwise.cuh,重点关注引用的两处屏障序列中的 group_block_scaled_2d_tma_kernel 和 group_block_scaled_1d_tma_kernel。在这两处都将现有的 __syncthreads() 移到 leader 使屏障失效之前,然后运行相关的分组 FP8 blockwise 测试;当所有线程都在任一屏障失效之前完成同步时,即为完成。
由索引模型根据 Issue 内容生成。
描述
Describe the bug
In transformer_engine/common/cast/fp8_blockwise/group_quantize_fp8_blockwise.cuh (main 5e99464), both TMA kernels (group_block_scaled_2d_tma_kernel and group_block_scaled_1d_tma_kernel) end their TMA load like this (lines 343–345, and the same at 630–632):
ptx::mbarrier_wait_parity(&tma_mbar, 0);
if (leading_thread) ptx::mbarrier_invalid(&tma_mbar);
__syncthreads();
Every thread polls tma_mbar, and thread 0 invalidates it before the block joins. Nothing makes the other threads finish polling first. Warps execute independently, so another warp may not have started its poll yet. Also, mbarrier.try_wait may return after a system-dependent time limit and be retried (§9.7.15.16.19), so a lagging thread can poll again after the invalidation. Lanes 1–31 of warp 0 are not covered either: the wait loop is per thread, so lanes can diverge.
PTX ISA 9.4 (§9.7.15.16.13, mbarrier.inval): "Performing any mbarrier operation except mbarrier.init on a memory location that does not contain a valid mbarrier object, results in undefined behaviour." The ISA's own examples put a barrier before @t0 mbarrier.inval.
A late poll on the invalidated word is undefined. If invalidation changes the word, that thread may never see the phase complete, and the block hangs at the __syncthreads(). The window is narrow: the other warps start polling within cycles, while the load (32 KB for a BF16/FP16 tile, 64 KB for FP32) takes, we estimate, microseconds. We have not observed a failure on hardware; this is a conformance fix.
Steps/Code to reproduce bug
Found by checking a reduced extract of this sequence (a 4 KB linear bulk copy instead of the tensor-map load), compiled with CUDA 12.9 for sm_90a, against the PTX ISA. It has not been reproduced on hardware. A targeted probe would delay one non-leader warp before its first poll, use bounded waits, and compare against a version that joins first.
Expected behavior
All threads have finished waiting on tma_mbar before it is invalidated. The fix is to move the existing barrier above the invalidation at both sites:
ptx::mbarrier_wait_parity(&tma_mbar, 0);
__syncthreads();
if (leading_thread) ptx::mbarrier_invalid(&tma_mbar);
TE already does this elsewhere, for example in cast/mxfp8/dequantize_mxfp8.cuh (sm_100 path) and fused_attn/flash_attn.cu, which reach a __syncthreads() before invalidating their barriers. tma_mbar is not used after the invalidation, so no other change is needed.
Environment overview
Source analysis at 5e99464; no runtime environment involved.
Device details
Hopper (sm_90a) code path.
Additional context
Reach: the grouped FP8 block-scaling quantize kernels on Hopper (2D, 1D columnwise and both, and 1D rowwise with dbias through bgrad_group_quantize). te.ops.GroupedLinear reaches them by default on Hopper with cuBLASLt 13.6 or later and a block-scaling recipe; the te.pytorch.GroupedLinear module only with the opt-in use_grouped_tensor=True (or the deprecated NVTE_GROUPED_LINEAR_USE_FUSED_GROUPED_GEMM=1).
- 主要语言
- Python
- 星标
- 3.6k
- 派生
- 851
- 平均合并
- 5 天 1 小时
- 30 天内合并 PR
- 52
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
NVIDIA/TransformerEngine 的其他 Issue
-
[PyTorch] fp8_cs_quantize fake implementation returns a vector inverse scale instead of a scalar可能已有人在做 @sanjana658 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
NVIDIA/TransformerEngine#3636 · 2 条评论 ·
维护者通常 2 天内回复
-
[Bug] Backend selection picks FA3 for training with head_dim_qk=192 / v_head_dim=128, but FA3 backward cannot run it可能已有人在做 @yuweih205 于 32 天前认领。 未关闭attention
难度 2/5 1-3 小时 新手友好度 85/100
NVIDIA/TransformerEngine#3481 · 4 条评论 ·
维护者通常 2 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 68/100
NVIDIA/TransformerEngine#2189 · 7 条评论 · 5 个 reaction ·
维护者通常 2 天内回复
-
[PyTorch] CUDA graph RNG registration floods training logs on automatic-registration builds可能已有人在做 @ksivaman 今天认领。 未关闭
难度 4/5 3-5 天 新手友好度 50/100
NVIDIA/TransformerEngine#3645 · 1 条评论 · 已指派 1 人 ·
维护者通常 2 天内回复
-
enhancement
难度 5/5 一周以上 新手友好度 35/100
NVIDIA/TransformerEngine#3644 ·
维护者通常 2 天内回复
查看 NVIDIA/TransformerEngine 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 68/100
pyjanitor-devs/pyjanitor#1758 ·
维护者通常 1 天内回复
-
bug ready for review
难度 2/5 1-3 小时 新手友好度 86/100
odysseus-dev/odysseus#6641 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 76/100
happypawspillaro/happypaws#78 ·
维护者通常 4 天内回复
-
pydanty:is-working
难度 2/5 1-3 小时 新手友好度 82/100
pydantic/pydantic-ai#10020 ·
维护者通常 1 天内回复
-
stdlib type-bug
难度 2/5 1-3 小时 新手友好度 68/100
python/cpython#159044 · 4 条评论 ·
维护者通常 1 天内回复