Skip to content

Refactor device selection: Rename to computePolicy, remove accelerated, and add fallback#923

Open
mingmingtasd wants to merge 3 commits into
webmachinelearning:mainfrom
mingmingtasd:policy
Open

Refactor device selection: Rename to computePolicy, remove accelerated, and add fallback#923
mingmingtasd wants to merge 3 commits into
webmachinelearning:mainfrom
mingmingtasd:policy

Conversation

@mingmingtasd
Copy link
Copy Markdown
Contributor

@mingmingtasd mingmingtasd commented Mar 18, 2026

To fix #911

Description:
This PR refactors the device selection preference API to establish a more extensible framework by replacing MLPowerPreference with MLComputePolicy in MLContextOptions.

Key changes included:

  1. Renamed preference enum: MLPowerPreference has been refactored to MLComputePolicy (and the corresponding MLContextOptions dictionary member updated to computePolicy).
  2. Clarified extensibility: The spec now explicitly states that the policy is designed to be extensible to accommodate future execution profiles, moving beyond just power and performance metrics.
  3. Removed "accelerated" option: Removed the accelerated value to eliminate ambiguity, as performance and power semantics are better covered by other profiles.
  4. Introduced "fallback" policy: Added a new "fallback" compute policy. This option prioritizes maximum compatibility over other considerations (typically running on a CPU) and is highly useful for verifying a model's numeric behavior without utilizing parallel accelerators like GPUs or NPUs.

The corresponding chromium CL is https://chromium-review.googlesource.com/c/chromium/src/+/7513189

PTAL, thanks! @huningxin


Preview | Diff

Comment thread index.bs Outdated
Copy link
Copy Markdown
Collaborator

@zolkis zolkis left a comment

Choose a reason for hiding this comment

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

Thanks!

Copy link
Copy Markdown
Collaborator

@fdwr fdwr left a comment

Choose a reason for hiding this comment

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

Consider clearer naming, otherwise LGTM sir.

Comment thread index.bs Outdated
Comment thread index.bs
Comment thread index.bs Outdated
Copy link
Copy Markdown

@mwyrzykowski mwyrzykowski left a comment

Choose a reason for hiding this comment

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

Would like to see the references to CPU removed from the non-normative wording https://github.com/webmachinelearning/webnn/pull/923/changes#r3010808209 but otherwise no objections to the API surface changes ✅

@mingmingtasd
Copy link
Copy Markdown
Contributor Author

I have no preference for the naming; I'll wait for the decision. For the description wording, I'm OK with not mentioning CPU to avoid being implementation-specific.

Copy link
Copy Markdown

@mwyrzykowski mwyrzykowski left a comment

Choose a reason for hiding this comment

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

✅ with the current

 "low-power",
 "fallback"

values

@anssiko
Copy link
Copy Markdown
Member

anssiko commented Apr 23, 2026

RESOLUTION: Use MLComputePolicy "fallback" as the name for maximum compatibility preference. (PR #923)

@anssiko anssiko removed the Agenda+ label Apr 23, 2026
@anssiko
Copy link
Copy Markdown
Member

anssiko commented Apr 23, 2026

We also acknowledged the following enhancements in our discussion today:

Anssi: other enhancements from this PR, to be addressed in a separate PR:
… - "low-latency" MLComputePolicy, example use case audio processing
… - "precision" MLContextOptions, to signal chopping off low bits is not preferred for this context

@mingmingtasd
Copy link
Copy Markdown
Contributor Author

I have no preference for the naming; I'll wait for the decision. For the description wording, I'm OK with not mentioning CPU to avoid being implementation-specific.

Thanks for your discussion! Let's keep the "fallback".

And in the latest commit, I removed the "CPU" word in the description for "fallback". @mwyrzykowski

Copy link
Copy Markdown
Member

@anssiko anssiko left a comment

Choose a reason for hiding this comment

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

This is ready to be merged by the editors. Thank you all.

The editors can track the discussed enhancements #923 (comment) as deemed appropriate.

Comment thread index.bs Outdated
Copy link
Copy Markdown
Collaborator

@fdwr fdwr left a comment

Choose a reason for hiding this comment

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

👍

Copy link
Copy Markdown
Contributor

@huningxin huningxin left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @mingmingtasd !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

accelerated should be prior to powerPreference for device selection

7 participants