Skip to main content
Version: 0.10.0

Function: loadModel()

loadModel(modelPath, options?): Model

Defined in: core/model.ts:126

Loads and compiles an ExecuTorch .pte model from the local filesystem.

The model is loaded synchronously into native memory. Prefer calling this inside a worklet runtime thread (via wrapAsync) to avoid blocking the JS thread during compilation.

Parameters​

modelPath​

string

The absolute local path to the .pte model file.

options?​

LoadModelOptions

Optional loading configuration. See LoadModelOptions.

Returns​

Model

The compiled Model instance, ready for execution.

Throws​

Thrown with code LOAD_FAILED if the model file cannot be opened, has an invalid format, or fails native initialization.

See​

wrapAsync

Example​

const model = loadModel('/path/to/model.pte');
const input = tensor('float32', [1, 3, 224, 224]);
const output = tensor('float32', [1, 1000]);
try {
model.execute('forward', [input], [output]);
// ...
} finally {
input.dispose();
output.dispose();
model.dispose();
}