Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions packages/transformers/src/models/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,16 @@ async function getSession(
session_options,
);

if (externalData.length > 0 && !apis.IS_NODE_ENV) {
session_options.externalData = externalData;
if (externalData.length > 0) {
// In non-Node environments, always pass external data via session options.
// In Node.js with filesystem cache, the ONNX runtime locates external data
// files automatically relative to the model path, so we skip this.
// However, when using a custom cache (which returns Uint8Array instead of a
// file path), the ONNX runtime cannot find the files on disk, so we must
// supply the data in-memory via session_options.externalData.
if (!apis.IS_NODE_ENV || externalData.some(item => item instanceof Uint8Array)) {
session_options.externalData = externalData;
}
}

if (cache_config && selectedDevice === 'webgpu' && kv_cache_dtype_config !== false) {
Expand Down