get_py_MAF_handle {mafR}R Documentation

Utilities to manage Python environment and torch tensors

Description

Utility initializing a Python environment for running zuko.flows.MAF and retrieving it.

Usage

  get_py_MAF_handle(envir, reset=FALSE, torch_device="cpu", GPU_mem=NULL,
                    verbose = TRUE)

Arguments

envir

An environment (in the R sense) initialized as shown in the Examples.

reset

Boolean: Whether to reinitialize the Python session or not.

torch_device

Character: "cpu"; or a GPU backend, either "cuda" (or "cuda:0", etc.) or "mps" depending on system capabilities.

GPU_mem

For development purposes (effect is complicated). An amount of (dedicated) GPU memory, in bytes.

verbose

Boolean. Whether to print some messages or not.

Value

If successful, get_py_MAF_handle returns the modified input environment. If sourcing the Python code provided by mafR failed (presumably from trying to use an improperly set-up Python environment), the error condition message is returned.

Examples

# Initialization of Python session:
my_env <- list2env(list(is_set=FALSE),parent = emptyenv())
my_env <- get_py_MAF_handle(my_env, reset=FALSE, torch_device="cpu")
    
if (inherits(my_env,"environment"))  {
    # => provides access to:
    my_env$torch # Imported Python package (result of reticulate::import("torch"))
    my_env$device # the torch_device
    # and to internal definitions for MAF training 
}

[Package mafR version 1.1.6 Index]