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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reading a .pt files gives an error #58

Closed
Het-Shah opened this issue Sep 14, 2021 · 5 comments
Closed

Reading a .pt files gives an error #58

Het-Shah opened this issue Sep 14, 2021 · 5 comments

Comments

@Het-Shah
Copy link

Het-Shah commented Sep 14, 2021

Hi! I have been trying to use ocaml-torch to load a PyTorch model that has already been trained. I have installed PyTorch 1.9.0 which is what is compatible with ocaml-torch. Upon trying to load the file, it throws the following error

Fatal error: exception (Failure
"version_number <= kMaxSupportedFileFormatVersion ASSERT FAILED at /pytorch/caffe2/serialize/inline_container.cc:131, please report a bug to PyTorch. Attempted to read a PyTorch file with version 4, but the maximum supported version for reading is 1. Your PyTorch installation may be too old. (init at /pytorch/caffe2/serialize/inline_container.cc:131)\

Can you suggest what can be done in this case? Thank you!

Edit: Source code
python file -

net = CNN()
net.eval()
example = torch.rand(16384)
traced = torch.jit.trace(net, example)
traced.save("./models/feat.pt")

ocaml file -

open Base
open Torch

let model = Module.load "../models/feat.pt" ;;

@LaurentMazare
Copy link
Owner

That seems very odd, if you look at the pytorch code triggering this here, this uses kMaxSupportedFileFormatVersion which is set to 6 in pytorch 1.9. This constant was set to 1 only for versions <= 1.3, also the line number in your error message doesn't match 1.9 so maybe you're not building or linking with pytorch 1.9 properly?

@Het-Shah
Copy link
Author

Het-Shah commented Sep 15, 2021

The PyTorch version in my conda environment is set to 1.9.0. Is it possible that ocaml is taking some other environment's pytorch version?

>>> import torch 
>>> print(torch.__version__)
1.9.0

(My base conda environment doesn't have pytorch installed.)

@Het-Shah
Copy link
Author

Sorry for a lot of doubts, but does opam-torch v0.7 correspond to pytorch 1.9.0 (given in README) or is it v0.13?

@Het-Shah
Copy link
Author

Sorry for a lot of doubts, but does opam-torch v0.7 correspond to pytorch 1.9.0 (given in README) or is it v0.13?

Seems like this was the issue. I upgraded to v0.13 and reboot the system (reboot was necessary). And it seems to work. Thanks @LaurentMazare!

@LaurentMazare
Copy link
Owner

Closing this at it seems fixed now, feel free to re-open if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants