Skip to content

Arm backend: Match fp32->int32 cast between pytorch and TOSA's CAST #12243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

YufengShi-dudu
Copy link
Collaborator

@YufengShi-dudu YufengShi-dudu commented Jul 7, 2025

  • Pytorch .to() truncates values toward zeros, while TOSA's CAST rounds values to the nearest int. They will show different behaviours on fp32->int32 casting.
  • Fix the mismatched behaviour with the following transformation:
    Before:
    output = to_copy(x, torch.int32)
    After:
    is_non_negative = x >= 0
    floor_x = floor(x)
    ceil_x = ceil(x)
    decorated_x = where(is_non_negative, floor_x, ceil_x)
    output = to_copy(decorated_x, torch.int32)

Change-Id: I21286432eeb0a5e2f21865f3ac097051c921a9b3

cc @digantdesai @freddan80 @per @zingo @oscarandersson8218

- Pytorch .to() truncates values toward zeros, while TOSA's CAST
  rounds values to the nearest int. They will show different
  behaviours on fp32->int32 casting.
- Fix the mismatched behaviour with the following transformation:
  Before:
    output = to_copy(x, torch.int32)
  After:
    is_non_negative = x >= 0
    floor_x = floor(x)
    ceil_x = ceil(x)
    decorated_x = where(is_non_negative, floor_x, ceil_x)
    output = to_copy(decorated_x, torch.int32)

Change-Id: I21286432eeb0a5e2f21865f3ac097051c921a9b3
Signed-off-by: Yufeng Shi <yufeng.shi@arm.com>
@YufengShi-dudu YufengShi-dudu added partner: arm For backend delegation, kernels, demo, etc. from the 3rd-party partner, Arm ciflow/trunk release notes: arm Changes to the ARM backend delegate labels Jul 7, 2025
Copy link

pytorch-bot bot commented Jul 7, 2025

🔗 Helpful Links

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

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

❌ 1 New Failure, 1 Pending, 4 Unrelated Failures

As of commit 4e19b63 with merge base b342f83 (image):

NEW FAILURE - The following job has failed:

FLAKY - The following job failed but was likely due to flakiness present on trunk:

BROKEN TRUNK - The following jobs failed but was 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.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ciflow/trunk CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. partner: arm For backend delegation, kernels, demo, etc. from the 3rd-party partner, Arm release notes: arm Changes to the ARM backend delegate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants