Skip to content

Commit b0e070e

Browse files
authored
remove MOCKGPU workaround in rand (tinygrad#9565)
also `requires_grad_` to save a line
1 parent d7c754c commit b0e070e

File tree

1 file changed

+1
-9
lines changed

1 file changed

+1
-9
lines changed

tinygrad/tensor.py

+1-9
Original file line numberDiff line numberDiff line change
@@ -507,9 +507,6 @@ def rand(*shape, device:str|None=None, dtype:DTypeLike|None=None, contiguous:boo
507507
if (numel := prod(shape)) == 0: return Tensor.zeros(shape, device=_device, dtype=dtype, **kwargs)
508508
num = ceildiv(numel * dtype.itemsize, 4)
509509

510-
# when using MOCKGPU and NV generate rand on CPU
511-
if getenv("MOCKGPU") and device.startswith("NV"): device = "CPU"
512-
513510
# generate per device seeds and rng counter if we haven't seen this device yet
514511
if device not in Tensor._device_seeds:
515512
Tensor._device_seeds[device] = Tensor(
@@ -532,12 +529,7 @@ def rand(*shape, device:str|None=None, dtype:DTypeLike|None=None, contiguous:boo
532529
one = Tensor.ones_like(bits, device=bits.device, dtype=dtype).bitcast(uint_dtype)
533530
bits = bits.rshift((dtype.itemsize * 8) - nmant).bitwise_or(one)
534531
# bitcast back to the original dtype and reshape
535-
out = bits.bitcast(dtype)[:numel].sub(1).reshape(shape)
536-
537-
# move back to the original device if we were using MOCKGPU
538-
if getenv("MOCKGPU") and _device: out = out.to(_device)
539-
540-
out.requires_grad = kwargs.get("requires_grad")
532+
out = bits.bitcast(dtype)[:numel].sub(1).reshape(shape).requires_grad_(kwargs.get("requires_grad"))
541533
return out.contiguous() if contiguous else out
542534

543535
# ***** creation helper functions *****

0 commit comments

Comments
 (0)