pytorch - 💡(How to fix) Fix Dead code: TritonOverrides.pow integer fast path is unreachable [1 comments, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
pytorch/pytorch#184376Fetched 2026-05-20 03:39:02
View on GitHub
Comments
1
Participants
1
Timeline
46
Reactions
0
Author
Participants
Timeline (top)
mentioned ×20subscribed ×20labeled ×4closed ×1

The is_integer_dtype(result_dtype) branch in TritonOverrides.pow (torch/_inductor/codegen/triton.py) that calls triton_helpers.pow_integer is dead code — no lowering path ever produces an integer result_dtype through ops.pow.

Root Cause

The pow lowering in torch/_inductor/lowering.py diverts all integer cases before they reach ops.pow:

CaseWhat happensReaches ops.pow?
int_tensor ** constant_intpow_recursive unrolls to x * x * ...No
int_tensor ** int_tensorFalls back to ATen (fallback_pow_tensor_tensor)No
float_tensor ** anythingpow_nativeops.powYes, but result_dtype is float

Since all integer pow cases are handled before reaching ops.pow, the guard if result_dtype is not None and is_integer_dtype(result_dtype) in TritonOverrides.pow never fires.

Code Example

# torch/_inductor/codegen/triton.py
@classmethod
def pow(cls, a, b):
    result_dtype = get_dtype_handler().pow(a, b)
    if result_dtype is not None and is_integer_dtype(result_dtype):
        base = cls._cast_libdevice_arg(a, result_dtype)
        exponent = (
            cls.constant(b, torch.int64)
            if isinstance(b, torch._prims_common.Number)
            else f"{b}"
        )
        return f"triton_helpers.pow_integer({base}, {exponent})"
    ...
RAW_BUFFERClick to expand / collapse

Description

The is_integer_dtype(result_dtype) branch in TritonOverrides.pow (torch/_inductor/codegen/triton.py) that calls triton_helpers.pow_integer is dead code — no lowering path ever produces an integer result_dtype through ops.pow.

Analysis

The pow lowering in torch/_inductor/lowering.py diverts all integer cases before they reach ops.pow:

CaseWhat happensReaches ops.pow?
int_tensor ** constant_intpow_recursive unrolls to x * x * ...No
int_tensor ** int_tensorFalls back to ATen (fallback_pow_tensor_tensor)No
float_tensor ** anythingpow_nativeops.powYes, but result_dtype is float

Since all integer pow cases are handled before reaching ops.pow, the guard if result_dtype is not None and is_integer_dtype(result_dtype) in TritonOverrides.pow never fires.

Location

# torch/_inductor/codegen/triton.py
@classmethod
def pow(cls, a, b):
    result_dtype = get_dtype_handler().pow(a, b)
    if result_dtype is not None and is_integer_dtype(result_dtype):
        base = cls._cast_libdevice_arg(a, result_dtype)
        exponent = (
            cls.constant(b, torch.int64)
            if isinstance(b, torch._prims_common.Number)
            else f"{b}"
        )
        return f"triton_helpers.pow_integer({base}, {exponent})"
    ...

Suggestion

Either:

  1. Remove the dead branch and simplify TritonOverrides.pow, or
  2. Route integer aten.pow.Tensor_Tensor through Triton (removing the ATen fallback) and rely on this code path for correctness.

Option 2 would also benefit from verifying that triton_helpers.pow_integer works correctly when exponent is a loaded tensor element (vs a kernel arg or tl.full literal), since tl.static_range(exponent.dtype.primitive_bitwidth) requires the bitwidth to be constexpr.

cc @chauhang @penguinwu @voznesenskym @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @aakhundov @coconutruben @jataylo @jansel @eellison

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

pytorch - 💡(How to fix) Fix Dead code: TritonOverrides.pow integer fast path is unreachable [1 comments, 1 participants]