2

I am trying to use a model which is already trained (I have stored the state_dict in a .pth file) in OCaml. I have been attempting to install OCaml-torch. However, I faced some issues installing and using the library.

While following the installation instructions [Downloaded and unzipped Libtorch] -

export LIBTORCH=./libtorch
git clone https://github.com/LaurentMazare/ocaml-torch.git
cd ocaml-torch
make clean
make all

I get the following error -

File "src/stubs/torch_bindings_generated.ml", line 8309, characters 2-16:
Error: Multiple definition of the type name t.
       Names must be unique in a given structure or signature.
File "src/wrapper/torch_bindings_generated.ml", line 8309, characters 2-16:
Error: Multiple definition of the type name t.
       Names must be unique in a given structure or signature.
Makefile:34: recipe for target 'all' failed
make: *** [all] Error 1

Let me know a way to overcome the above error. Thanks!

PS: Is there any other way to use a model in OCaml?

Het Shah
  • 31
  • 6
  • Does this answer your question? [pytorch load model without torchvision](https://stackoverflow.com/questions/68813681/pytorch-load-model-without-torchvision) – Be Chiller Too Nov 16 '21 at 14:41
  • Not really there are no inherent library bindings for loading pytorch functions in OCaml. I have to do a forward pass for samples in OCaml which won't be possible. Thanks! – Het Shah Nov 16 '21 at 14:45
  • Can you clarify on the issues you faced installing the library? Someone here may be able to assist. Otherwise requests for software or libraries are off-topic for SO. – Chris Nov 16 '21 at 15:09
  • 1
    Thanks, @Chris I have updated the question! Sorry for providing an unclear question earlier. – Het Shah Nov 16 '21 at 15:21
  • 1
    From the error message I can tell that you're building the bindings using a too old version of OCaml. Use `opam` to install a more modern version and try again. – ivg Nov 16 '21 at 15:49
  • If you have opam installed, you might as well use it to install ocaml-torch. – Chris Nov 16 '21 at 15:52
  • @Chris opam install torch only installs the CPU version of ocaml-torch. I would like to have a GPU accelerated version. – Het Shah Nov 16 '21 at 15:57
  • @ivg I can't really update the ocaml version. It is a dependency for the rest of the project and I couldn't find a way to install an older version of ocaml-torch with GPU compatibility. Thanks! – Het Shah Nov 16 '21 at 15:58
  • Then you're in trouble. You can try to modify the bindings but I would suggest persuading your team to upgrade the OCaml version, at least to 4.09. – ivg Nov 17 '21 at 14:54
  • You can also ask the ocaml-torch maintainers to make the bindings more portable. It is a bit of work but is doable. – ivg Nov 17 '21 at 15:01

0 Answers0