Loads an exported ONNX checkpoint into memory (about 1 to 1.5 GB of RAM)
and returns an engine to pass to laya_predict() and friends. Create one
and reuse it: loading takes several seconds, predictions are fast.
Arguments
- checkpoint
Which checkpoint to load:
"multilingual"(100+ languages, the default),"english"(English-optimized) or"typed-decisions"(fine-tuned for four specific workflows).- model_dir
Path to an exported checkpoint directory. Overrides the lookup by
checkpoint(seelaya_model_path()).- intra_op_threads, inter_op_threads
ONNX Runtime thread counts.
NULLlets ONNX Runtime choose. ThelayaR.threadsoption sets the default forintra_op_threads.- lang_temperatures
Optional per-language calibration overrides, a named list such as
list(fr = list(temperature = c(1.1, 1, 0.9))); see the Python SDK'slang_temperatures. They apply to calls made with a matchinglang.
Details
Most code never needs this: the prediction functions default to
laya_default_engine(), which loads the checkpoint named by the
layaR.checkpoint option ("multilingual" by default) on first use and
keeps it for the session.
Engines can't be sent to other processes. An engine restored with
readRDS(), or used in a PSOCK worker (parallel::makePSOCKcluster(),
future::multisession), reconnects to its model directory on first use,
which loads the model again in that process (another 1 to 1.5 GB each).
Engines don't work across fork() (parallel::mclapply(),
future::multicore): ONNX Runtime's thread pools don't survive it, so a
forked child could hang. Using an engine in a forked child raises a
laya_error_forked error instead. A single engine already runs one forward
pass on several cores; for more throughput use laya_predict_batch(), or
PSOCK workers that each load their own engine.
Examples
if (laya_model_available()) {
engine <- laya_engine("multilingual", intra_op_threads = 2)
engine
laya_engine_close(engine)
}