diff --git a/tinygrad/ops_gpu.py b/tinygrad/ops_gpu.py index 6cb3279e75..c1126e97db 100644 --- a/tinygrad/ops_gpu.py +++ b/tinygrad/ops_gpu.py @@ -67,7 +67,7 @@ class Exp(Function): class Sign(Function): @staticmethod def forward(ctx, input): - return unary_op(ctx, 'a >= 0', input) + return unary_op(ctx, '(a > 0) - (a < 0)', input) @staticmethod def backward(ctx, grad_output): diff --git a/tinygrad/tensor.py b/tinygrad/tensor.py index 332dd2dc0b..590fbd1609 100644 --- a/tinygrad/tensor.py +++ b/tinygrad/tensor.py @@ -274,7 +274,7 @@ class Tensor: return self * (self.softplus().tanh()) # x*tanh(softplus(x)) def abs(self): - return self.relu() + (-1.0*self).relu() + return self * self.sign() def _pool2d(self, py, px): xup = self[:, :, :self.shape[2]-self.shape[2]%py, :self.shape[3]-self.shape[3]%px]