Skip to content

Commit fd4cccf

Browse files
authored
Keep the FACTO pow exponent representable in float32 (pytorch#24179)
Summary: `pow.Tensor_Scalar`'s `exponent` fell into `facto_testcase_gen`'s generic scalar branch, `Gt(0)` and `Le(2)`. The open lower bound makes `nextup(0) = 5e-324` an edge value. That value flushes to 0 when a float32 kernel reads it, so `0 ** 5e-324` (0 in eager, computed with a double exponent) becomes `0 ** 0 = 1` on device. The exponent now gets its own lower bound of `torch.finfo(torch.float32).tiny`. Integer exponents are unchanged (≥ 1), and the upper bound stays 2. Authored with Claude Code. Reviewed By: DrJessop Differential Revision: D127746756 Pull Request resolved: pytorch#24179
1 parent c1caad6 commit fd4cccf

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

‎backends/cadence/utils/facto_util.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,17 @@ def facto_testcase_gen( # noqa: C901
518518
spec.inspec[index].constraints.extend(
519519
[cp.Value.Ge(lambda deps, _: deps[1])]
520520
)
521+
elif in_spec.name == "exponent" and op_name == "pow.Tensor_Scalar":
522+
# A Gt(0) bound makes nextup(0) = 5e-324 an edge value, which
523+
# flushes to 0 in float32 kernels and turns 0 ** e into 0 ** 0.
524+
spec.inspec[index].constraints.extend(
525+
[
526+
cp.Value.Ge(
527+
lambda deps, dtype: torch.finfo(torch.float32).tiny
528+
),
529+
cp.Value.Le(lambda deps, dtype: 2),
530+
]
531+
)
521532
elif in_spec.name == "negative_slope" and op_name == "leaky_relu.default":
522533
# For leaky_relu, negative_slope should be in typical range (0, 1]
523534
spec.inspec[index].constraints.extend(

0 commit comments

Comments
 (0)