remove Tensor.detach override [pr] (#16239)

This commit is contained in:
chenyu
2026-05-16 23:58:12 -04:00
committed by GitHub
parent dcee90aa3f
commit fcdd1af880
2 changed files with 3 additions and 7 deletions
+3 -1
View File
@@ -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:
-6
View File
@@ -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"):