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

How do I install a specific PyTorch version in rTorch #4

Open
f0nzie opened this issue Aug 10, 2020 · 7 comments
Open

How do I install a specific PyTorch version in rTorch #4

f0nzie opened this issue Aug 10, 2020 · 7 comments

Comments

@f0nzie
Copy link
Owner

f0nzie commented Aug 10, 2020

No description provided.

@f0nzie
Copy link
Owner Author

f0nzie commented Aug 10, 2020

From the R prompt in RStudio.

This will install the latest stable PyTorch for Python 3.6:

rTorch:::install_conda(package="pytorch", envname="r-torch", conda="auto", conda_python_version = "3.6", pip=FALSE, channel="pytorch", extra_packages=c("torchvision", "cpuonly", "matplotlib", "pandas"))

This will install PyTorch 1.2 under Python 3.7:

rTorch:::install_conda(package="pytorch=1.2", envname="r-torch", conda="auto", conda_python_version = "3.7", pip=FALSE, channel="pytorch", extra_packages=c("torchvision", "cpuonly", "matplotlib", "pandas"))

This will install PyTorch 1.5 under Python 3.8:

rTorch:::install_conda(package="pytorch=1.5", envname="r-torch", conda="auto", conda_python_version = "3.8", pip=FALSE, channel="pytorch", extra_packages=c("torchvision", "cpuonly", "matplotlib", "pandas", "bokeh"))

These commands have been tested in:

  • MacOS Mojave running R 3.6 inside RStudio 1.2.5001. rTorch 0.0.3 was installed from CRAN.
  • Windows 10 running R 3.6 inside RStudio 1.3.959. rTorch 0.0.3 was installed from CRAN.

@beew
Copy link

beew commented Aug 23, 2020

Hi, I wonder if there is a way for rTorch to choose from among python and pytorch versions already installed in the system without conda. What I mean is like tenorflow-r, where you can use the function use_python('path/to/python/binary") or Sys.setenv(RETICULATE_PYTHON="path/to/python/binary") to choose from the python versions already installed in the system without needing to create a conda along with all the extra junks that it pulls in.

I have 4 pythons on my system. python2.7 and python3.5.4 which come with the system and I don't use for developmental purpose. I have python-3.7.8 and 3.8.5 installed in local folders for development (each with its own configuration script) and I have tested tensorflow-r using the use_python function and the RETICULATE_PYTHON environmental variable described above. Is it possible to do something similar with rTorch?

OS is Ubuntu Linux.

@beew
Copy link

beew commented Aug 29, 2020

OK, it works just like r-tensorflow. use_python() will do the job

@f0nzie
Copy link
Owner Author

f0nzie commented Aug 30, 2020

I borrowed functions from reticulate and tensorflow for the PyTorch installation under Python. I adapted those functions for PyTorch. They worked fine until PyTorch 1.2. Then, PyTorch introduced changes that made it a little bit different. So, my function install_pytorch() stopped working. But the lower level functions do work. Such as rTorch:::install_conda(). I am working these days on a newer version that takes changes in PyTorch 1.6. If you want to try, all is the develop branch.

@beew
Copy link

beew commented Aug 30, 2020

Actually I just tested with PyTorch-1.4 and it works.

@beew
Copy link

beew commented Aug 30, 2020

Actually it works for PyTorch 1.6.0 as well (I have several pythons installed locally) , except for a small issue with reticulate rstudio/reticulate#836 (comment)

R version 4.0.2 (2020-06-22) -- "Taking Off Again"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> Sys.setenv(LD_LIBRARY_PATH = paste("/home/bee/opt/python385/lib", Sys.getenv("LD_LIBRARY_PATH"), sep = ":"))
> library(rTorch)
> use_python("/home/bee/opt/python385/bin/python")
> torch_config()
PyTorch v1.6.0 (~/opt/python385/lib/python3.8/site-packages/torch)

Python v3.8 (~/opt/python385/bin/python)

> bt <- torch$ByteTensor(3L, 3L)
> ft <- torch$FloatTensor(3L, 3L)
> dt <- torch$DoubleTensor(3L, 3L
+ )
> lt <- torch$LongTensor(3L, 3L)
> Bt <- torch$BoolTensor(5L, 5L)
> ft
tensor([[1.2019e+36, 4.5758e-41, 1.2019e+36],
        [4.5758e-41, 0.0000e+00, 0.0000e+00],
        [0.0000e+00, 0.0000e+00, 0.0000e+00]])
> Bt
tensor([[ True,  True,  True,  True,  True],
        [ True, False, False,  True,  True],
        [ True,  True,  True,  True, False],
        [False,  True, False, False, False],
        [False, False, False, False,  True]])
> 

@f0nzie
Copy link
Owner Author

f0nzie commented Aug 30, 2020

Awesome!

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