Skip to main content
Version: Next

Function: loadModel()

loadModel(modelSource, options?): Model

Defined in: core/model.ts:163

Loads and compiles an ExecuTorch .pte model from local files or callback readers.

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​

modelSource​

ModelSource

Local program path, program with external data paths, or callback readers. See ModelSource.

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. With code INVALID_ARGUMENT if a source is malformed or callback loaders are combined with lazy loading. Exceptions from user callbacks propagate.

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();
}