Skip to content

Conversation

@nico-martin
Copy link
Collaborator

@nico-martin nico-martin commented Nov 30, 2025

I invested some time into #1236 and from what I see there are three ways how we could solve this:

  1. suppress console.error while creating InferenceSession
  2. while copying the wasm .mjs file we could overwrite the line that cases the console.error
  3. change the wasm library .mjs file.

for 3. We (or the ONNX maintainers) would have to make changes directly in their library. This would certainly be the cleanest solution, but we would be dependent on third parties. 2. I would not recommend this, as it could disrupt the copying process if changes are made within the ONNX library.
That's why solution one would be my favorite. It looks a bit messy or hacky, but honestly, I think it's the simplest solution.

@nico-martin nico-martin requested a review from xenova November 30, 2025 15:09
@nico-martin nico-martin changed the title suppress console.error while creating InferenceSession suppress console.error while creating InferenceSession (closes #1236) Nov 30, 2025
@nico-martin nico-martin changed the title suppress console.error while creating InferenceSession (closes #1236) suppress console.error while creating InferenceSession Nov 30, 2025
@xenova
Copy link
Collaborator

xenova commented Dec 1, 2025

Thanks for the PR! I recall that for V3, the inference session logging options would not work

[logSeverityLevel](https://onnxruntime.ai/docs/api/js/interfaces/InferenceSession.SessionOptions.html#logSeverityLevel)?: 0 | 2 | 1 | 3 | 4;
    [logVerbosityLevel](https://onnxruntime.ai/docs/api/js/interfaces/InferenceSession.SessionOptions.html#logVerbosityLevel)?: number;

but perhaps they work now? https://onnxruntime.ai/docs/api/js/interfaces/InferenceSession.SessionOptions.html


We can then set a global default logging behaviour, without needing to override global console methods.

@nico-martin nico-martin changed the title suppress console.error while creating InferenceSession [v4] suppress console.error while creating InferenceSession Dec 2, 2025
@nico-martin
Copy link
Collaborator Author

Unfortunately this does not work. Even with logSeverityLevel:4, logVerbosityLevel:4 I still get this console.error
Screenshot 2025-12-02 at 09 58 15

I think it does make sense to set the logSeverityLevel: 4.

But for the Unknown CPU vendor. cpuinfo_vendor value: 0 error, I had to dig deeper.
This is actually thrown here: https://github.com/microsoft/onnxruntime/blob/main/onnxruntime/core/common/cpuid_info_vendor.cc#L239
I think thats a) expected behaviour because when running in WebAssembly in a browser, the code doesn't have access to CPU vendor information and b) not an issue at all.

This warning actually bypasses the session-specific settings.
But after a lot of further digging in the onnxrunntime I found out there is a ONNX_WEB.env.logLevel. So when this is set to fatal, it wont show up in the console :)

@nico-martin
Copy link
Collaborator Author

My solution now sets the default logging level to 4 (fatal). But it can be overwritten with session_options.logSeverityLevel

const segmenter = await pipeline("background-removal", "Xenova/modnet", {
  device: "webgpu",
  session_options: {
    logSeverityLevel: 2, // warning
  },
});

Tis will not only set the onnxrunntime session_options, but also the ONNX_WEB.env.logLevel


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).

// 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.

nico-martin and others added 2 commits December 3, 2025 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants