Skip to content
Open
Show file tree
Hide file tree
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
16 changes: 16 additions & 0 deletions src/backends/onnx.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ const DEVICE_TO_EXECUTION_PROVIDER_MAPPING = Object.freeze({
'webnn-cpu': { name: 'webnn', deviceType: 'cpu' }, // WebNN CPU
});

/** @type {Array<'verbose' | 'info' | 'warning' | 'error' | 'fatal'>} */
const LOG_LEVELS = ['verbose', 'info', 'warning', 'error', 'fatal'];

/**
* The list of supported devices, sorted by priority/performance.
* @type {import("../utils/devices.js").DeviceType[]}
Expand Down Expand Up @@ -149,6 +152,19 @@ let webInitChain = Promise.resolve();
* @returns {Promise<import('onnxruntime-common').InferenceSession & { config: Object}>} The ONNX inference session.
*/
export async function createInferenceSession(buffer_or_path, session_options, session_config) {

/** @type {0|1|2|3|4} */
const logSeverityLevel =
typeof session_options.logSeverityLevel !== 'number' ||
session_options.logSeverityLevel < 0 ||
session_options.logSeverityLevel > 4
? 4
: session_options.logSeverityLevel;

ONNX_WEB.env.logLevel = LOG_LEVELS[logSeverityLevel];

session_options = { ...session_options, logSeverityLevel };
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can move the ONNX_WEB.env.logLevel logic to happen during init (similar to how we set default WASM paths (as a good default).

This should hopefully minimize any session_options specific code a user would need to set.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually think it makes sense to set the ONNX_WEB.env.logLevel here where I create a new session. Als a transformers.js user I dont really care if the log is a "onnxruntime session log" or a "onnxruntime general log". All I want to do is to create a pipeline and then be able to set the logLevel.
My solutions basically abstracts this decision away by only providing one setting and thats basically the settings that has always been available in the session_options (although very view people actually used that setting in the past I guess).


const load = () => InferenceSession.create(buffer_or_path, session_options);
const session = await (IS_WEB_ENV ? (webInitChain = webInitChain.then(load)) : load());
session.config = session_config;
Expand Down
2 changes: 2 additions & 0 deletions src/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ async function getSession(pretrained_model_name_or_path, fileName, options, is_d

// Overwrite `executionProviders` if not specified
session_options.executionProviders ??= executionProviders;
// Set `logSeverityLevel` to 4 (fatal) if not specified
session_options.logSeverityLevel ??= 4;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be good. From my testing, a value of 3 will hide

2025-12-03 00:44:48.937 node[68874:20600323] 2025-12-03 00:44:48.937479 [W:onnxruntime:, session_state.cc:1316 VerifyEachNodeIsAssignedToAnEp] Some nodes were not assigned to the preferred execution providers which may or may not have an negative impact on performance. e.g. ORT explicitly assigns shape related ops to CPU to improve perf.
2025-12-03 00:44:48.937 node[68874:20600323] 2025-12-03 00:44:48.937528 [W:onnxruntime:, session_state.cc:1318 VerifyEachNodeIsAssignedToAnEp] Rerunning with verbose output on a non-minimal build will show node assignments.

but as you say in #1468 (comment), a value of 4 is necessary to hide everything else when running in browser.


// Overwrite `freeDimensionOverrides` if specified in config and not set in session options
const free_dimension_overrides = custom_config.free_dimension_overrides;
Expand Down
Loading