Multiple torch.load in one file fails with 1.6.0

Dear all,

The following code was working fine with pytorch 1.5.0 and is now failing:

with open('test.pkl', 'wb') as f:, f), f)

with open('test.pkl', 'rb') as f:
    assert torch.load(f) == 4
    assert torch.load(f) == 5

I get the following error

~/anaconda3/envs/env38/lib/python3.8/site-packages/torch/ in load(f, map_location, pickle_module, **pickle_load_args)
    583                     return torch.jit.load(opened_file)
    584                 return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
--> 585         return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)

~/anaconda3/envs/env38/lib/python3.8/site-packages/torch/ in _legacy_load(f, map_location, pickle_module, **pickle_load_args)
    753             "functionality.".format(type(f)))
--> 755     magic_number = pickle_module.load(f, **pickle_load_args)
    756     if magic_number != MAGIC_NUMBER:
    757         raise RuntimeError("Invalid magic number; corrupt file?")

UnpicklingError: A load persistent id instruction was encountered,
but no persistent_load function was specified.


Thanks for reporting this. It does look like a regression. Could you open an issue on github please?

OK! Done here

1 Like