tinygrad / tinygrad

You like pytorch? You like micrograd? You love tinygrad! ❤️

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fail to run examples with DISK=1

junaire opened this issue · comments

Not sure what disk runtime is used for, but it fails with the following example:

DISK=1 python3 -c "from tinygrad import Tensor; x = Tensor([1]); y = Tensor([2]); (x+y).realize()"

Errors:

Traceback (most recent call last):
  File "/home/jun/Documents/tinygrad/venv/lib/python3.10/site-packages/tinygrad-0.9.1-py3.10.egg/tinygrad/runtime/ops_disk.py", line 89, in _might_open
    try: self.fd = os.open(filename, os.O_RDWR|os.O_CREAT|(0 if OSX else os.O_DIRECT))
FileNotFoundError: [Errno 2] No such file or directory: ''

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/jun/Documents/tinygrad/venv/lib/python3.10/site-packages/tinygrad-0.9.1-py3.10.egg/tinygrad/tensor.py", line 3161, in _wrapper
    ret = fn(*args, **kwargs)
  File "/home/jun/Documents/tinygrad/venv/lib/python3.10/site-packages/tinygrad-0.9.1-py3.10.egg/tinygrad/tensor.py", line 203, in realize
    run_schedule(*self.schedule_with_vars(*lst), do_update_stats=do_update_stats)
  File "/home/jun/Documents/tinygrad/venv/lib/python3.10/site-packages/tinygrad-0.9.1-py3.10.egg/tinygrad/engine/realize.py", line 225, in run_schedule
    ei.run(var_vals, do_update_stats=do_update_stats)
  File "/home/jun/Documents/tinygrad/venv/lib/python3.10/site-packages/tinygrad-0.9.1-py3.10.egg/tinygrad/engine/realize.py", line 175, in run
    bufs = [cast(Buffer, x) for x in self.bufs] if jit else [cast(Buffer, x).ensure_allocated() for x in self.bufs]
  File "/home/jun/Documents/tinygrad/venv/lib/python3.10/site-packages/tinygrad-0.9.1-py3.10.egg/tinygrad/engine/realize.py", line 175, in <listcomp>
    bufs = [cast(Buffer, x) for x in self.bufs] if jit else [cast(Buffer, x).ensure_allocated() for x in self.bufs]
  File "/home/jun/Documents/tinygrad/venv/lib/python3.10/site-packages/tinygrad-0.9.1-py3.10.egg/tinygrad/device.py", line 78, in ensure_allocated
    def ensure_allocated(self) -> Buffer: return self.allocate() if not hasattr(self, '_buf') else self
  File "/home/jun/Documents/tinygrad/venv/lib/python3.10/site-packages/tinygrad-0.9.1-py3.10.egg/tinygrad/device.py", line 87, in allocate
    self._buf = opaque if opaque is not None else self.allocator.alloc(self.nbytes, self.options)
  File "/home/jun/Documents/tinygrad/venv/lib/python3.10/site-packages/tinygrad-0.9.1-py3.10.egg/tinygrad/device.py", line 136, in alloc
    return self._alloc(size, options if options is not None else BufferOptions())
  File "/home/jun/Documents/tinygrad/venv/lib/python3.10/site-packages/tinygrad-0.9.1-py3.10.egg/tinygrad/runtime/ops_disk.py", line 20, in _alloc
    self.device._might_open(size)
  File "/home/jun/Documents/tinygrad/venv/lib/python3.10/site-packages/tinygrad-0.9.1-py3.10.egg/tinygrad/runtime/ops_disk.py", line 90, in _might_open
    except OSError: self.fd = os.open(filename, os.O_RDWR|os.O_CREAT)
FileNotFoundError: [Errno 2] No such file or directory: ''

So it try to open a file with filename, but it's an empty string.

filename comes from:

filename = self.dname[len("disk:"):]

and self.dname is a str DISK, so it doesn't feel right...

OK, i investigated a little bit, looks like we need to specify the device name?

Tensor.empty((4,), dtype=dtypes.int8, requires_grad=True, device=f"DISK:{tmp}").bitcast(dtypes.float16)

maybe we should assign a random file if that's not specified.