[PyTorch] fp8_cs_quantize fake implementation returns a vector inverse scale instead of a scalar
Maintainers usually reply within 2 days
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 82/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Domain
- machine-learning, testing
Research direction
Read transformer_engine/pytorch/onnx_extensions.py around onnx_cs_quantize_fp8_op and its register_fake implementation. Change the fake inverse-scale output to match the eager scalar shape, then run the proposed torch.library.opcheck FakeTensor check in a compatible TE/CUDA environment; done means eager and fake output metadata match.
Written by the indexing model from the issue text.
Description
Problem
At current main 9d4bd38678f29a29dc0989e3a679dc14f3538e6a, onnx_cs_quantize_fp8_op computes amax = tensor.abs().max() without a dimension, then scale_inv = 1 / scale. This produces a zero-dimensional float32 tensor. Its register_fake implementation instead returns torch.ones(1, ...) for that output, describing a one-dimensional tensor.
This violates the custom operator's eager/FakeTensor metadata contract. PyTorch's torch.library.opcheck(..., test_utils=("test_faketensor",)) reports:
found mismatched tensor metadata for output[1]:
Shapes torch.Size([]) and torch.Size([1]) are not equal!
Narrow reproduction and limitation
I isolated the exact upstream current-scaling function and its fake registration on Linux with PyTorch 2.11.0+cu130, CUDA hidden. I replaced only the lower tex::fp8_quantize operation with a CPU uint8 shape producer. The separately computed inverse scale does not depend on that producer's output. Across FP32/FP16/BF16 inputs with shapes (4,), (2, 3), and (2, 3, 4), all nine original metadata checks fail with the mismatch above.
Changing only the fake inverse-scale allocation to torch.ones((), dtype=torch.float32, device=tensor.device) makes all nine isolated metadata checks pass. This is a shape-contract reproduction, not a test of native TE FP8 kernels, numerical quantization, ONNX Runtime, or TensorRT export.
Suggested fix and native follow-up
Return a scalar inverse scale in the fake implementation:
return torch.empty(tensor.shape, dtype=torch.uint8, device=tensor.device), torch.ones(
(), dtype=torch.float32, device=tensor.device
)
On a compatible installed TE/CUDA environment, a focused regression can compare eager and FakeTensor metadata using:
import torch
import transformer_engine.pytorch.onnx_extensions
x = torch.randn(16, 16, device="cuda", dtype=torch.float32)
torch.library.opcheck(torch.ops.tex.fp8_cs_quantize.default, (x,),
test_utils=("test_faketensor",))
The native follow-up command above is proposed, not executed in my isolated reproduction.
- Dominant language
- Python
- Stars
- 3.6k
- Forks
- 851
- Avg merge
- 5d 1h
- Merged PRs (30d)
- 52
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from NVIDIA/TransformerEngine
-
[Bug] group_quantize_fp8_blockwise: mbarrier invalidated before other threads finish waiting on itOpen
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
NVIDIA/TransformerEngine#3647 ·
Maintainers usually reply within 2 days
-
[Bug] Backend selection picks FA3 for training with head_dim_qk=192 / v_head_dim=128, but FA3 backward cannot run itPossibly taken @yuweih205 claimed this 32 days ago. Openattention
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
NVIDIA/TransformerEngine#3481 · 4 comments ·
Maintainers usually reply within 2 days
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
NVIDIA/TransformerEngine#2189 · 7 comments · 5 reactions ·
Maintainers usually reply within 2 days
-
[PyTorch] CUDA graph RNG registration floods training logs on automatic-registration buildsPossibly taken @ksivaman claimed this today. Open
Difficulty 4/5 3-5 days Newbie friendliness 50/100
NVIDIA/TransformerEngine#3645 · 1 comment · 1 assignee ·
Maintainers usually reply within 2 days
-
enhancement
Difficulty 5/5 Over a week Newbie friendliness 35/100
NVIDIA/TransformerEngine#3644 ·
Maintainers usually reply within 2 days
All issues in NVIDIA/TransformerEngine
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
pyjanitor-devs/pyjanitor#1758 ·
Maintainers usually reply within 1 day
-
bug ready for review
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
odysseus-dev/odysseus#6641 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
happypawspillaro/happypaws#78 ·
Maintainers usually reply within 4 days
-
pydanty:is-working
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
pydantic/pydantic-ai#10020 ·
Maintainers usually reply within 1 day
-
stdlib type-bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
python/cpython#159044 · 4 comments ·
Maintainers usually reply within 1 day