mlverse / torch

R Interface to Torch
https://torch.mlverse.org
Other
489 stars 64 forks source link

Cannot install lantern dependencies on aarm64 architecture #1182

Open bagdaddy opened 1 month ago

bagdaddy commented 1 month ago

Hello, whenever I try to install and use torch, it says that I don't have certain dependencies installed (lantern). I went through all documentation and I still don't get how I can achieve that manually.

When I try to get the physical files for manual installation, I get an error that my architecture is unsupported. I'm running a rocker/rstudio docker container on an M1 Mac computer.

What I tried:

When trying to run torch::install_torch() or get_install_libs_url I get the following error: ! Architecture "aarch64" is not supported in this OS.

I looked at the code, is this issue due to me running this in a docker container? My architecture is aarch64, but the "OS" in the container is ubuntu. How can I work around this?

Maybe someone could point me to how I can download the actual lantern lib or something? I will set the env variables for torch and lantern urls and maybe then it will get installed? I am starting to go crazy over this

dfalbel commented 1 month ago

This is unfortunatelly not a simple task as LibTorch doesn't provide pre-built binaries for aarch64 systems, so you will need to first:

  1. Build LibTorch from source (see instructions here). Make sure to point to the same version as the R package. Point the env var TORCH_HOME and TORCH_PATH to the installation directory.
  2. Make sure you have cmake installed and on the path. Set BUILD_LANTERN=1 before installing torch from source (via github or install.packages(type="source")), this will build lantern from source.

Sorry for the inconvenience about this :(

bagdaddy commented 1 month ago

Thank you for such a rapid response!

Do you mean to point to the correct python installation? Or do I need to refer to the version of R torch package? The container is running 3.10 python version.

So do I build the binaries using cmake as in the instructions you provided and then set BUILD_LANTERN=1 and run install.packages("torch", type="source')? And that should be it effectively?

dfalbel commented 1 month ago

Sorry, I meant pointing to the correct LibTorch version (currently it's 2.0.1), when building LibTorch from source:

https://github.com/mlverse/torch/blob/fe5020f62e6aa6c3c7fbce06c4aacb1e09c55db7/src/lantern/CMakeLists.txt#L4

bagdaddy commented 1 month ago

Wouldn't the version be decided by the branch name I provide when cloning the pytorch repository? In this case it would be the latest ~2.4, should I set the branch to v2.0.1 instead?

dfalbel commented 1 month ago

Yes, you have to clone from the tag v2.0.1 in order to get the correct LibTorch version.

bagdaddy commented 1 month ago

Unfortunately I'm getting this error when building the sources:

CMake Error at cmake/Dependencies.cmake:1088 (if):
  if given arguments:

    "VERSION_LESS" "3"

I tried using this to fix these errors, https://github.com/shanemcandrewai/pytorch-setup?tab=readme-ov-file, but it's not compatible with 2.0.1

Also, when I tried cloning from the main branch I didn't get these errors and I managed to run all of the steps successfully... It's when I tried to downgrad it stopped working

Torch 2.0.1 is compatible with python3.10, so I'm unsure what's wrong.

Edit: Somehow managed to build the sources using the pytorch-setup CMakeFile.txt in the link above, but now I get this output (but I'm guessing this is because removing that stuff before doesn't really fix anything):

* installing *source* package ‘torch’ ...
** package ‘torch’ successfully unpacked and MD5 sums checked
** using staged installation
CMAKE_FLAGS: 
** libs
using C++ compiler: ‘g++ (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0’
*** Building lantern!
mkdir -p ../build-lantern
cd ../build-lantern && cmake ../src/lantern -DCMAKE_INSTALL_PREFIX=/usr/local/lib/R/site-library/00LOCK-torch/00new/torch -DCMAKE_INSTALL_MESSAGE="LAZY"  && cmake --build . --target install --config Release
CMake Error: The source directory "/tmp/RtmpiNfdV5/R.INSTALL1f944316e37f/torch/src/lantern" does not exist.
Specify --help for usage, or press the help button on the CMake GUI.
make: *** [Makevars:14: lantern] Error 1
ERROR: compilation failed for package ‘torch’
* removing ‘/usr/local/lib/R/site-library/torch’
* restoring previous ‘/usr/local/lib/R/site-library/torch’

The downloaded source packages are in
    ‘/tmp/RtmpcYGbOv/downloaded_packages’
Warning message:
In install.packages("torch", type = "source") :
  installation of package ‘torch’ had non-zero exit status