setup_cache: Use a Shared or Offline Cache

View source: R/setup_cache.R

setup_cacheR Documentation

Use a Shared or Offline Cache

Description

Stores the Python environment, Python itself and the Hugging Face models in one folder, and optionally runs without network access. This is the route for HPC clusters: prepare the folder on a login node with internet access, then use it offline on compute nodes.

Usage

setup_cache(path, offline = FALSE, gpu = NULL)

Arguments

path

Folder for the caches, for example on project or scratch storage shared by login and compute nodes. It needs several GB and must be writable.

offline

Logical. Use only what is already in the cache, with no network access (sets UV_OFFLINE and HF_HUB_OFFLINE).

gpu

Logical or NULL. Choose the CUDA (TRUE) or CPU (FALSE) build of PyTorch instead of detecting the GPU. Login nodes usually have no GPU, so when the compute nodes do, pass gpu = TRUE both when preparing the cache and in jobs.

Details

Call setup_cache() in a new R session, after library(transforEmotion) and before any analysis. It sets these environment variables for the session:

UV_CACHE_DIR

uv package cache and Python environments

UV_PYTHON_INSTALL_DIR, UV_PYTHON_PREFERENCE

a Python interpreter kept in the cache, so compute nodes do not need one

HF_HOME

Hugging Face models

R_USER_CACHE_DIR

reticulate's own copy of uv and the NLTK data used by rag(). This also moves the cache of any other R package that uses tools::R_user_dir() in this session.

Offline sessions can use any combination of the feature sets prepared with setup_modules(), and any model it downloaded.

The cache must stay writable, because uv locks it even when reusing an environment. For read-only environments such as Apptainer images, build a fixed Python environment instead (see python_requirements).

Value

Invisibly, a named character vector of the environment variables set.

Examples

## Not run: 
# On a login node, with internet access
library(transforEmotion)
setup_cache("/project/mylab/transforEmotion-cache", gpu = TRUE)
setup_modules(extras = "rag", models = "facebook/bart-large-mnli")

# In a job on a compute node, without internet access
library(transforEmotion)
setup_cache("/project/mylab/transforEmotion-cache", offline = TRUE, gpu = TRUE)
transformer_scores(text, classes, transformer = "facebook-bart")

## End(Not run)


transforEmotion documentation built on Oct. 26, 2026, 5:07 p.m.