Skip to content

Add no-tree-loop-optimize pragma for apply_grad_input on GCC/AArch64 - #182034

Closed
robert-hardwick wants to merge 4 commits into
gh/robert-hardwick/20/basefrom
gh/robert-hardwick/20/head
Closed

robert-hardwick wants to merge 4 commits into
gh/robert-hardwick/20/basefrom
gh/robert-hardwick/20/head

Conversation

@robert-hardwick

@robert-hardwick robert-hardwick commented Apr 30, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes an AArch64 GCC optimization issue in CPU upsample backward for reduced-precision gradients.

The reduced-precision apply_grad_input path accumulates a temporary float buffer into BFloat16/Half gradients. On AArch64 GCC builds, tree vectorization of this function can produce incorrect results or illegal instructions. This change disables GCC tree vectorization only around that overload, while preserving the explicit PyTorch Vectorized<> implementation inside the function.

The ARM64 xfail for TestNN.test_upsampling_bfloat16 is removed because the test now passes with this guard.

Stack from ghstack (oldest at bottom):

Fixes #177250

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Apr 30, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

✅ No Failures

As of commit e095ecd with merge base 11261ac (image):
💚 Looks good so far! There are no failures yet. 💚

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

@pytorch-bot pytorch-bot Bot added the release notes: nn release notes category label Apr 30, 2026
[ghstack-poisoned]
robert-hardwick added a commit that referenced this pull request Apr 30, 2026
@Skylion007

Copy link
Copy Markdown
Collaborator

Summary

Fixes an AArch64 GCC optimization issue in CPU upsample backward for reduced-precision gradients.

The reduced-precision apply_grad_input path accumulates a temporary float buffer into BFloat16/Half gradients. On AArch64 GCC builds, tree vectorization of this function can produce incorrect results or illegal instructions. This change disables GCC tree vectorization only around that overload, while preserving the explicit PyTorch Vectorized<> implementation inside the function.

The ARM64 xfail for TestNN.test_upsampling_bfloat16 is removed because the test now passes with this guard.

Stack from ghstack (oldest at bottom):

* **->** [Add no-tree-loop-optimize pragma for apply_grad_input on GCC/AArch64 #182034](https://github.com/pytorch/pytorch/pull/182034)

Fixes #177250

Oh. THIS IS WHY enabling LTO fixed this bug, it was making it decide not to vectorize it. Interesting...

Comment thread aten/src/ATen/native/UpSample.h Outdated
return;
}

// Avoid GCC AArch64 tree-vectorization issues when adding float buffers to BFloat16/Half gradients.

@Skylion007 Skylion007 Apr 30, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still still a bug on GCC15? We are about to update GCC from 13 to 15 for AARCH anyway. #182016

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going to do this next, it's better to scope it to specific GCC versions if possible. I should probably have set this as draft until that's done, but i'll leave it open.

@Anndrey24 Anndrey24 May 1, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested this on 13, 14 and 15 and looks like it has been fixed in 14 and 15 so i've updated the pragma to a tighter scope.

[ghstack-poisoned]
robert-hardwick added a commit that referenced this pull request May 1, 2026
@robert-hardwick

Copy link
Copy Markdown
Collaborator Author

I seem to have included some other commits in here, marking as draft until i've fixed that

@robert-hardwick
robert-hardwick marked this pull request as draft May 2, 2026 14:04
[ghstack-poisoned]
robert-hardwick added a commit that referenced this pull request May 2, 2026
@robert-hardwick
robert-hardwick marked this pull request as ready for review May 2, 2026 14:23
@robert-hardwick

Copy link
Copy Markdown
Collaborator Author

I seem to have included some other commits in here, marking as draft until i've fixed that

OK fixed it now. We should have the correct pragma change scoped to only affect GCC < 14.

@aditew01 aditew01 added the ciflow/trunk Trigger trunk jobs on your pull request label May 11, 2026
Anndrey24 added a commit to Anndrey24/pytorch that referenced this pull request May 14, 2026
This commits temporarily skips tests fixed by pytorch#182034 and pytorch#183697
@aditew01

Copy link
Copy Markdown
Collaborator

@pytorchbot rebase

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Rebase failed due to Command git -C /home/runner/work/pytorch/pytorch rebase refs/remotes/origin/viable/strict gh/robert-hardwick/20/orig returned non-zero exit code 1

Rebasing (1/1)
Auto-merging test/test_nn.py
CONFLICT (content): Merge conflict in test/test_nn.py
error: could not apply 8853e61f96d... Add no-tree-loop-optimize pragma for apply_grad_input on GCC/AArch64
hint: Resolve all conflicts manually, mark them as resolved with
hint: "git add/rm <conflicted_files>", then run "git rebase --continue".
hint: You can instead skip this commit: run "git rebase --skip".
hint: To abort and get back to the state before "git rebase", run "git rebase --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Could not apply 8853e61f96d... # Add no-tree-loop-optimize pragma for apply_grad_input on GCC/AArch64

Raised by https://github.com/pytorch/pytorch/actions/runs/26583354552

@aditew01

Copy link
Copy Markdown
Collaborator

@pytorchbot rebase

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Rebase failed due to Command git -C /home/runner/work/pytorch/pytorch rebase refs/remotes/origin/viable/strict gh/robert-hardwick/20/orig returned non-zero exit code 1

Rebasing (1/1)
Auto-merging test/test_nn.py
CONFLICT (content): Merge conflict in test/test_nn.py
error: could not apply 8853e61f96d... Add no-tree-loop-optimize pragma for apply_grad_input on GCC/AArch64
hint: Resolve all conflicts manually, mark them as resolved with
hint: "git add/rm <conflicted_files>", then run "git rebase --continue".
hint: You can instead skip this commit: run "git rebase --skip".
hint: To abort and get back to the state before "git rebase", run "git rebase --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Could not apply 8853e61f96d... # Add no-tree-loop-optimize pragma for apply_grad_input on GCC/AArch64

Raised by https://github.com/pytorch/pytorch/actions/runs/27534654544

@github-actions

Copy link
Copy Markdown
Contributor

Looks like this PR hasn't been updated in a while so we're going to go ahead and mark this as Stale.
Feel free to remove the Stale label if you feel this was a mistake.
If you are unable to remove the Stale label please contact a maintainer in order to do so.
If you want the bot to never mark this PR stale again, add the no-stale label.
Stale pull requests will automatically be closed after 30 days of inactivity.

@github-actions github-actions Bot added the Stale label Aug 14, 2026
@Skylion007

Copy link
Copy Markdown
Collaborator

@pytorchbot rebase

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Rebase failed due to Command git -C /home/runner/work/pytorch/pytorch rebase refs/remotes/origin/viable/strict gh/robert-hardwick/20/orig returned non-zero exit code 1

Rebasing (1/1)
Auto-merging aten/src/ATen/native/UpSample.h
Auto-merging test/test_nn.py
CONFLICT (content): Merge conflict in test/test_nn.py
error: could not apply 8853e61f96d... Add no-tree-loop-optimize pragma for apply_grad_input on GCC/AArch64
hint: Resolve all conflicts manually, mark them as resolved with
hint: "git add/rm <conflicted_files>", then run "git rebase --continue".
hint: You can instead skip this commit: run "git rebase --skip".
hint: To abort and get back to the state before "git rebase", run "git rebase --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Could not apply 8853e61f96d... # Add no-tree-loop-optimize pragma for apply_grad_input on GCC/AArch64

Raised by https://github.com/pytorch/pytorch/actions/runs/31814080717

@aditew01

Copy link
Copy Markdown
Collaborator

@pytorchbot rebase

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Rebase failed due to Command git -C /home/runner/work/pytorch/pytorch rebase refs/remotes/origin/viable/strict gh/robert-hardwick/20/orig returned non-zero exit code 1

Rebasing (1/1)
Auto-merging aten/src/ATen/native/UpSample.h
Auto-merging test/test_nn.py
CONFLICT (content): Merge conflict in test/test_nn.py
error: could not apply 8853e61f96d... Add no-tree-loop-optimize pragma for apply_grad_input on GCC/AArch64
hint: Resolve all conflicts manually, mark them as resolved with
hint: "git add/rm <conflicted_files>", then run "git rebase --continue".
hint: You can instead skip this commit: run "git rebase --skip".
hint: To abort and get back to the state before "git rebase", run "git rebase --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Could not apply 8853e61f96d... # Add no-tree-loop-optimize pragma for apply_grad_input on GCC/AArch64

Raised by https://github.com/pytorch/pytorch/actions/runs/32863406276

@github-actions github-actions Bot closed this Sep 24, 2026
@github-actions
github-actions Bot deleted the gh/robert-hardwick/20/head branch October 25, 2026 01:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request open source release notes: nn release notes category Stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants