EOFError: Ran out of input, using torch.load()
I saw this error being posted a lot and often it was due to the file not being closed properly after opening. But since I'm using the integrated torch.load() function, I'm not sure what I could do different.

First the saving part:

    torch.save({
            'model_state_dict': agent.dqn.state_dict(),
             ...
            'loss_history': agent.losshistory
            }, modelpath)


and here the loading part, where I also get the error message:

if os.path.exists(modelpath):
    checkpoint = torch.load(modelpath)
    agent.dqn.load_state_dict(checkpoint['model_state_dict'])
    ...
    agent.losshistory = checkpoint['loss_history']


and here the error:

Traceback (most recent call last):
  File "c:/Users/levin/Desktop/programming/main.py", line 33, in &lt;module&gt;
    checkpoint = torch.load(modelpath)
  File "C:\Users\levin\AppData\Local\Programs\Python\Python37\lib\site-packages\torch\serialization.py", line 529, in load
    return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)
  File "C:\Users\levin\AppData\Local\Programs\Python\Python37\lib\site-packages\torch\serialization.py", line 702, in _legacy_load
    result = unpickler.load()
EOFError: Ran out of input


One more thing I want to mention is that I used this exact code several times without a problem. I can't remember changing anything that could have caused the error.

According to this thread it seems to raise an exception when reading an empty file, so please check the size of the document before reading it and post a response if it is not solved.
