Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

torch.load() - OSError on a file larger than 2GB #26998

Closed
Roffild opened this issue Sep 27, 2019 · 5 comments
Closed

torch.load() - OSError on a file larger than 2GB #26998

Roffild opened this issue Sep 27, 2019 · 5 comments
Labels
module: windows Windows support for PyTorch triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Milestone

Comments

@Roffild
Copy link
Contributor

Roffild commented Sep 27, 2019

馃悰 Bug

In version 1.2, torch.load() does not work with files larger than 2GB.

import torch
import pathlib
torch.save(torch.rand(int((2 * 1024**3) / 4), dtype=torch.float32, device="cpu"),
           pathlib.Path("pytorch_test_load.temp"))
torch.load(pathlib.Path("pytorch_test_load.temp"))
 File "torch\serialization.py", line 581, in _load
    deserialized_objects[key]._set_from_file(f, offset, f_should_read_directly)
OSError: [Errno 22] Invalid argument

This is probably due to #20270 or #20900

Windows 10
Python 3.7
Pytorch 1.2.0

cc @ezyang @gchanan @zou3519 @peterjc123

@peterjc123
Copy link
Collaborator

Since these PRs are merged, could you please try whether the nightly one solves this issue?

@Akamight
Copy link

Nope. It doesn't fix it. Running torch-1.3.0.dev20190924 on Python 3.6.8 still yields the error.

@Akamight
Copy link

Looks like force setting f_should_read_directly = False before this block in serialization.py

    offset = f.tell() if f_should_read_directly else None
    for key in deserialized_storage_keys:
        assert key in deserialized_objects
        #print(deserialized_objects[key])
        deserialized_objects[key]._set_from_file(f, offset, f_should_read_directly)
        if offset is not None:
            offset = f.tell()

seems to solve the problem

@philippslang
Copy link
Contributor

The long cast in #20900 limits the file offset to a 32 bit integer, hence the >2G issues.

peterjc123 pushed a commit to peterjc123/pytorch that referenced this issue Sep 30, 2019
Summary:
Fixes pytorch#26998
Pull Request resolved: pytorch#27047

Differential Revision: D17666050

Pulled By: ezyang

fbshipit-source-id: f02ebd5320ae25f8949be20d0744fe3cd3e2fee9
(cherry picked from commit 1afe3fc)
@ezyang ezyang reopened this Sep 30, 2019
@ezyang ezyang added critical module: windows Windows support for PyTorch triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module labels Sep 30, 2019
@ezyang ezyang added this to the 1.3 milestone Sep 30, 2019
@ezyang
Copy link
Contributor

ezyang commented Sep 30, 2019

The fix is getting reverted as it breaks Windows CI

peterjc123 pushed a commit to peterjc123/pytorch that referenced this issue Oct 1, 2019
Summary:
Fixes pytorch#26998
Pull Request resolved: pytorch#27047

Differential Revision: D17666050

Pulled By: ezyang

fbshipit-source-id: f02ebd5320ae25f8949be20d0744fe3cd3e2fee9
(cherry picked from commit 1afe3fc)
(cherry picked from commit 5846008)
soumith pushed a commit that referenced this issue Oct 4, 2019
* Fixed seek offset size to 64bit. (#27047)

Summary:
Fixes #26998
Pull Request resolved: #27047

Differential Revision: D17666050

Pulled By: ezyang

fbshipit-source-id: f02ebd5320ae25f8949be20d0744fe3cd3e2fee9
(cherry picked from commit 1afe3fc)

* Use _lseeki64 instead for MSVC

(cherry picked from commit f49f78d)
pdlive215 pushed a commit to pdlive215/pytorch that referenced this issue Nov 27, 2019
Summary:
Fixes pytorch#26998
Pull Request resolved: pytorch#27047

Differential Revision: D17666050

Pulled By: ezyang

fbshipit-source-id: f02ebd5320ae25f8949be20d0744fe3cd3e2fee9
pdlive215 pushed a commit to pdlive215/pytorch that referenced this issue Nov 27, 2019
Summary:
Fixes pytorch#26998.
Pull Request resolved: pytorch#27125

Differential Revision: D17687154

Pulled By: ezyang

fbshipit-source-id: 6784f4fd799130ac72a25884f120a0ba96bd4f51
thiagocrepaldi pushed a commit to thiagocrepaldi/pytorch that referenced this issue Feb 4, 2020
Summary:
Fixes pytorch#26998
Pull Request resolved: pytorch#27047

Differential Revision: D17666050

Pulled By: ezyang

fbshipit-source-id: f02ebd5320ae25f8949be20d0744fe3cd3e2fee9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: windows Windows support for PyTorch triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
5 participants