From 2c6f4e4c6677d07b85c58eb0a85c6000b3145f83 Mon Sep 17 00:00:00 2001 From: Ollin Boer Bohan Date: Sun, 4 Sep 2022 13:47:27 -0700 Subject: [PATCH] Make creation helpers use fp32 by default (#374) * Make creation helpers use fp32 by default half the big = twice the fast * Fix flake8 with an extra multiply --- tinygrad/tensor.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tinygrad/tensor.py b/tinygrad/tensor.py index 9cd72b4f1f..b259d5a4e8 100644 --- a/tinygrad/tensor.py +++ b/tinygrad/tensor.py @@ -90,17 +90,17 @@ class Tensor: def empty(cls, *shape, **kwargs): return cls(np.empty(shape, dtype=np.float32), **kwargs) @classmethod - def randn(cls, *shape, **kwargs): return cls(np.random.randn(*shape).astype(np.float32), **kwargs) + def randn(cls, *shape, **kwargs): return cls(np.random.default_rng().standard_normal(size=shape, dtype=np.float32), **kwargs) @classmethod - def arange(cls, stop, start=0, **kwargs): return cls(np.arange(start=start, stop=stop).astype(np.float32), **kwargs) + def arange(cls, stop, start=0, **kwargs): return cls(np.arange(start=start, stop=stop, dtype=np.float32), **kwargs) # TODO: uniform should be a late binding thing @classmethod - def uniform(cls, *shape, **kwargs): return cls((np.random.uniform(-1., 1., size=shape)/np.sqrt(prod(shape))).astype(np.float32), **kwargs) + def uniform(cls, *shape, **kwargs): return cls(((np.random.default_rng().random(size=shape, dtype=np.float32) * 2 - 1) * prod(shape)**-0.5), **kwargs) @classmethod - def eye(cls, dim, **kwargs): return cls(np.eye(dim).astype(np.float32), **kwargs) + def eye(cls, dim, **kwargs): return cls(np.eye(dim, dtype=np.float32), **kwargs) # ***** toposort and backward pass *****