Skip to content

feat: Enable WebGPU Shape op support, remove EliminateShape rewrite rules - #132

Merged
justinchuby merged 2 commits into
mainfrom
justinchu/webgpu-shapes
Apr 9, 2026
Merged

feat: Enable WebGPU Shape op support, remove EliminateShape rewrite rules#132
justinchuby merged 2 commits into
mainfrom
justinchu/webgpu-shapes

Conversation

@justinchuby

Copy link
Copy Markdown
Member

WebGPU now supports the ONNX Shape operator natively. This PR removes the workaround that existed for the old constraint.

What was removed

Item Reason
_eliminate_shape.py WebGPU-only workaround — replaces Shape(attention_mask) with ReduceSum+ReduceMax. No longer needed.
_eliminate_shape_test.py Tests for the removed module
supports_shape field from EpCapabilities Only WebGPU used it with False; removing the field cleans up the API
EliminateShape lowering pass in _optimizations.py Nothing calls it anymore
eliminate_shape_rules from rewrite_rules public API Removed with the implementation

What was enabled

The webgpu EP entry in _execution_providers.py no longer sets supports_shape=False (field removed). WebGPU models now retain their Shape ops, matching all other EPs.

Test update

test_webgpu_no_shape_nodestest_webgpu_supports_shape_nodes: assertion flipped from == 0 to > 0, confirming Shape nodes are preserved in WebGPU graphs.

Stats

  • 416 lines deleted, 10 lines added
  • 2317 tests pass

…ules

WebGPU now supports the ONNX Shape operator natively. Remove the
EliminateShape workaround that replaced Shape(attention_mask, start=1,
end=2) with ReduceSum+ReduceMax.

Changes:
- Remove supports_shape from EpCapabilities (no longer needed)
- Remove EliminateShape lowering path from _optimizations.py
- Delete _eliminate_shape.py and _eliminate_shape_test.py
- Remove eliminate_shape_rules from rewrite_rules public API
- Update test: WebGPU graph now retains Shape nodes (was: assert 0, now: assert >0)
- Clean up stale WebGPU/EliminateShape comments in _common.py

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
@justinchuby
justinchuby force-pushed the justinchu/webgpu-shapes branch from 7f9f9e1 to 65d86a4 Compare April 9, 2026 05:04

Copilot AI 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.

Pull request overview

This PR updates Mobius’s EP optimization pipeline to reflect that WebGPU now natively supports the ONNX Shape operator, removing the prior WebGPU-only workaround rewrite and simplifying the EP capability surface area.

Changes:

  • Removed the WebGPU EliminateShape rewrite rule (and its tests) plus the EpCapabilities.supports_shape capability flag and corresponding lowering hook.
  • Updated WebGPU EP registration to stop advertising “no Shape”, aligning it with other EPs.
  • Flipped the WebGPU optimization test to assert Shape nodes are preserved.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/ep_optimization_test.py Updates WebGPU expectation: Shape nodes should remain present.
src/mobius/rewrite_rules/_eliminate_shape.py Deletes the Shape-elimination rewrite implementation.
src/mobius/rewrite_rules/_eliminate_shape_test.py Deletes tests validating the eliminated rewrite.
src/mobius/rewrite_rules/init.py Removes eliminate_shape_rules from the public rewrite_rules API.
src/mobius/components/_common.py Removes comments describing the old WebGPU Shape-elimination workaround.
src/mobius/_optimizations.py Removes the EliminateShape lowering-stage plumbing and references.
src/mobius/_execution_providers.py Removes supports_shape from EpCapabilities and from built-in EP entries.
src/mobius/main.py Removes CLI “no-shape” capability annotation in mobius list.

Comment thread tests/ep_optimization_test.py
Comment thread src/mobius/rewrite_rules/__init__.py
Comment thread src/mobius/_execution_providers.py
@github-actions

github-actions Bot commented Apr 9, 2026

Copy link
Copy Markdown

Performance Comparison

Comparing d31f871ded8033

Model Metric Baseline Current Delta
bert (feature-extraction) model_size_bytes 359 KB 359 KB +0.0%
bert (feature-extraction) num_nodes 61 61 +0.0%
falcon model_size_bytes 364 KB 364 KB +0.0%
falcon num_nodes 66 66 +0.0%
gemma2 model_size_bytes 428 KB 428 KB +0.0%
gemma2 num_nodes 107 107 +0.0%
gpt2 model_size_bytes 388 KB 388 KB +0.0%
gpt2 num_nodes 53 53 +0.0%
llama model_size_bytes 425 KB 425 KB +0.0%
llama num_nodes 61 61 +0.0%
llama (static-cache) model_size_bytes 425 KB 425 KB +0.0%
llama (static-cache) num_nodes 58 58 +0.0%
mamba (ssm-text-generation) model_size_bytes 360 KB 360 KB +0.0%
mamba (ssm-text-generation) num_nodes 103 103 +0.0%
phi3 model_size_bytes 421 KB 421 KB +0.0%
phi3 num_nodes 61 61 +0.0%
phi3 (static-cache) model_size_bytes 421 KB 421 KB +0.0%
phi3 (static-cache) num_nodes 58 58 +0.0%
qwen2 model_size_bytes 425 KB 425 KB +0.0%
qwen2 num_nodes 61 61 +0.0%
qwen2 (static-cache) model_size_bytes 425 KB 425 KB +0.0%
qwen2 (static-cache) num_nodes 58 58 +0.0%
qwen3_5_moe (hybrid-text-generation) model_size_bytes 506 KB 506 KB +0.0%
qwen3_5_moe (hybrid-text-generation) num_nodes 275 275 +0.0%
qwen3_5_text (hybrid-text-generation) model_size_bytes 458 KB 458 KB +0.0%
qwen3_5_text (hybrid-text-generation) num_nodes 129 129 +0.0%
qwen3_5_vl (hybrid-qwen-vl) model_size_bytes 977 KB 977 KB +0.0%
qwen3_5_vl (hybrid-qwen-vl) num_nodes 409 409 +0.0%
t5 (seq2seq) model_size_bytes 836 KB 836 KB +0.0%
t5 (seq2seq) num_nodes 174 174 +0.0%
whisper (speech-to-text) model_size_bytes 1008 KB 1008 KB +0.0%
whisper (speech-to-text) num_nodes 128 128 +0.0%

No performance regressions.

- docs/ep_quickstart.md line 123: remove supports_shape=True from custom
  EP registration example (now raises TypeError)
- docs/execution_providers.md: remove 5 stale EliminateShape/supports_shape
  references (lowering table row, EpCapabilities field, webgpu registry
  entry, pipeline stage description)
- CHANGELOG.md: document breaking removal of EpCapabilities.supports_shape
  and eliminate_shape_rules from the public API

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
@github-actions

github-actions Bot commented Apr 9, 2026

Copy link
Copy Markdown

🏗️ Architecture Diff

Comparing d31f871ded8033

Model Sub-model Changes Status
bert (feature-extraction) model 0
falcon model 0
gemma2 model 0
gpt2 model 0
llama model 0
llama (static-cache) model 0
mamba (ssm-text-generation) model 0
phi3 model 0
phi3 (static-cache) model 0
qwen model 0
qwen (static-cache) model 0
qwen2 model 0
qwen2 (static-cache) model 0
qwen2_moe model 0
qwen2_moe (static-cache) model 0
qwen3 model 0
qwen3 (static-cache) model 0
qwen3_5_moe (hybrid-text-generation) model 0
qwen3_5_text (hybrid-text-generation) model 0
qwen3_5_vl (hybrid-qwen-vl) decoder 0
qwen3_5_vl (hybrid-qwen-vl) embedding 0
qwen3_5_vl (hybrid-qwen-vl) vision 0
qwen3_moe model 0
qwen3_moe (static-cache) model 0
qwen3_next (hybrid-text-generation) model 0
t5 (seq2seq) decoder 0
t5 (seq2seq) encoder 0
whisper (speech-to-text) decoder 0
whisper (speech-to-text) encoder 0

No architecture changes detected.


Legend: ⚪ No change · 🔵 Minor (attrs/inits) · 🟡 Moderate (nodes added/removed) · 🔴 Major (interface changed)

@justinchuby
justinchuby merged commit c87787e into main Apr 9, 2026
7 checks passed
@justinchuby
justinchuby deleted the justinchu/webgpu-shapes branch April 9, 2026 05:12
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.

2 participants