feat: Enable WebGPU Shape op support, remove EliminateShape rewrite rules - #132
Merged
Conversation
…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
force-pushed
the
justinchu/webgpu-shapes
branch
from
April 9, 2026 05:04
7f9f9e1 to
65d86a4
Compare
Contributor
There was a problem hiding this comment.
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
EliminateShaperewrite rule (and its tests) plus theEpCapabilities.supports_shapecapability 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
Shapenodes 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. |
Performance Comparison
|
- 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>
🏗️ Architecture Diff
No architecture changes detected. ✅ Legend: ⚪ No change · 🔵 Minor (attrs/inits) · 🟡 Moderate (nodes added/removed) · 🔴 Major (interface changed) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
WebGPU now supports the ONNX
Shapeoperator natively. This PR removes the workaround that existed for the old constraint.What was removed
_eliminate_shape.pyShape(attention_mask)withReduceSum+ReduceMax. No longer needed._eliminate_shape_test.pysupports_shapefield fromEpCapabilitiesFalse; removing the field cleans up the APIEliminateShapelowering pass in_optimizations.pyeliminate_shape_rulesfromrewrite_rulespublic APIWhat was enabled
The
webgpuEP entry in_execution_providers.pyno longer setssupports_shape=False(field removed). WebGPU models now retain theirShapeops, matching all other EPs.Test update
test_webgpu_no_shape_nodes→test_webgpu_supports_shape_nodes: assertion flipped from== 0to> 0, confirming Shape nodes are preserved in WebGPU graphs.Stats