Skip to contents

Deep-learning functions in pliman keep ONNX Runtime sessions in memory, so the model is loaded (and, on GPU, compiled) only once per R session. pliman_session_info() lists the cached sessions; pliman_max_sessions() reads or changes how many sessions are kept (least recently used sessions are released first). Use pliman_clear_sessions() to release all of them.

Usage

pliman_session_info()

pliman_max_sessions(n = NULL)

Arguments

n

Integer. New maximum number of cached sessions (>= 1). NULL only returns the current value.

Value

pliman_session_info(): a data.frame with one row per cached session (model, whether it runs on the GPU, threads, input dimensions, warm-up and CPU fallback flags, the execution provider actually used, the graph_cache state, the session creation time create_ms and, for GPU requests served by the CPU, the fallback_reason), most recently used first. A GPU session that fails to build (for example because another process holds the GPU memory) issues a warning, runs on the CPU and is retried on the GPU after 30 seconds; pliman_clear_sessions() retries immediately.

On Windows, GPU memory is managed automatically: before a new GPU session is built, sessions idle for at least 2 seconds are released (least recently used first) while the process uses more than 80% of its video-memory budget, because a DirectML session built over budget keeps part of its memory in system RAM and stays several times slower. A session that still had to be built over budget is flagged in vram_pressured and rebuilt automatically once memory is available. Disable with the environment variable PLIMAN_VRAM_GUARD=0. pliman_max_sessions(): the previous limit, invisibly when n is given.

Details

Pipelines such as Grounded-SAM (Grounding DINO + SAM encoder + SAM decoder) or detection with return_features = TRUE (YOLO + CLIP/DINOv2) need several sessions at once. The default limit is 8 and can also be set before loading the package with the environment variable PLIMAN_ONNX_MAX_SESSIONS or with options(pliman.max_sessions = n). Lower it if RAM or GPU memory is tight.

ONNX Runtime worker threads keep the runtime default of busy-waiting ("spinning") briefly between runs, which gives the lowest latency. When several R processes share the CPU (e.g. parallel batch workers), set the environment variable PLIMAN_ORT_SPIN=0 before the first inference to disable spinning.

Which GPU provider serves a model (DirectML, CUDA, TensorRT, CoreML, OpenVINO) is chosen with pliman_gpu_provider(); pliman_onnx_profiling() traces where every operator ran, and pliman_onnx_graph_cache() shortens session start-up.

Examples

if (FALSE) { # interactive()
library(pliman)
img <- image_pliman("soybean_touch.jpg")
res <- image_detect_dl(img, model = "yolo26n", plot = FALSE)
pliman_session_info()
pliman_max_sessions()
}