Repository navigation
Conversation
TE runs pure FP32 GEMMs with CUBLAS_COMPUTE_32F_FAST_TF32, while the PyTorch reference modules in test_numerics.py use TF32 only when torch.backends.cuda.matmul.allow_tf32 is set. NGC containers set it via TORCH_ALLOW_TF32_CUBLAS_OVERRIDE=1, so CI passes; on a plain PyTorch install it is False and 72 FP32 cases of test_linear_accuracy, test_layernorm_linear_accuracy and test_layernorm_mlp_accuracy fail. Enable TF32 matmul for the PyTorch references through an autouse fixture, next to the existing BF16 reduced-precision fixture, and restore the previous value afterwards. Signed-off-by: rlaope <105429536+rlaope@users.noreply.github.com>
Contributor
[Low impact] The PR appears safe to merge. SummaryAdds an autouse fixture in
Reviews (1) · Last reviewed commit: "[PyTorch] Match TE TF32 FP32 GEMM precis..." · Reviewed by Greptile |
8 of 13 tasks
Collaborator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Without an NGC container,
tests/pytorch/test_numerics.pygives 72 FP32 failures on correct code. TE runs pure FP32 GEMMs withCUBLAS_COMPUTE_32F_FAST_TF32(cublaslt_gemm.cu). The PyTorch reference modules in the test (torch.nn.Linear,TorchLayerNormLinear,TorchLayerNormMLP) use TF32 only whentorch.backends.cuda.matmul.allow_tf32is set. NGC PyTorch images setTORCH_ALLOW_TF32_CUBLAS_OVERRIDE=1, so both sides run TF32 and CI passes. On a plain PyTorch installallow_tf32defaults toFalse, so TE's TF32 output is compared against an IEEE FP32 reference with FP32 tolerances.#3014 and #3797 set
NVIDIA_TF32_OVERRIDE=0in the QA launchers. That disables TF32 for TE as well, and in #3014 it was pointed out that this moves the test away from what TE actually runs. This PR does what #3797 offered as the alternative: it changes the reference side of the test and keeps TE's TF32 path. The result is the same with or without the env override, and with directpytestruns that skipqa/*.sh.The failing cases are all
dtype0(FP32):test_linear_accuracy(8),test_layernorm_linear_accuracy(32),test_layernorm_mlp_accuracy(32). One example:Outputs not close enough in tensor at idx=0. Maximum difference at location [50] with -3.5490684509277344 vs -3.55558705329895. That is the same message #3014 reported on its setup.Type of change
Changes
tests/pytorch/test_numerics.py: add an autouse fixture that setstorch.backends.cuda.matmul.allow_tf32 = Truefor each test and restores the previous value afterwards. It sits next to the existingdisable_bf16_reduced_precision_reductionfixture, which aligns PyTorch with TE in the same way for BF16. FP16/BF16 cases are not affected.test_linear_tight_dimsstill turns TF32 off inside its own body for its FP32 case, so its behaviour does not change.Validation
Hardware: RTX PRO 6000 Blackwell Max-Q (SM 12.0), driver 590.48.01, CUDA 13.0.88, PyTorch 2.14.1+cu130 (pip, not NGC), TE source build at a6393d0.
Command:
PYTORCH_JIT=0 NVTE_TORCH_COMPILE=0 NVTE_ALLOW_NONDETERMINISTIC_ALGO=0 NVTE_FUSED_ATTN=0 python -m pytest tests/pytorch/test_numerics.py(theL0_pytorch_unittestline)TORCH_ALLOW_TF32_CUBLAS_OVERRIDE=1(NGC default)NVIDIA_TF32_OVERRIDE=0Only tested on SM 12.0. The mismatch comes from the TF32 setting and is not specific to the architecture (#3797 reports the same failures on B200).
Checklist: