Repository navigation
[Common][PyTorch] Enable compiler warnings and treat them as errors - #3955
Open
maxwbuckley wants to merge 2 commits into
Open
maxwbuckley wants to merge 2 commits into
maxwbuckley wants to merge 2 commits into
Conversation
maxwbuckley
requested review from
Oleg-Goncharov,
cyanguwa,
ksivaman and
ptrendx
as code owners
November 27, 2026 08:39
Contributor
[Medium impact] The changes appear safe to merge; the previous cuBLASMp finding is addressed and no new actionable issues were found. SummaryThis PR enables compiler warnings for the common library and PyTorch extension, treats them as errors by default, and cleans up existing warnings.
Reviews (4) · Last reviewed commit: "Build the common library and PyTorch ext..." · Reviewed by Greptile |
maxwbuckley
force-pushed
the
enable-compiler-warnings
branch
from
November 27, 2026 09:49
2ade89d to
f7e9abc
Compare
Contributor
|
Want your agent to iterate on Greptile's feedback? Try greploops. |
maxwbuckley
force-pushed
the
enable-compiler-warnings
branch
from
November 27, 2026 10:21
f7e9abc to
9f815a5
Compare
Fix everything -Wall -Wextra (GCC 13) and nvcc report in libtransformer_engine and transformer_engine_torch, in preparation for building with warnings as errors. The fixes do not change behavior for valid inputs: - Comment out or mark [[maybe_unused]] parameters that stub functions, or configuration-dependent code paths (cuBLASMp, cuSolverMp, MPI, NVSHMEM, CUDA version gates), do not use. - Use matching signedness in comparisons and loop counters. - Remove unused local variables, and reorder a member initializer list to match the declaration order. - Handle all enumerators in two switches over NVTE_QKV_Layout(_Group). - Throw instead of reading an uninitialized ScalingType or vector size when an unsupported configuration reaches the MXFP8 quantize and cast-transpose dispatch code. - Drop a self-initialized, unused at::TensorOptions in Float8Quantizer::set_quantization_params. - Discard unreachable code after an always-failing check in grouped NVFP4 quantization, and avoid ptxas warnings about out-of-range launch bounds on targets with fewer than 2048 threads per SM. - Call NVSHMEM's ::nvshmem_finalize() from the PyTorch extension's nvshmem_finalize() wrapper, which called itself (GCC -Winfinite-recursion). - Suppress nvcc's #20280-D for two TMA kernel templates, where it is a false positive for specializations named only in discarded if-constexpr branches. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Max Buckley <maxwbuckley@gmail.com>
Compile libtransformer_engine with -Wall -Wextra (host code via -Xcompiler for CUDA sources) and transformer_engine_torch with -Wall -Wextra, and treat warnings as errors. The NVTE_WARNINGS_AS_ERRORS CMake option and environment variable (default on) turn -Werror off, for example when building with a newer compiler that adds warnings. The flags are PRIVATE to TE's own targets. Third-party headers (CUTLASS, cuDNN frontend, NCCL, NCCL EP, TVM-FFI, MPI, NVSHMEM, cuBLASMp, cuSolverMp, PyTorch, CUDA and Python) are included as system headers so their warnings are not reported. A ptxas advisory about TMA multicast in the CUTLASS SM90 grouped GEMM, when it is compiled for family targets such as sm_120f, is silenced for that source only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Max Buckley <maxwbuckley@gmail.com>
maxwbuckley
force-pushed
the
enable-compiler-warnings
branch
from
November 27, 2026 11:26
9f815a5 to
9ef63cc
Compare
This branch has not been deployed
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.
TL;DR: build
libtransformer_engineand the PyTorch extension with-Wall -Wextra -Werror, after fixing the ~360 warnings they currently produce (no behavior change for valid inputs;NVTE_WARNINGS_AS_ERRORS=0turns-Werroroff).Description
TE's C++/CUDA code is built with no warning flags today, so warnings pile up silently. This PR turns them on and makes the build clean.
Flags and switch
transformer_engine/common/CMakeLists.txt:-Wall -Wextrafor C++ sources and-Xcompiler=-Wall,-Wextrafor CUDA sources, plus-Werror/-Werror=all-warnings(covers nvcc front-end and ptxas warnings) when the new CMake optionNVTE_WARNINGS_AS_ERRORSis on (default). The flags arePRIVATEto thetransformer_enginetarget, so nothing leaks to consumers.build_tools/pytorch.py:-Wall -Wextra(+-Werror) fortransformer_engine_torch.setup.pyreads theNVTE_WARNINGS_AS_ERRORSenvironment variable (default1) and passes it to CMake and the extension build; documented indocs/envvars.rst.-isystemin the extension build).Fix categories (unique sites, common library + PyTorch extension)
CommOverlapCorevirtual defaults, the non-cuBLASMp/cuSolverMp/MPI/NVSHMEM stubs, the deprecatedset_float8_block_scale_tensor_format). Names are commented out (Google style); parameters used only under#ifdefs or CUDA-version gates get[[maybe_unused]].atomic_gemm_overlap_rs, unused CuTe tensors in the Hadamard kernels).CudnnNormalizationPlan), 2 unhandled enumerators inswitch, 2{0}aggregate initializers, 1 type-limits, 1 redundantstd::move, 1#pragma unrollon a host loop, 1-Wparentheses(pointer-to-member return type, now a type alias).IS_ACT, now behindif constexpr), 1 unused variable.__launch_bounds__(512, 4)inscaled_activation.cuis out of range on targets with fewer than 2048 threads/SM (SM 7.5, 8.6, 8.7, 8.9, 12.x) and ptxas ignored it with a warning; the minimum is now omitted on exactly those targets, so the generated code is unchanged.Suppressions (2, both scoped and commented)
#20280-Daround the two TMA kernel templates ingroup_quantize_fp8_blockwise.cuh: the{rowwise=false, colwise=false}specializations are named only in discardedif constexprbranches inside theTRANSFORMER_ENGINE_SWITCH_CONDITIONmacros and are never instantiated, so the warning is a false positive. Happy to restructure the dispatch instead if you prefer.--suppress-async-bulk-multicast-advisory-warningforgemm/cutlass_grouped_gemm.cuonly (added only if the toolkit's ptxas supports it): CUTLASS's SM90 grouped GEMM uses TMA multicast, and ptxas warns about that when the file is also compiled forsm_120f.Things the warnings turned up (please take a look)
Float8Quantizer::set_quantization_paramshadat::TensorOptions opts = opts.dtype(...)...;, which readsoptsbefore it is constructed (undefined behavior). The result was unused, so the line is removed.quantize/quantize_gatedleftscaling_typeuninitialized (and then switched on it) when the output has neither rowwise nor columnwise data;cast_transpose_fuseddid the same forVecOutputTypeSize/VecComputeTypeSizewith an unexpected vector size. These now throwNVTE_ERRORinstead of reading an indeterminate value. The grouped MXFP8 path already rejects the first case the same way.quant_configingroup_scaled_swiglu(somxfp8_2d_quantizationis ignored there, unlikegroup_quantize),topkinfused_score_for_moe_aux_loss_backward,sm_countinrow_col_rht_gemm_ntt_w_sfc,m_splitsinte_general_grouped_gemm, andrecv_offsetinuserbuffers_sendrecv(_atomic). They may be intentional; I left the behavior alone.Not covered here: the JAX extension,
tests/cppandtests/cpp_distributedkeep their current flags; I can follow up with those.Testing
NVTE_CUDA_ARCHS=120, NCCL EP on.pip install -e . --no-build-isolationwithNVTE_FRAMEWORK=pytorchbuilds cleanly with-Werror(common library + extension).tests/cppbuilds. On an RTX 5090:test_utilpasses (15/15);test_operatorfiltered to the touched areas (*MXFP8*:*Softmax*:*Swizzle*:*Padding*:*CastTransposeDBias*:*ScaledActivation*:*Act*:*Grouped*) passes 8261 tests. The only failures are 198GroupedGemmTestcases that throw because grouped GEMM needs SM 10.x/11.0 (or cuBLAS has no algorithm on SM 12.0), which is unrelated to this change.import transformer_engine.pytorchand ate.Linearforward work.pre-commit(clang-format, black) andcpplintare clean on the touched files.NVTE_WARNINGS_AS_ERRORS=0is the escape hatch if CI disagrees, and I'm happy to fix whatever it reports.We've done the same cleanup elsewhere: faiss (facebookresearch/faiss#4933, facebookresearch/faiss#5952, after which faiss turned the strict warnings on by default) and CCCL (NVIDIA/cccl#8132). It removed a fair amount of tech debt and turned up real issues the compiler had been pointing at.
Per-file details
common/CMakeLists.txt:NVTE_WARNINGS_AS_ERRORSoption,nvte_enable_compiler_warnings(), third-party includes markedSYSTEM, ptxas advisory suppression forcutlass_grouped_gemm.cu.setup.py,build_tools/utils.py,build_tools/pytorch.py,docs/envvars.rst: env var, extension warning flags and-isystemfor PyTorch/CUDA/Python headers, docs.include/transformer_engine/comm_gemm_overlap.h,transformer_engine.h: unused parameters in default/deprecated inline methods.comm_gemm/comm_gemm.cpp,newton_schulz/newton_schulz.cpp: unused parameters in the stubs built without cuBLASMp / cuSolverMp.comm_gemm_overlap/comm_gemm_overlap.cpp: unused locals, loop counter type.comm_gemm_overlap/userbuffers/userbuffers-host.cpp,userbuffers.cu: unused parameters/locals,= {}forIpcSocketHandle,[[maybe_unused]]for MPI-only parameters.gemm/cublaslt_gemm.cu,cublaslt_grouped_gemm.cu,cutlass_grouped_gemm.cu(h): version-gated parameters, sign-compare, unused parameters.cast/dispatch/quantize.cuh: unused structured binding, unreachable code forIS_ACT.cast/mxfp8/quantize_mxfp8.cuh,gated_mxfp8.cuh,transpose/cast_transpose_fusion.cu: uninitialized-value paths now throw (see above); host#pragma unroll.cast/fp8_blockwise/group_quantize_fp8_blockwise.cuh: scoped#20280-Dsuppression.activation/scaled_activation.{h,cu}: launch bounds per target, sign-compare.fused_attn/context_parallel.cu,utils.cu,kv_cache.cu,graph_cache_debug.h: sign-compare, switch coverage, unused parameter, type alias.hadamard_transform/*.cu: unused variables (the ones used only throughdecltypeare[[maybe_unused]]), unused parameter, sign-compare.fused_softmax/*.cu,multi_tensor/*.cu(h),recipe/*.cu,swizzle/swizzle.cu,util/*.{cu,cpp,h},transformer_engine.cpp,cudnn_utils.cpp,normalization/common.cpp,fused_router/fused_score_for_moe_aux_loss.cu,cast/cast.cu: sign-compare, type-limits, unused parameters/variables, initializer order.pytorch/csrc/quantizer.cpp,common.h,extensions/{cast,comm_gemm_overlap,ep,gemm,nvshmem_comm,swizzle}.cpp: unused parameters/variables, missing field initializers, redundant move, the self-initializedTensorOptions, value-initializedNVTEShape.🤖 Generated with Claude Code