Skip to content

[Common][PyTorch] Enable compiler warnings and treat them as errors - #3955

Open
maxwbuckley wants to merge 2 commits into
NVIDIA:mainfrom
maxwbuckley:enable-compiler-warnings
Open

maxwbuckley wants to merge 2 commits into
NVIDIA:mainfrom
maxwbuckley:enable-compiler-warnings

Conversation

@maxwbuckley

Copy link
Copy Markdown

TL;DR: build libtransformer_engine and 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=0 turns -Werror off).

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 -Wextra for C++ sources and -Xcompiler=-Wall,-Wextra for CUDA sources, plus -Werror / -Werror=all-warnings (covers nvcc front-end and ptxas warnings) when the new CMake option NVTE_WARNINGS_AS_ERRORS is on (default). The flags are PRIVATE to the transformer_engine target, so nothing leaks to consumers.
  • build_tools/pytorch.py: -Wall -Wextra (+ -Werror) for transformer_engine_torch.
  • setup.py reads the NVTE_WARNINGS_AS_ERRORS environment variable (default 1) and passes it to CMake and the extension build; documented in docs/envvars.rst.
  • Third-party headers are included as system headers so their warnings are not reported: CUTLASS, cuDNN frontend, NCCL, NCCL EP, TVM-FFI, MPI, cuBLASMp, cuSolverMp (CMake), and PyTorch, CUDA and Python headers (-isystem in the extension build).

Fix categories (unique sites, common library + PyTorch extension)

  • ~260 unused parameters: mostly stub functions (CommOverlapCore virtual defaults, the non-cuBLASMp/cuSolverMp/MPI/NVSHMEM stubs, the deprecated set_float8_block_scale_tensor_format). Names are commented out (Google style); parameters used only under #ifdefs or CUDA-version gates get [[maybe_unused]].
  • ~70 sign-compare: casts that spell out the conversion the compiler already did, or matching loop-counter types.
  • ~15 unused / set-but-unused variables removed (e.g. dead pointers in atomic_gemm_overlap_rs, unused CuTe tensors in the Hadamard kernels).
  • 1 member initializer order (CudnnNormalizationPlan), 2 unhandled enumerators in switch, 2 {0} aggregate initializers, 1 type-limits, 1 redundant std::move, 1 #pragma unroll on a host loop, 1 -Wparentheses (pointer-to-member return type, now a type alias).
  • nvcc: 1 unreachable code (grouped NVFP4 dispatch with IS_ACT, now behind if constexpr), 1 unused variable.
  • ptxas: __launch_bounds__(512, 4) in scaled_activation.cu is 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)

  • nvcc #20280-D around the two TMA kernel templates in group_quantize_fp8_blockwise.cuh: the {rowwise=false, colwise=false} specializations are named only in discarded if constexpr branches inside the TRANSFORMER_ENGINE_SWITCH_CONDITION macros and are never instantiated, so the warning is a false positive. Happy to restructure the dispatch instead if you prefer.
  • ptxas --suppress-async-bulk-multicast-advisory-warning for gemm/cutlass_grouped_gemm.cu only (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 for sm_120f.

Things the warnings turned up (please take a look)

  1. Float8Quantizer::set_quantization_params had at::TensorOptions opts = opts.dtype(...)...;, which reads opts before it is constructed (undefined behavior). The result was unused, so the line is removed.
  2. MXFP8 quantize / quantize_gated left scaling_type uninitialized (and then switched on it) when the output has neither rowwise nor columnwise data; cast_transpose_fused did the same for VecOutputTypeSize / VecComputeTypeSize with an unexpected vector size. These now throw NVTE_ERROR instead of reading an indeterminate value. The grouped MXFP8 path already rejects the first case the same way.
  3. Not changed, just flagged: some parameters are silently ignored, e.g. quant_config in group_scaled_swiglu (so mxfp8_2d_quantization is ignored there, unlike group_quantize), topk in fused_score_for_moe_aux_loss_backward, sm_count in row_col_rht_gemm_ntt_w_sfc, m_splits in te_general_grouped_gemm, and recv_offset in userbuffers_sendrecv(_atomic). They may be intentional; I left the behavior alone.

Not covered here: the JAX extension, tests/cpp and tests/cpp_distributed keep their current flags; I can follow up with those.

Testing

  • GCC 13.3, CUDA 13.2, cuDNN 9.26 (wheel), NCCL 2.32 (wheel), PyTorch 2.15 (cu132), Python 3.12; NVTE_CUDA_ARCHS=120, NCCL EP on.
  • pip install -e . --no-build-isolation with NVTE_FRAMEWORK=pytorch builds cleanly with -Werror (common library + extension).
  • tests/cpp builds. On an RTX 5090: test_util passes (15/15); test_operator filtered to the touched areas (*MXFP8*:*Softmax*:*Swizzle*:*Padding*:*CastTransposeDBias*:*ScaledActivation*:*Act*:*Grouped*) passes 8261 tests. The only failures are 198 GroupedGemmTest cases 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.pytorch and a te.Linear forward work.
  • pre-commit (clang-format, black) and cpplint are clean on the touched files.
  • Not tested: CUDA 12.x, other GPU architectures (only sm_120 / sm_120f), Clang, and the cuBLASMp / cuSolverMp / MPI / NVSHMEM / CuTeDSL build options. Arch-specific or version-gated code may still warn there; NVTE_WARNINGS_AS_ERRORS=0 is 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_ERRORS option, nvte_enable_compiler_warnings(), third-party includes marked SYSTEM, ptxas advisory suppression for cutlass_grouped_gemm.cu.
  • setup.py, build_tools/utils.py, build_tools/pytorch.py, docs/envvars.rst: env var, extension warning flags and -isystem for 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, = {} for IpcSocketHandle, [[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 for IS_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-D suppression.
  • 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 through decltype are [[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-initialized TensorOptions, value-initialized NVTEShape.

🤖 Generated with Claude Code

@github-actions github-actions Bot added the community-contribution PRs from external contributor outside the core maintainers, representing community-driven work. label Nov 27, 2026
@greptile-apps

greptile-apps Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The changes appear safe to merge; the previous cuBLASMp finding is addressed and no new actionable issues were found.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The changes appear safe to merge; the previous cuBLASMp finding is addressed and no new actionable issues were found.

Summary

This PR enables compiler warnings for the common library and PyTorch extension, treats them as errors by default, and cleans up existing warnings.

  • The common library and PyTorch extension treat their compiler warnings as errors by default.
  • The common library's source code now builds cleanly under stricter compiler warnings.
  • MXFP8 quantization rejects outputs without rowwise or columnwise data.
  • Cast-transpose reports unsupported vector sizes instead of using unset sizes.
  • The PyTorch extension's source code now builds cleanly under stricter compiler warnings.
  • Float8 quantizer setup no longer creates a self-initialized temporary.

Reviews (4) · Last reviewed commit: "Build the common library and PyTorch ext..." · Reviewed by Greptile

Comment thread build_tools/pytorch.py Resolved
@maxwbuckley
maxwbuckley force-pushed the enable-compiler-warnings branch from 2ade89d to f7e9abc Compare November 27, 2026 09:49
Comment thread build_tools/pytorch.py Resolved
@greptile-apps

greptile-apps Bot commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Want your agent to iterate on Greptile's feedback? Try greploops.

@maxwbuckley
maxwbuckley force-pushed the enable-compiler-warnings branch from f7e9abc to 9f815a5 Compare November 27, 2026 10:21
maxwbuckley and others added 2 commits November 27, 2026 12:26
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
maxwbuckley force-pushed the enable-compiler-warnings branch from 9f815a5 to 9ef63cc Compare November 27, 2026 11:26

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution PRs from external contributor outside the core maintainers, representing community-driven work.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant