Skip to content

[ExecuTorch][WebGPU] Add aten._to_copy.default with int<->float numeric convert#20987

Open
JCNTH wants to merge 2 commits into
gh/JCNTH/91/basefrom
gh/JCNTH/91/head
Open

[ExecuTorch][WebGPU] Add aten._to_copy.default with int<->float numeric convert#20987
JCNTH wants to merge 2 commits into
gh/JCNTH/91/basefrom
gh/JCNTH/91/head

Conversation

@JCNTH

@JCNTH JCNTH commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Add aten._to_copy.default with int↔float numeric convert

Problem: The copy-family ops byte-copied across dtypes, so an int32 -> fp32 cast reinterpreted the raw bits — int32 2 = 0x2 decodes as the fp32 denormal 2.8e-45 — producing wrong values (and div-by-~0 inf downstream). Separately, aten._to_copy.default was unregistered, so any delegate containing it failed to load.

Solution: Add add_to_copy_node: same-dtype copies stay a flat byte copy, while int<->float copies run a numeric-convert compute shader (f32(i32) / i32(f32)). Register aten._to_copy.default, and route the dim-order copy ops (dim_order_ops._clone_dim_order.default / ._to_dim_order_copy.default) through the same convert-aware path so an int<->float dim-order copy numeric-converts instead of byte-reinterpreting; view_copy / clone / alias_copy stay on the flat copy. Mirrors Vulkan ToCopy.cpp (BlitNode vs the view_convert path).

Implementation: runtime/ops/to_copy/{ToCopy.cpp,to_copy.h,to_copy_int_to_float.wgsl,to_copy_float_to_int.wgsl} provide add_to_copy_node and register aten._to_copy.default; runtime/ops/view_copy/ViewCopy.cpp re-points the two dim-order copy ops at add_to_copy_node. One WEBGPU_SRCS entry.

Constraints: 32-bit only (int64 constants are downcast to int32 by the Vulkan serializer); fails loud on any other element width.

Co-authored-with: Claude Code.

Differential Revision: D112378932

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Jul 16, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/20987

Note: Links to docs will display an error until the docs builds have been completed.

❌ 128 New Failures, 3 Unrelated Failures, 7 Unclassified Failures

As of commit b82a606 with merge base c2b273e (image):

NEW FAILURES - The following jobs have failed:

UNCLASSIFIED FAILURES - DrCI could not classify the following jobs because the workflow did not run on the merge base. The failures may be pre-existing on trunk or introduced by this PR:

FLAKY - The following jobs failed but were likely due to flakiness present on trunk:

  • pull / unittest / windows / windows-job (gh) (matched win rule in flaky-rules.json)
    Can't find 'action.yml', 'action.yaml' or 'Dockerfile' under 'C:\actions-runner\_work\executorch\executorch\test-infra\.github\actions\teardown-windows'. Did you forget to run actions/checkout before running your local action?
  • pull / unittest-editable / windows / windows-job (gh) (matched win rule in flaky-rules.json)
    Can't find 'action.yml', 'action.yaml' or 'Dockerfile' under 'C:\actions-runner\_work\executorch\executorch\test-infra\.github\actions\teardown-windows'. Did you forget to run actions/checkout before running your local action?

BROKEN TRUNK - The following job failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@github-actions

Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

This was referenced Jul 16, 2026
[ghstack-poisoned]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants