From 8694eeb16d626b509ef1aed991250ee73da1cab3 Mon Sep 17 00:00:00 2001 From: chenyu Date: Wed, 15 May 2024 15:46:33 -0400 Subject: [PATCH] Revert "simpler abs and sign (#4606)" (#4608) This reverts commit a5e157f663d2f7a2327a490871bab4dfc5075e2e. --- tinygrad/tensor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tinygrad/tensor.py b/tinygrad/tensor.py index 3acd10be9f21..ab0b784007db 100644 --- a/tinygrad/tensor.py +++ b/tinygrad/tensor.py @@ -1151,8 +1151,8 @@ def round(self: Tensor) -> Tensor: def lerp(self, end: Tensor, weight: Union[Tensor, float]) -> Tensor: return self + (end - self) * weight def square(self): return self*self def clip(self, min_, max_): return self.maximum(min_).minimum(max_) - def abs(self): return (self < 0).detach().where(-self, self) - def sign(self): return (self == 0).detach().where(0, self / self.abs()).cast(self.dtype) + def abs(self): return self.relu() + (-self).relu() + def sign(self): return ((self.float()) / (self.float().abs() + 1e-12)).cast(self.dtype) def reciprocal(self): return F.Reciprocal.apply(self.cast(least_upper_float(self.dtype))) # ***** activation functions (unary) *****