You are browsing as a guest. Sign up (or log in) to start making projects!

1h 17m 11s logged

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::abs lacks 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() within torch/_inductor/codegen/cpp.py to 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 standard std::abs({x}) fallback.
  • Validation & Testing: Authored a targeted regression unit test (test_uint8_abs_codegen_issue_187018) within test/inductor/test_torchinductor.py under CpuTests. Verified that eager and compiled outputs now align flawlessly with strict parity.
0
1

Comments 0

No comments yet. Be the first!