When enabled, the first CPU session of each model saves the graph produced by ONNX
Runtime's optimizer to dir, and later sessions (new R sessions, parallel workers,
after pliman_clear_sessions()) load that optimized graph with the optimizer
turned off. This shortens session start-up for large models such as the SAM 2.1
encoder, Grounding DINO or RMBG. Predictions are unchanged: the cached file is the
same graph the optimizer would build again.
Cached files are keyed by model size, modification time and ONNX Runtime API version,
so an updated model or runtime never reuses a stale graph. They are tied to the CPU
that produced them (the optimizer may insert CPU-specific layouts) and are therefore
kept locally; GPU sessions are never cached because provider-specific graphs are not
portable. Models stored with external weight files (.onnx.data) are skipped.
Usage
pliman_onnx_graph_cache(
enable = NULL,
dir = file.path(pliman_model_dir(), "ort_graph_cache"),
clear = FALSE
)Examples
if (FALSE) { # interactive()
pliman_onnx_graph_cache(TRUE)
pliman_session_info()[, c("model", "graph_cache", "create_ms")]
}
