Skip to content

Commit

Permalink
update to use greta_deps_spec(), and other small tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
njtierney committed Aug 20, 2024
1 parent 1561d59 commit f2dd7cd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 55 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ devtools::install_github("greta-dev/greta")

The `install_greta_deps()` function helps install the Python dependencies (Google's [TensorFlow](https://www.tensorflow.org/) and [tensorflow-probability](https://github.com/tensorflow/probability)).

By default, `install_greta_deps()` installs versions TF 2.15.0, and TFP version 0.23.0, using python 3.10. To change the versions of TF, TFP, or python that you want to use, you specify the `python_deps` argument of `install_greta_deps()`, which used `greta_python_deps()`. See `?install_greta_deps()` or `?greta_python_deps()` for more information.
By default, `install_greta_deps()` installs versions TF 2.15.0, and TFP version 0.23.0, using python 3.10. To change the versions of TF, TFP, or python that you want to use, you specify the `deps` argument of `install_greta_deps()`, which used `greta_deps_spec()`. See `?install_greta_deps()` or `?greta_deps_spec()` for more information.

This helper function, `install_greta_deps()`, installs the exact pythons package versions needed. It also places these inside a conda environment, "greta-env-tf2". This isolates these exact python modules from other python installations, so that only `greta` will see them. This helps avoids installation issues, where previously you might update tensorflow on your computer and overwrite the current version needed by `greta`. Using this "greta-env-tf2" conda environment means installing other python packages should not be impact the Python packages needed by `greta`.

Expand Down
84 changes: 30 additions & 54 deletions vignettes/installation.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ We do this as it helps avoids installation issues, where previously you might up

The `install_greta_deps()` function takes three arguments:

1. `python_deps`: Specify dependencies with `greta_python_deps()`
1. `deps`: Specify dependencies with `greta_deps_spec()`
2. `timeout`: time in minutes to wait in installation before failing/exiting
3. `restart`: whether to restart R ("force" - restart R, "no", will not restart, "ask" (default) - ask the user)

You specify the version of TF TFP, or python that you want to use with `greta_python_deps()`, which has arguments:
You specify the version of TF TFP, or python that you want to use with `greta_deps_spec()`, which has arguments:

- `tf_version`
- `tfp_version`
Expand All @@ -58,96 +58,72 @@ If you specify versions of TF/TFP/Python that are not compatible with each other

If you provide an invalid installation versions, it will error and suggest some alternative installation versions.

## How we install dependencies.
## How we install dependencies

We create a separate R instances using [`callr`]() to install python dependencies using `reticulate` to talk to Python, and the R package `tensorflow`, for installing the tensorflow python module.
This is for users who want to know more about the installation process of dependencies in greta.

## More Detail on how greta installs python dependencies
We create a separate R instance using [`callr`](https://callr.r-lib.org/index.html) to install python dependencies using `reticulate` to talk to Python, and the R package `tensorflow`, for installing the tensorflow python module. We use `callr` so that we can ensure the installation of python dependencies happens in a clean R session that doesn't have python or reticulate already loaded.

## Troubleshooting installation
If miniconda isn't installed, we install miniconda. You can think of miniconda as a lightweight version of python with minimal dependencies.

### Using reinstallers
### destroying dependencies
### manual installation
If "greta-tf2-env" isn't found, then we create a new conda environment named "greta-tf2-env", for a version of python that works with the specified versions of TF and TFP.

If the previous installation helper did not work, you can try the following:
Then we install the TF and TFP python modules, using the versions specified in `greta_deps_spec()`.

```{r install_tensorflow, eval = FALSE}
reticulate::install_miniconda()
reticulate::conda_create(
envname = "greta-env",
python_version = "3.7"
)
reticulate::conda_install(
envname = "greta-env",
packages = c(
"numpy==1.16.4",
"tensorflow-probability==0.7.0",
"tensorflow==1.14.0"
)
)
```
After installation, we ask users if they want to restart R. This only happens in interactive sessions, and only if the user is in RStudio. This is to avoid potential issues where this script might be used in batch scripts online.

Which will install the python modules into a conda environment named "greta-env".
## Troubleshooting installation

You can also not install these not into a special conda environment "greta-env",
like so:
Installation doesn't always go to plan. Sometimes

```{r install-deps-plain, eval = FALSE}
reticulate::install_miniconda()
reticulate::conda_install(
packages = c(
"numpy==1.16.4",
"tensorflow-probability==0.7.0",
"tensorflow==1.14.0"
)
)
```
### Using a logfile

<!-- You can also use `install_tensorflow()` to install different versions of TensorFlow, including versions with GPU acceleration. If you're having trouble with this step, [this guide](https://tensorflow.rstudio.com/installation/) may help. -->
We write a logfile

<hr>
### Using reinstallers

You

# Morgue
### Destroying dependencies


#### Standard installation
### Manual installation

If the previous installation helper did not work, you can try the following:

```{r install_tensorflow, eval = FALSE}
reticulate::install_miniconda()
reticulate::conda_create(
envname = "greta-env",
python_version = "3.7"
envname = "greta-env-tf2",
python_version = "3.10"
)
reticulate::conda_install(
envname = "greta-env",
envname = "greta-env-tf2",
packages = c(
"numpy==1.16.4",
"tensorflow-probability==0.7.0",
"tensorflow==1.14.0"
"tensorflow-probability==0.23.0",
"tensorflow==2.15.0"
)
)
```

Which will install the python modules into a conda environment named "greta-env".
Which will install the python modules into a conda environment named "greta-env-tf2".

You can also not install these not into a special conda environment "greta-env",
like so:
You can also not install these not into a special conda environment like so:

```{r install-deps-plain, eval = FALSE}
reticulate::install_miniconda()
reticulate::conda_install(
packages = c(
"numpy==1.16.4",
"tensorflow-probability==0.7.0",
"tensorflow==1.14.0"
"tensorflow-probability==0.23.0",
"tensorflow==2.15.0"
)
)
```

<!-- You can also use `install_tensorflow()` to install different versions of TensorFlow, including versions with GPU acceleration. If you're having trouble with this step, [this guide](https://tensorflow.rstudio.com/installation/) may help. -->

<hr>

<!-- You can also use `install_tensorflow()` to install different versions of TensorFlow, including versions with GPU acceleration. If you're having trouble with this step, [this guide](https://tensorflow.rstudio.com/installation/) may help. -->

<!-- If you want `greta` to run as fast as possible on your computer's CPUs, it would be worth installing python and TensorFlow using Anaconda since they will be automatically configured to use Intel's MKL routines, which provide a 2-8 fold sampling speedup on most models. -->

0 comments on commit f2dd7cd

Please sign in to comment.