prevent grouper can_chase while fusing arange [pr] (#10623)

This commit is contained in:
qazal
2025-06-05 18:50:21 +03:00
committed by GitHub
parent 69f7778985
commit 1190062812
2 changed files with 10 additions and 5 deletions
+6 -5
View File
@@ -143,13 +143,14 @@ class TestSchedule(unittest.TestCase):
root = root + functools.reduce(lambda a,b:a+b, bufs[i:i+X])
self.assertEqual(root.item(), sum(range(N)))
@unittest.expectedFailure # TODO: failing because of can_chase
def test_indexing_scalars_multiple_dims(self):
X = Tensor.randn(2, 3).realize()
xt = X[Tensor(0)][Tensor(1)]
@given(strat.sampled_from(range(2,4)), strat.sampled_from(range(2,4)), strat.sampled_from(range(0,4)), strat.sampled_from(range(0,4)))
def test_indexing_scalars(self, x, y, a, b):
assume(a<x and b<y)
X = Tensor.randn(x, y).realize()
xt = X[Tensor(a)][Tensor(b)]
with Context(FUSE_ARANGE=1):
run_schedule(check_schedule(xt, 2))
np.testing.assert_equal(xt.numpy(), X.numpy()[0][1])
np.testing.assert_equal(xt.numpy(), X.numpy()[a][b])
def test_push_pads_elementwise(self):
x = Tensor.full((4,4), 2.).contiguous().realize()
+4
View File
@@ -186,6 +186,10 @@ def group_realizes(sink:UOp) -> dict[UOp, None]:
recursive_group(r, unwrap(r.st), r, children, realizes, reduce_for_op, group, cache={})
# max one reduceop per kernel
can_chase = all(tr not in reduce_for_op for tr in group)
for u in r.toposort(gate=lambda u: u not in realizes):
if u.op is Ops.REDUCE_AXIS and u.src[0].base.op is Ops.CONST:
can_chase = False
break
# TODO: forced_realize exists because the scheduler is incapable of checking for self-contained DAGs
forced_realize = r in group
# can only have one output