[ExecuTorch][WebGPU] SymInt arithmetic ops (add/sub/mul/floordiv) for dynamic shapes#20573
[ExecuTorch][WebGPU] SymInt arithmetic ops (add/sub/mul/floordiv) for dynamic shapes#20573JulianCloudNTH wants to merge 3 commits into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/20573
Note: Links to docs will display an error until the docs builds have been completed. ⏳ No Failures, 2 PendingAs of commit fe4f84f with merge base db5f1ba ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
|
@claude review and check for any areas or opportunities for modularization |
|
Claude finished @JulianCloudNTH's task in 2m 6s —— View job Review: WebGPU SymInt arithmetic ops
Overall this is a clean, well-scoped change. The resize-hook approach is a genuine improvement over the Vulkan reference it mirrors, and the diff does exactly what the description claims. Notes below, ordered by importance. Modularization (the main ask)1. 2. File/directory naming no longer matches contents. This is the clearest modularization opportunity. The file now contains general SymInt arithmetic ( Consider extracting the arithmetic ops into a sibling Correctness3. Division by zero in 4. 5. Self-referential operands register the hook twice. If Minor / style6. 7. Chained arithmetic relies on registration order. VerificationI could not build/run the WebGPU backend in this environment, so the above is static analysis only. Worth confirming with an actual dynamic-shape |
Stack from ghstack (oldest at bottom):
Register scalar SymInt arithmetic so dynamic-shape graphs lower without an "unsupported op" failure.
Problem: A dynamic-shape exported program emits scalar SymInt arithmetic nodes (
add/sub/mul/floordiv) to compute live sizes and positions (e.g.input_pos + S,seq_len // n). The WebGPU backend registered onlyet_vk.select_as_symint.default, soWebGPUGraph::build()threwunsupported op: addwhen loading any dynamic.pte.Solution:
select_as_symintproduced a live SymInt; any arithmetic on it was unsupported.add/sub/mul/floordiveach recompute their output SymInt from the operands via a resize hook whenever a live operand changes.Implementation:
register_sym_binaryreads each operand (live SymInt viaread_symint, else a staticInt), seeds the build-time value, and registers a resize hook on any live operand (set_syminton recompute).floordivrounds toward negative infinity (Python semantics).backends/vulkan/runtime/graph/ops/impl/SymIntOps.cpp(add/sub/floordiv/mul).add/sub/mul/floordiv— distinct registry keys from the tensoraten.add.Tensor/aten.mul.Tensorops.Constraints: An output that folded to a static
Intis a no-op. No GPU kernel, no dispatch, no change to the static-shape path.sym_size.intis intentionally not added here (depends on the tensor-shape dim-source API in the following diff).Co-authored-with: Claude Code.
@exported-using-ghexport
Differential Revision: D109906102
Differential Revision: D109906102