diff --git a/tinygrad/mixin/elementwise.py b/tinygrad/mixin/elementwise.py index e61b070c5b..7fc928ab7b 100644 --- a/tinygrad/mixin/elementwise.py +++ b/tinygrad/mixin/elementwise.py @@ -25,8 +25,10 @@ class ElementwiseMixin(DTypeMixin, CreationMixin): def usum(self, *uops) -> Self: return functools.reduce(operator.or_ if self.dtype is dtypes.bool else operator.add, argfix(*uops), self) def uprod(self, *uops) -> Self: return functools.reduce(operator.and_ if self.dtype is dtypes.bool else operator.mul, argfix(*uops), self) - # NOTE: Tensor overrides this to also set requires_grad=False def detach(self) -> Self: + """ + Returns a new tensor with the same data as this tensor, but detached from the autograd graph. + """ return self.alu(Ops.DETACH) def logical_not(self) -> Self: diff --git a/tinygrad/tensor.py b/tinygrad/tensor.py index b8a7fbc8f6..d19692f579 100644 --- a/tinygrad/tensor.py +++ b/tinygrad/tensor.py @@ -279,12 +279,6 @@ class Tensor(OpMixin): self.uop = assign return self - def detach(self) -> Tensor: - """ - Returns a new tensor with the same data as this tensor, but detached from the autograd graph. - """ - return Tensor(self.uop.detach(), requires_grad=False) - def _buffer(self) -> Buffer: from tinygrad.engine.realize import capturing if capturing and not getenv("UNSAFE_ALLOW_JIT_BUFFER"):