greta-dev / greta

simple and scalable statistical modelling in R
https://greta-stats.org
Other
532 stars 63 forks source link

Fix M1 greta installation issues #458

Closed njtierney closed 3 months ago

njtierney commented 3 years ago

As noted in #424 by @flyaflya :

Python is unfindable by greta even though the Python environment seems to be setup correctly. Have you discovered this and any workarounds? Seems the reticulate folks are aware of this: https://github.com/rstudio/reticulate/issues?q=is%3Aissue+is%3Aopen+M1

I don't think there is an M1 mac image on GitHub runners yet, but I can at least test this locally.

njtierney commented 3 years ago

See these installation instructions from @juliasilge:

https://gist.github.com/juliasilge/035d54c59436604d6142ebebf29aa224

We might also need to upgrade to tensorflow 2.0 in order to support this on M1 macs...

outlace commented 2 years ago

Yeah - I think TF2 would fix this issue as there is native build of TF2 for mac m1

njtierney commented 2 years ago

I can confirm that the following works on my M1 mac

# this version, 0.15.0 requires TF 2.7.0...
reticulate::py_install(packages = "tensorflow==2.6.0", pip = TRUE)
reticulate::py_module_available(module = "tensorflow")

reticulate::py_install(packages = "tensorflow-probability==0.14.1", pip = TRUE)
reticulate::py_module_available(module = "tensorflow_probability")

However, there are still a few things that need to be addressed, in #306 before I can confidently close this issue

adamramey commented 2 years ago

I can confirm that the following works on my M1 mac

# this version, 0.15.0 requires TF 2.7.0...
reticulate::py_install(packages = "tensorflow==2.6.0", pip = TRUE)
reticulate::py_module_available(module = "tensorflow")

reticulate::py_install(packages = "tensorflow-probability==0.14.1", pip = TRUE)
reticulate::py_module_available(module = "tensorflow_probability")

However, there are still a few things that need to be addressed, in #306 before I can confidently close this issue

I tried doing this on my M1 but no luck. Everything is installed as per

**reticulate::py_config() python: /Users/ajr7/Library/r-miniconda-arm64/envs/greta-env/bin/python libpython: /Users/ajr7/Library/r-miniconda-arm64/envs/greta-env/lib/libpython3.8.dylib pythonhome: /Users/ajr7/Library/r-miniconda-arm64/envs/greta-env:/Users/ajr7/Library/r-miniconda-arm64/envs/greta-env version: 3.8.12 | packaged by conda-forge | (default, Jan 30 2022, 23:13:24) [Clang 11.1.0 ] numpy: /Users/ajr7/Library/r-miniconda-arm64/envs/greta-env/lib/python3.8/site-packages/numpy numpy_version: 1.19.5 tensorflow: /Users/ajr7/Library/r-miniconda-arm64/envs/greta-env/lib/python3.8/site-packages/tensorflow

NOTE: Python version was forced by use_python function**

But when I load greta and try to use it, it says

Loaded Tensorflow version 2.7.0ing dependencies, this may take a moment. x Initialising python and checking dependencies, this may take a moment. ... failed Error: We have detected that you do not have the expected python packages setup. You can set these up by running this R code in the console: install_greta_deps() Then, restart R and run: library(greta) (Note: Your R session should not have initialised Tensorflow yet.) For more information, see ?install_greta_deps

I do this and it does nothing.

njtierney commented 2 years ago

Hi there @adamramey !

Thanks so much for trying this out, really appreciate it!

I should have communicated what is needing to happen before I can implement this.

I'm currently implementing the TF2 features here: https://github.com/greta-dev/greta/pull/482

You can install it with:

remotes::install_github("greta-dev/greta#482")

So far this PR changes the way greta checks for python dependencies - so we can use TF2 and TFP 14.1, but there is still a bit more to be done.

At the moment it is only for proof of concept testing, I'm getting some low level issues regarding the way tensors are constructed, which I am still debugging. And currently all you can do is create variables in greta, but it doesn't let you do any modelling

I'm really keen to have people test this out, would I be able to tag you here on this issue when I've got something I think might be a bit more stable to release?

adamramey commented 2 years ago

Thanks so much @njtierney! Installed this and managed to get things working - at least for variable creation.

I'm definitely down for testing and happy to be tagged going forward. Thanks again for this really great package.

njtierney commented 2 years ago

The current progress is that it looks like we need to get TensorFlow 2.0.0 to work with M1 macs, since only TF2.6 is built for M1 macs, and we cannot go earlier than TF2. So we need to also resolve #306

njtierney commented 1 year ago

I believe this has now been resolved with the new install_greta_deps() function in the dev branch of greta