From fb61f3519f10280df5815602fcf0b523d3008d39 Mon Sep 17 00:00:00 2001 From: George Hotz <72895+geohot@users.noreply.github.com> Date: Tue, 14 Oct 2025 16:42:14 +0800 Subject: [PATCH] remove assign contiguous hack (#12659) * remove assign contiguous hack * remove bad contiguous usage in torch backend * assign --- extra/torch_backend/backend.py | 6 ++---- test/test_assign.py | 1 + test/test_ops.py | 1 + tinygrad/schedule/rangeify.py | 3 --- 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/extra/torch_backend/backend.py b/extra/torch_backend/backend.py index d5993f64b0..04668ee3ef 100644 --- a/extra/torch_backend/backend.py +++ b/extra/torch_backend/backend.py @@ -155,16 +155,14 @@ def index_tensor(x, y): def zero_(x): if TORCH_DEBUG: print(f"zero_ {x.shape}") tt = unwrap(x) - # NOTE: unconditional contiguous covers if x is contiguous (match it) or if x is view (realize for inplace) - # TODO: consolidate - tt.assign(tt.zeros_like().contiguous()) + tt.assign(tt.zeros_like()) @torch.library.impl("aten::fill_.Scalar", "privateuseone") @inplace_fn("x") def fill_scalar(x, y): if TORCH_DEBUG: print(f"fill_.Scalar {x.shape} {y}") tt = unwrap(x) - tt.assign(tt.full_like(y).contiguous()) + tt.assign(tt.full_like(y)) @torch.library.impl("aten::_local_scalar_dense", "privateuseone") def _local_scalar_dense(tensor): return unwrap(tensor).item() diff --git a/test/test_assign.py b/test/test_assign.py index f3406d082e..19aafad603 100644 --- a/test/test_assign.py +++ b/test/test_assign.py @@ -129,6 +129,7 @@ class TestAssign(unittest.TestCase): @unittest.expectedFailure def test_assign_changes_realized_alt(self): return self.test_assign_changes_alt(realize=True) + @unittest.skip("assign to contiguous shouldn't change the base buffer") def test_assign_changes_buffer_alt(self): a, b = [Tensor(Tensor(0).contiguous().realize().uop.as_buf()) for _ in range(2)] Tensor.realize(a.contiguous().assign(1), b.contiguous().assign(2)) diff --git a/test/test_ops.py b/test/test_ops.py index 6e413d3dff..03aea1ffce 100644 --- a/test/test_ops.py +++ b/test/test_ops.py @@ -3177,6 +3177,7 @@ class TestOps(unittest.TestCase): def test_bitcast(self): helper_test_op([(3, 3)], lambda x: x.view(torch.int32), lambda x: x.bitcast(dtypes.int32), forward_only=True) + @unittest.skip("we have test_linalg, no need to test here. TODO: should be in torch backend tests") def test_svd(self): # test for tiny backend. real svd tests are in test_linalg A = torch.randn(5, 5) diff --git a/tinygrad/schedule/rangeify.py b/tinygrad/schedule/rangeify.py index 324c20958d..6e4ad755f7 100644 --- a/tinygrad/schedule/rangeify.py +++ b/tinygrad/schedule/rangeify.py @@ -92,9 +92,6 @@ earliest_rewrites = PatternMatcher([ # realize before assign if input permutes the target buffer (UPat(Ops.ASSIGN, src=(UPat.var("a"), UPat.var("b")), name="assign"), find_permutes), - - # contiguous buffer is buffer, this is for *correctness* of assign, not just speed - (UPat(Ops.CONTIGUOUS, name="root", src=(UPat(Ops.BUFFER),)), lambda root: root.src[0].forced_reshape(root.shape).rtag(root.tag)), ]) # *****************