onnx_load: Load an ONNX model

View source: R/onnx.R

onnx_loadR Documentation

Load an ONNX model

Description

Parses an .onnx file, builds a ggml computation graph, and allocates tensors on the specified device. Weights are loaded via memory-mapped file (zero-copy where possible).

Usage

onnx_load(
  path,
  device = NULL,
  input_shapes = NULL,
  n_threads = NULL,
  dtype = "f32"
)

Arguments

path

Path to .onnx file.

device

Backend device: "vulkan" (default if available) or "cpu".

input_shapes

Optional named list of integer vectors specifying fixed shapes for inputs with dynamic dimensions. Names must match input tensor names. Each shape must include all dimensions including batch, e.g. list(image = c(1L, 3L, 224L, 224L)). Required when the model has dynamic dimensions and no default shape.

n_threads

Number of CPU threads. NULL (default) reads getOption("ggmlR.n_threads"); if that is also unset, uses parallel::detectCores() - 1 (minimum 1).

dtype

Weight precision: "f32" (default) or "f16". When "f16", large weight tensors (>= 256 elements) are stored in half-precision for faster Vulkan compute and lower VRAM usage. Small tensors (bias, scalars, batch-norm params) remain in F32 for numerical stability. Inputs and outputs are always F32.

Value

An opaque model object (external pointer) for use with onnx_run(), onnx_summary(), and onnx_inputs().


ggmlR documentation built on July 14, 2026, 1:08 a.m.