mirror of
https://github.com/tinygrad/tinygrad.git
synced 2026-01-09 15:08:02 -05:00
Fix Tensor's __repr__ for printing out grad (#3673)
* update check for Tensor's __repr__ with grad * add test for repr with grad bugfix
This commit is contained in:
@@ -334,6 +334,12 @@ class TestTinygrad(unittest.TestCase):
|
||||
with self.assertRaises(TypeError):
|
||||
_a = Tensor([3]) in [Tensor([3]), Tensor([4]), Tensor([5])]
|
||||
|
||||
def test_repr_with_grad(self):
|
||||
a = Tensor([1])
|
||||
b = Tensor([1])
|
||||
c = (a + b).mean().backward()
|
||||
print(c)
|
||||
|
||||
@unittest.skipIf(CI and Device.DEFAULT in {"GPU", "CUDA", "METAL"}, "no GPU CI")
|
||||
class TestMoveTensor(unittest.TestCase):
|
||||
d0, d1 = f"{Device.DEFAULT}:0", f"{Device.DEFAULT}:1"
|
||||
|
||||
@@ -111,7 +111,7 @@ class Tensor:
|
||||
else:
|
||||
self.lazydata = data if data.device == device else data.copy_to_device(device)
|
||||
|
||||
def __repr__(self): return f"<Tensor {self.lazydata!r} on {self.device} with grad {(self.grad.lazydata if self.grad else None)!r}>"
|
||||
def __repr__(self): return f"<Tensor {self.lazydata!r} on {self.device} with grad {(self.grad.lazydata if self.grad is not None else None)!r}>"
|
||||
|
||||
# Python has a non moving GC, so this should be okay
|
||||
def __hash__(self): return id(self)
|
||||
|
||||
Reference in New Issue
Block a user