[ExecuTorch][WebGPU] Dynamic resize hooks for sigmoid and select_copy#20578
[ExecuTorch][WebGPU] Dynamic resize hooks for sigmoid and select_copy#20578JulianCloudNTH wants to merge 4 commits into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/20578
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 New FailureAs of commit 46fcce5 with merge base db5f1ba ( NEW FAILURE - The following job has failed:
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 47s —— View job Review: Dynamic resize hooks for sigmoid and select_copy
The change is well-scoped and matches the established per-op resize-hook pattern ( Correctness — looks good, two minor notes
No issues with the lambda captures (all captured values are used; handles copied before Modularization — the more substantive feedbackThis PR is behavior-correct, but it lands on top of a growing amount of near-duplicate boilerplate across 1. A meta-UBO rewrite helper (highest value, lowest risk). The "synthesize a inline void write_meta_from_dims(WebGPUGraph& g, WGPUBuffer buf,
const std::vector<int64_t>& dims) {
WebGPUTensor t; t.dims = dims;
TensorMeta m; fill_tensor_meta(t, &m);
wgpuQueueWriteBuffer(g.queue(), buf, 0, &m, sizeof(m));
}Select's hook then drops to 2. A 3. The 5-binding gather scaffold shared by struct GatherPipeline { WGPUComputePipeline pipeline; WGPUBindGroup bind_group;
WGPUBuffer out_meta_buf, in_meta_buf, params_buf; };
GatherPipeline build_gather_op(graph, in_tensor, out_tensor, wgsl,
wg_size, const void* params, size_t params_size);The Given CLAUDE.md's "no trivial single-use helpers" rule, #1 and #2 clear that bar because they're now used by 2+ ops and will be reused by every shape-changing op; #3 is a real refactor worth a follow-up PR rather than expanding this one. RecommendationShip the fix as-is (correct and minimal). Suggest doing #1 either here or as the immediate next stacked diff while the pattern is fresh, and tracking #3 as a follow-up. |
Stack from ghstack (oldest at bottom):
Make sigmoid and select_copy serve any live shape from one graph; fix select's last-token index under dynamic shapes.
Problem: Both ops baked their dispatch/params/output shape at
build()for the max shape.select_copywas worse: a negative index (e.g.-1for the last token) was normalized against the build-time MAX dim, so at a smaller live S it selected a stale/zero position past the live data — producing wrong (often zero) output.Solution:
sigmoid(genericadd_unary_op): a resize hook recomputesnum_elements/dispatch and sets the outputcur_dims(shape-preserving).select_copy: KEEP the raw (possibly negative) index at build; a resize hook re-resolves it against the LIVE dim, recomputes the output dims (= input minusdim), rebuilds the out/inTensorMetaUBOs and the dispatch.own_uniform_buffer.Implementation:
WebGPUTensor{dims}viafill_tensor_meta(reads only.dims).resize_*_node.Constraints: Behavior-neutral on static graphs (hooks fire only when an input's live shape differs from the max). No kernel/WGSL/numerics change.
Co-authored-with: Claude Code.
@exported-using-ghexport
Differential Revision: D109906095
Differential Revision: D109906095