Torch.save FileNotFoundError

when i try to call torch.save to save my model in a tmp_file, it rises a FileNotFoundError. the trace back is as follow:

Traceback (most recent call last):
File “C:/Users/Haoran/Documents/GitHub/dose-response/python/simulations/hdr.py”, line 234, in
test_hdr_continuous()
File “C:/Users/Haoran/Documents/GitHub/dose-response/python/simulations/hdr.py”, line 195, in test_hdr_continuous
model = fit_mdn(X[:split], y[:split], nepochs=20)
File “C:\Users\Haoran\Documents\GitHub\dose-response\python\simulations\continuous.py”, line 192, in fit_mdn
torch.save(model, tmp_file)
File “C:\Users\Haoran\Documents\GitHub\dose-response\python\venv\lib\site-packages\torch\serialization.py”, line 161, in save
return _with_file_like(f, “wb”, lambda f: _save(obj, f, pickle_module, pickle_protocol))
File “C:\Users\Haoran\Documents\GitHub\dose-response\python\venv\lib\site-packages\torch\serialization.py”, line 116, in _with_file_like
f = open(f, mode)
FileNotFoundError: [Errno 2] No such file or directory: ‘/tmp/tmp_file_4358f298-a1d9-4c81-9e44-db4d8f1b4319’

it is weird that everything works perfectly on my mac, but I got this error on my Windows desktop

Hi,

Does the /tmp folder exists on windows? How do you generate the temporary file name? Is it a valid windows filename?

Found any solution?
Even I face the same problem.

The problem here was that the path does not exist on windows machines. So if you’re using windows, you should set a path that matches a windows machines, not Unix machine.

Actually, the path existed. But, I had a weird file name. I think, that’s the reason why it wasn’t behaving as expected. Thanks @albanD