ID: PyTorch PR-2
Summary of Upstream Work
Investigated and resolved a silent miscompilation bug in torch.compile where abs() operations on unsigned integer tensors (such as uint8) routed through the C++ codegen produced incorrect downstream graph results (Fixes #187018).
Engineering Execution
-
Root Cause Diagnostics: Identified that the TorchInductor CPU codegen emitted
std::abs({x})unconditionally for scalar paths. In C++,std::abslacks an overload for unsigned types, triggering implicit signed integer promotion that broke critical downstream unsigned wrap-around semantics during negation and reduction. -
Fix: Modified
CppOverrides.abs()withintorch/_inductor/codegen/cpp.pyto handle types explicitly. Unsigned integers now bypass C++ math entirely as an identity operation (x), signed integers utilize a typed ternary bypass to avoid implicit promotion, and floating-point paths preserve the standardstd::abs({x})fallback. -
Validation & Testing: Authored a targeted regression unit test (
test_uint8_abs_codegen_issue_187018) withintest/inductor/test_torchinductor.pyunderCpuTests. Verified that eager and compiled outputs now align flawlessly with strict parity.
Comments 0
No comments yet. Be the first!
Sign in to join the conversation.