Skip to content

[skill-update] skill(webnn): remove MLDeviceType, add accelerated/powerPreference, update API surface#18

Merged
webmaxru merged 1 commit intomainfrom
webnn-skill-update-96bf357e3e850c3c
Mar 29, 2026
Merged

[skill-update] skill(webnn): remove MLDeviceType, add accelerated/powerPreference, update API surface#18
webmaxru merged 1 commit intomainfrom
webnn-skill-update-96bf357e3e850c3c

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

Summary

The W3C WebNN Candidate Recommendation (CRD) removed MLDeviceType (the "cpu" | "gpu" | "npu" enumeration) in PR #809 to simplify device selection. The current skill still referenced deviceType throughout. This PR brings the skill in line with the current specification.

Material Changes

MLDeviceType removed ([spec §8.2]((www.w3.org/redacted), PR #809)

  • MLContextOptions no longer has deviceType. It now has:
    • powerPreference: "default" | "high-performance" | "low-power" (unchanged)
    • accelerated: boolean (default true) — replaces device-type enumeration; true allows GPU/NPU hardware, false requests CPU inference
  • MLContext.accelerated — new read-only attribute reflecting actual acceleration state ([spec §8.3]((www.w3.org/redacted)
  • All deviceType: "cpu" / "gpu" / "npu" patterns must migrate to accelerated + powerPreference

Additional spec surface now documented ([spec §8.3]((www.w3.org/redacted)

  • destroy() methods on MLContext, MLGraph, and MLTensor ([spec §8.3.8]((www.w3.org/redacted), [§8.4.1]((www.w3.org/redacted), [§8.8.2]((www.w3.org/redacted) — template already used these; references now document them explicitly
  • readTensor(tensor, outputData) overload ([spec §8.3]((www.w3.org/redacted) — reads into an existing AllowSharedBufferSource instead of returning a new ArrayBuffer
  • createContext(gpuDevice: GPUDevice) overload ([spec §8.2.2]((www.w3.org/redacted) — creates a WebGPU-interop context

MLGraphBuilder.build() single-invocation restriction (spec PR #717)

  • build() can only be called once per builder — noted in webnn-reference.md

Files Changed

File What changed
skills/webnn/SKILL.md Replace deviceType guidance with accelerated/powerPreference; update error handling and validation steps
skills/webnn/references/webnn-reference.md Reflect current spec API: accelerated, destroy(), readTensor overload, createContext(gpuDevice), deprecation note on MLDeviceType
skills/webnn/references/compatibility.md Replace cpu/gpu/npu device selection guidance with accelerated + powerPreference table; add migration note
skills/webnn/references/examples.md Update createContext call to use powerPreference: "high-performance" instead of deviceType: "gpu"
skills/webnn/references/troubleshooting.md Replace gpu or npu context failure text with accelerated/high-performance wording
skills/webnn/assets/webnn-runtime.template.ts Remove WebNNDeviceType; replace deviceType field with accelerated: boolean in WebNNContextOptions and normalizedOptions

Validation

  • Metadata validator passed: python .github/skills/skill-creator/scripts/validate-metadata.py --name "webnn" --description "..."SUCCESS: Metadata is valid and optimized for discovery.
  • Checklist: all items pass (flat hierarchy, no human docs, SKILL.md under 500 lines, imperative mood, progressive disclosure intact)
  • No remaining deviceType, MLDeviceType, or "cpu" / "gpu" / "npu" device-type strings in the skill directory

Source Citations per Update

Each update traces to its authoritative source:

  • MLDeviceType removal: [(www.w3.org/redacted)(www.w3.org/redacted) and PR #809
  • accelerated option: [(www.w3.org/redacted)(www.w3.org/redacted)
  • MLContext.accelerated attribute: [(www.w3.org/redacted)(www.w3.org/redacted)
  • destroy() methods: [(www.w3.org/redacted)(www.w3.org/redacted), [#api-mlgraph-destroy]((www.w3.org/redacted), [#api-mltensor-destroy]((www.w3.org/redacted)
  • readTensor(tensor, outputData) overload: [(www.w3.org/redacted)(www.w3.org/redacted)
  • createContext(gpuDevice): [(www.w3.org/redacted)(www.w3.org/redacted)
  • build() single-invocation: Allow MLGraphBuilder.build() to be called only once webmachinelearning/webnn#717

Remaining Risks

  • Browser implementations may still accept deviceType in their shipped versions (Chromium 112–131 era). The compatibility.md migration note covers this. The skill now correctly reflects what the spec defines, not historical implementation behavior.
  • The webnn.io reference URL (secondary source) delivered a JavaScript SPA with minimal extractable text — the W3C spec (primary source) was used as authoritative for all API surface changes per the prompt's source priority rules.

Generated by Skill Update Worker ·

…pdate API surface

The W3C WebNN CRD removed MLDeviceType (cpu/gpu/npu) in PR #809 to simplify
device selection. Replace all deviceType references with the current API:
- MLContextOptions now has powerPreference and accelerated (boolean, default true)
- MLContext gains a readonly accelerated attribute
- Add destroy() method documentation for MLContext, MLGraph, MLTensor
- Add readTensor(tensor, outputData) overload for reading into existing buffers
- Add createContext(gpuDevice: GPUDevice) WebGPU interop overload
- Note that builder.build() can only be called once per builder

Files changed:
- references/webnn-reference.md: reflect current spec API surface
- references/compatibility.md: replace cpu/gpu/npu guidance with accelerated+powerPreference
- references/examples.md: update examples to use new context options
- references/troubleshooting.md: update createContext failure guidance
- SKILL.md: replace deviceType guidance with accelerated+powerPreference
- assets/webnn-runtime.template.ts: remove WebNNDeviceType, add accelerated field

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@webmaxru webmaxru marked this pull request as ready for review March 29, 2026 11:05
@webmaxru webmaxru merged commit 47a45eb into main Mar 29, 2026
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.

1 participant