Skip to content

Add dynamic shape explainer - #945

Open
miaobin wants to merge 12 commits into
webmachinelearning:mainfrom
miaobin:dynamic-shape-explainer
Open

miaobin wants to merge 12 commits into
webmachinelearning:mainfrom
miaobin:dynamic-shape-explainer

Conversation

@miaobin

@miaobin miaobin commented Aug 7, 2026

Copy link
Copy Markdown

This is the initial draft to summarize the discussion on dynamic shapes #883 .

The explainer covers named/unnamed dynamic dimensions, deferred (dispatch-time) shape validation, computeShapes() API, and a new family of shape-as-data (*Dynamic) operators.

Open questions and considered alternatives are called out explicitly in the explainer and feedback on this doc would be very welcome.

@miaobin

miaobin commented Aug 7, 2026

Copy link
Copy Markdown
Author

A POC based on the current explainer is WIP. And it has been validated against some real-world Transformer, LLM and image generation models.
With credits to @Honry for the ORT WebNN EP POC and assistance with the explainer, @huningxin and @fdwr for the initial review of this explainer.

@fdwr fdwr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

👍 I have some thoughts, but it's 95% 👌.

Comment thread dynamic-shape-explainer.md
Comment thread dynamic-shape-explainer.md Outdated
Comment thread dynamic-shape-explainer.md Outdated
Comment thread dynamic-shape-explainer.md
Comment thread dynamic-shape-explainer.md Outdated
Comment thread dynamic-shape-explainer.md
@w3cbot

w3cbot commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

anssiko marked as non substantive for IPR from ash-nazg.

@anssiko

anssiko commented Aug 13, 2026

Copy link
Copy Markdown
Member

I cleared the automatic IPR check for this PR, since explainer documents are consider non-substantive from the W3C Patent Policy point of view.

DetailsThis IPR check is to ensure normative portions of the specification come from organizations who participate the WG. Furthermore, in this case, I can attest the authors of this PR are affiliated with Intel, and as such, any normative portions are reusable in the spec PR, as appropriate.

@anssiko

anssiko commented Aug 24, 2026

Copy link
Copy Markdown
Member

@reillyeon you had good questions comments on our last call for this. Do you have some other Googlers in mind who should review this explainer PR?

When this PR lands, the team will start landing the implementation in smaller chunks for further validation of this approach.

@reillyeon reillyeon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Overall I think this approach is reasonable. My main concern is that by making shapes dynamic there are more opportunities for memory safety issues in the implementation.

@anssiko

anssiko commented Aug 27, 2026

Copy link
Copy Markdown
Member

With two approvals, editors are welcome to merge this explainer PR at will.

Thank you @miaobin for this contribution and Reilly, Dwayne, everyone for your review.

Comment thread dynamic-shape-explainer.md Outdated
Comment thread dynamic-shape-explainer.md Outdated
Comment thread dynamic-shape-explainer.md
Comment thread dynamic-shape-explainer.md
Comment thread dynamic-shape-explainer.md Outdated
Comment thread dynamic-shape-explainer.md Outdated

@fdwr fdwr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

👍 Cool.

Comment thread dynamic-shape-explainer.md Outdated
Comment thread dynamic-shape-explainer.md
Comment thread dynamic-shape-explainer.md Outdated
@miaobin

miaobin commented Sep 8, 2026

Copy link
Copy Markdown
Author

@huningxin The latest Patchset of the dynamic shape POC runs dynamic shape inference and validation in Blink at dispatch time and also makes MLGraph.computeShapes() synchronous. PTAL, thanks.

```js
// After: 'sequence_length' is a named dynamic dimension.
const input = builder.input('attention_mask', {dataType: 'float32', shape: [1, 'sequence_length']});
const graph = await builder.build({output});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

the post-compilation on dispatch might be finger printable (below discussion suggest computeShapes is the natural place for post-compilation and shape specialization). Also, the implementation hitting an very unfortunate shape might have a finger printable cost that allows guesses about the used HW and implementation.

Comment thread dynamic-shape-explainer.md Outdated
Comment thread dynamic-shape-explainer.md
Comment thread dynamic-shape-explainer.md Outdated
Comment thread dynamic-shape-explainer.md Outdated
Comment thread dynamic-shape-explainer.md
Comment thread dynamic-shape-explainer.md
Comment thread dynamic-shape-explainer.md Outdated
@miaobin

miaobin commented Sep 16, 2026

Copy link
Copy Markdown
Author

Hi @theHamsta, thank you for the depth of this review; it changed the document in several places. I'd like to check whether the current state is one you'd be comfortable approving.

@anssiko

anssiko commented Sep 22, 2026

Copy link
Copy Markdown
Member

Last call for comments. Editors will merge this by our next meeting this Thu.

@fdwr fdwr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Some of the newly added sentences need polish for our human readers. Otherwise the latest iteration seems fine to me.

Comment thread dynamic-shape-explainer.md Outdated
Comment thread dynamic-shape-explainer.md Outdated
Comment thread dynamic-shape-explainer.md Outdated
Comment thread dynamic-shape-explainer.md Outdated
Comment thread dynamic-shape-explainer.md Outdated
@miaobin

miaobin commented Sep 24, 2026

Copy link
Copy Markdown
Author

Some of the newly added sentences need polish for our human readers. Otherwise the latest iteration seems fine to me.

@fdwr I've pushed two commits:
On one hand I've fixed the five places you flagged. I used your wording where it kept the meaning. On the other hand, I've applied the same cleanup to the other sentences added since your last approval: the Design Discussion intro, the shape chain part of Shape computation at dispatch, Symbolic shape expressions, the timing paragraph, and the Making the shape subgraph explicit open question. It changes wording only, not the design. And I also fixed a broken code span in the reshape example. PTAL, thanks!

@anssiko

anssiko commented Sep 24, 2026

Copy link
Copy Markdown
Member

Resolved as #883 (comment)

Rephrase sentences for clarity and conciseness (no functional changes).

@fdwr fdwr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

👍 Thanks Bin, humans happy 😁.

@anssiko

anssiko commented Oct 5, 2026

Copy link
Copy Markdown
Member

@fdwr @huningxin feel free to merge this per https://www.w3.org/2026/09/24-webmachinelearning-minutes.html#f51e at your earliest opportunity.

@miaobin thank you for your work on this and the subsequent iteration.

As usual, also this explainer is expected to receive updates as we learn more from the implementation experience, from Chromium and from other environments such as #945 (comment)

@theHamsta theHamsta mentioned this pull request Oct 5, 2026
1 of 6 tasks
Comment thread dynamic-shape-explainer.md Outdated
Comment thread dynamic-shape-explainer.md Outdated
Comment thread dynamic-shape-explainer.md Outdated

@fdwr fdwr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

👍

@huningxin huningxin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

This branch has not been deployed

No deployments
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.

8 participants