Skip to content

Back out "[pytorch] Vectorize indexFuncLargeIndex for contiguous tensors (#175760)" (#182693) - #182693

Closed
AlbertDachiChen wants to merge 1 commit into
pytorch:mainfrom
AlbertDachiChen:export-D104098792
Closed

AlbertDachiChen wants to merge 1 commit into
pytorch:mainfrom
AlbertDachiChen:export-D104098792

Conversation

@AlbertDachiChen

@AlbertDachiChen AlbertDachiChen commented May 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

D94314062 introduced a VecSize=4 fast path in indexFuncLargeIndex that amortizes divmod and index lookup by having each thread process consecutive elements.

On uniform-random workloads this gives a ~1.8-2.0x speedup. However, when the index distribution is heavy-tailed (e.g. zipf, or skewed where a few hot rows receive millions of writes), the fast path issues 4 atomicAdds back-to-back from the same warp into consecutive cache lines of the same destination row.

The L2 atomic queue cannot drain between the unrolled rounds, and the resulting serialization causes a 4.7x slowdown on fp32 zipf inputs (and ~2x on bf16). Measured on a B200 with dst=[1.72M,128] and nIdx=7.77M:

{F1989310065}

Proposal https://fb.workplace.com/groups/482605989533128/permalink/1656067795520269/ exhibits highly skewed behavior and saw a regression with the diffs

We back the current implementation out temporarily and will be following the approach of #182675 instead and address the contention problem

Test Plan: CI

Reviewed By: yjhao

Differential Revision: D104098792

@pytorch-bot

pytorch-bot Bot commented May 6, 2026

Copy link
Copy Markdown

This appears to be a diff that was exported from phabricator, but the PR author does not have sufficient permissions to run CI. @AlbertDachiChen, please do step 2 of internal wiki to get write access so you do not need to get CI approvals in the future. If you think this is a mistake, please contact the Pytorch Dev Infra team.

@pytorch-bot

pytorch-bot Bot commented May 6, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

✅ You can merge normally! (1 Unrelated Failure)

As of commit 19650e4 with merge base cdae8ab (image):

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

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

@meta-codesync

meta-codesync Bot commented May 6, 2026

Copy link
Copy Markdown

@AlbertDachiChen has exported this pull request. If you are a Meta employee, you can view the originating Diff in D104098792.

@pytorch-bot

pytorch-bot Bot commented May 6, 2026

Copy link
Copy Markdown

This PR needs a release notes: label

If your changes are user facing and intended to be a part of release notes, please use a label starting with release notes:.

If not, please add the topic: not user facing label.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "topic: not user facing"

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

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label May 6, 2026
@meta-codesync meta-codesync Bot changed the title Back out "[pytorch] Vectorize indexFuncLargeIndex for contiguous tensors (#175760)" Back out "[pytorch] Vectorize indexFuncLargeIndex for contiguous tensors (#175760)" (#182693) May 6, 2026
AlbertDachiChen added a commit to AlbertDachiChen/pytorch that referenced this pull request May 6, 2026
…ors (pytorch#175760)" (pytorch#182693)

Summary:

D94314062 introduced a VecSize=4 fast path in indexFuncLargeIndex that amortizes divmod and index lookup by having each thread process consecutive elements.

On uniform-random workloads this gives a ~1.8-2.0x speedup. However, when the index distribution is heavy-tailed (e.g. zipf, or skewed where a few hot rows receive millions of writes), the fast path issues 4 atomicAdds back-to-back from the same warp into consecutive cache lines of the same destination row.

The L2 atomic queue cannot drain between the unrolled rounds, and the resulting serialization causes a 4.7x slowdown on fp32 zipf inputs (and ~2x on bf16). Measured on a B200 with dst=[1.72M,128] and nIdx=7.77M:

{F1989310065}


Proposal https://fb.workplace.com/groups/482605989533128/permalink/1656067795520269/  exhibits highly skewed behavior and saw a regression with the diffs 


We back the current implementation out temporarily and will be following the approach of pytorch#182675 instead and address the contention problem

Test Plan: CI

Reviewed By: yjhao

Differential Revision: D104098792
@pytorch-bot

pytorch-bot Bot commented May 6, 2026 •

Copy link
Copy Markdown

Workflows were awaiting approval. CI has now been triggered for the ciflow labels on this PR.

AlbertDachiChen added a commit to AlbertDachiChen/pytorch that referenced this pull request May 6, 2026
…ors (pytorch#175760)" (pytorch#182693)

Summary:

D94314062 introduced a VecSize=4 fast path in indexFuncLargeIndex that amortizes divmod and index lookup by having each thread process consecutive elements.

On uniform-random workloads this gives a ~1.8-2.0x speedup. However, when the index distribution is heavy-tailed (e.g. zipf, or skewed where a few hot rows receive millions of writes), the fast path issues 4 atomicAdds back-to-back from the same warp into consecutive cache lines of the same destination row.

The L2 atomic queue cannot drain between the unrolled rounds, and the resulting serialization causes a 4.7x slowdown on fp32 zipf inputs (and ~2x on bf16). Measured on a B200 with dst=[1.72M,128] and nIdx=7.77M:

{F1989310065}


Proposal https://fb.workplace.com/groups/482605989533128/permalink/1656067795520269/  exhibits highly skewed behavior and saw a regression with the diffs 


We back the current implementation out temporarily and will be following the approach of pytorch#182675 instead and address the contention problem

Test Plan: CI

Reviewed By: yjhao

Differential Revision: D104098792
…ors (pytorch#175760)" (pytorch#182693)

Summary:

D94314062 introduced a VecSize=4 fast path in indexFuncLargeIndex that amortizes divmod and index lookup by having each thread process consecutive elements.

On uniform-random workloads this gives a ~1.8-2.0x speedup. However, when the index distribution is heavy-tailed (e.g. zipf, or skewed where a few hot rows receive millions of writes), the fast path issues 4 atomicAdds back-to-back from the same warp into consecutive cache lines of the same destination row.

The L2 atomic queue cannot drain between the unrolled rounds, and the resulting serialization causes a 4.7x slowdown on fp32 zipf inputs (and ~2x on bf16). Measured on a B200 with dst=[1.72M,128] and nIdx=7.77M:

{F1989310065}


Proposal https://fb.workplace.com/groups/482605989533128/permalink/1656067795520269/  exhibits highly skewed behavior and saw a regression with the diffs 


We back the current implementation out temporarily and will be following the approach of pytorch#182675 instead and address the contention problem

Test Plan: CI

Reviewed By: yjhao

Differential Revision: D104098792
@facebook-github-tools

Copy link
Copy Markdown

@pytorchbot merge -i

(Initiating merge automatically since Phabricator Diff has merged, merging with -i because oss signals were bypassed internally)

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: This PR needs a release notes: label
If your changes are user facing and intended to be a part of release notes, please use a label starting with release notes:.

If not, please add the topic: not user facing label.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "topic: not user facing"

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

Details for Dev Infra team Raised by workflow job

@pytorch-bot

pytorch-bot Bot commented May 7, 2026

Copy link
Copy Markdown

This PR needs a release notes: label

If your changes are user facing and intended to be a part of release notes, please use a label starting with release notes:.

If not, please add the topic: not user facing label.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "topic: not user facing"

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

@facebook-github-tools

Copy link
Copy Markdown

@pytorchbot merge -i

(Initiating merge automatically since Phabricator Diff has merged, merging with -i because oss signals were bypassed internally)

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: This PR needs a release notes: label
If your changes are user facing and intended to be a part of release notes, please use a label starting with release notes:.

If not, please add the topic: not user facing label.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "topic: not user facing"

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

Details for Dev Infra team Raised by workflow job

@pytorch-bot

pytorch-bot Bot commented May 7, 2026

Copy link
Copy Markdown

This PR needs a release notes: label

If your changes are user facing and intended to be a part of release notes, please use a label starting with release notes:.

If not, please add the topic: not user facing label.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "topic: not user facing"

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

@facebook-github-tools

Copy link
Copy Markdown

@pytorchbot merge -i

(Initiating merge automatically since Phabricator Diff has merged, merging with -i because oss signals were bypassed internally)

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: This PR needs a release notes: label
If your changes are user facing and intended to be a part of release notes, please use a label starting with release notes:.

If not, please add the topic: not user facing label.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "topic: not user facing"

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

Details for Dev Infra team Raised by workflow job

@pytorch-bot

pytorch-bot Bot commented May 7, 2026

Copy link
Copy Markdown

This PR needs a release notes: label

If your changes are user facing and intended to be a part of release notes, please use a label starting with release notes:.

If not, please add the topic: not user facing label.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "topic: not user facing"

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

@facebook-github-tools

Copy link
Copy Markdown

@pytorchbot merge -i

(Initiating merge automatically since Phabricator Diff has merged, merging with -i because oss signals were bypassed internally)

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: This PR needs a release notes: label
If your changes are user facing and intended to be a part of release notes, please use a label starting with release notes:.

If not, please add the topic: not user facing label.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "topic: not user facing"

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

Details for Dev Infra team Raised by workflow job

@pytorch-bot

pytorch-bot Bot commented May 7, 2026

Copy link
Copy Markdown

This PR needs a release notes: label

If your changes are user facing and intended to be a part of release notes, please use a label starting with release notes:.

If not, please add the topic: not user facing label.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "topic: not user facing"

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

@facebook-github-tools

Copy link
Copy Markdown

@pytorchbot merge -i

(Initiating merge automatically since Phabricator Diff has merged, merging with -i because oss signals were bypassed internally)

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: This PR needs a release notes: label
If your changes are user facing and intended to be a part of release notes, please use a label starting with release notes:.

If not, please add the topic: not user facing label.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "topic: not user facing"

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

Details for Dev Infra team Raised by workflow job

@pytorch-bot

pytorch-bot Bot commented May 7, 2026

Copy link
Copy Markdown

This PR needs a release notes: label

If your changes are user facing and intended to be a part of release notes, please use a label starting with release notes:.

If not, please add the topic: not user facing label.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "topic: not user facing"

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

@facebook-github-tools

Copy link
Copy Markdown

@pytorchbot merge -i

(Initiating merge automatically since Phabricator Diff has merged, merging with -i because oss signals were bypassed internally)

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: This PR needs a release notes: label
If your changes are user facing and intended to be a part of release notes, please use a label starting with release notes:.

If not, please add the topic: not user facing label.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "topic: not user facing"

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

Details for Dev Infra team Raised by workflow job

@pytorch-bot

pytorch-bot Bot commented May 7, 2026

Copy link
Copy Markdown

This PR needs a release notes: label

If your changes are user facing and intended to be a part of release notes, please use a label starting with release notes:.

If not, please add the topic: not user facing label.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "topic: not user facing"

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

@huydhn huydhn added the topic: not user facing topic category label May 7, 2026
@huydhn

huydhn commented May 7, 2026

Copy link
Copy Markdown
Contributor

@pytorchbot merge -f 'This has been landed internally'

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes). Please use -f as last resort and instead consider -i/--ignore-current to continue the merge ignoring current failures. This will allow currently pending tests to finish and report signal before the merge.

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

Alokksinha00 pushed a commit to Alokksinha00/pytorch that referenced this pull request May 15, 2026
…ors (pytorch#175760)" (pytorch#182693) (pytorch#182693)

Summary:

D94314062 introduced a VecSize=4 fast path in indexFuncLargeIndex that amortizes divmod and index lookup by having each thread process consecutive elements.

On uniform-random workloads this gives a ~1.8-2.0x speedup. However, when the index distribution is heavy-tailed (e.g. zipf, or skewed where a few hot rows receive millions of writes), the fast path issues 4 atomicAdds back-to-back from the same warp into consecutive cache lines of the same destination row.

The L2 atomic queue cannot drain between the unrolled rounds, and the resulting serialization causes a 4.7x slowdown on fp32 zipf inputs (and ~2x on bf16). Measured on a B200 with dst=[1.72M,128] and nIdx=7.77M:

{F1989310065}

Proposal https://fb.workplace.com/groups/482605989533128/permalink/1656067795520269/  exhibits highly skewed behavior and saw a regression with the diffs

We back the current implementation out temporarily and will be following the approach of pytorch#182675 instead and address the contention problem

Test Plan: CI

Reviewed By: yjhao

Differential Revision: D104098792

Pull Request resolved: pytorch#182693
Approved by: https://github.com/drisspg
aperson30 pushed a commit to aperson30/pytorch that referenced this pull request Jun 20, 2026
…ors (pytorch#175760)" (pytorch#182693) (pytorch#182693)

Summary:

D94314062 introduced a VecSize=4 fast path in indexFuncLargeIndex that amortizes divmod and index lookup by having each thread process consecutive elements.

On uniform-random workloads this gives a ~1.8-2.0x speedup. However, when the index distribution is heavy-tailed (e.g. zipf, or skewed where a few hot rows receive millions of writes), the fast path issues 4 atomicAdds back-to-back from the same warp into consecutive cache lines of the same destination row.

The L2 atomic queue cannot drain between the unrolled rounds, and the resulting serialization causes a 4.7x slowdown on fp32 zipf inputs (and ~2x on bf16). Measured on a B200 with dst=[1.72M,128] and nIdx=7.77M:

{F1989310065}

Proposal https://fb.workplace.com/groups/482605989533128/permalink/1656067795520269/  exhibits highly skewed behavior and saw a regression with the diffs

We back the current implementation out temporarily and will be following the approach of pytorch#182675 instead and address the contention problem

Test Plan: CI

Reviewed By: yjhao

Differential Revision: D104098792

Pull Request resolved: pytorch#182693
Approved by: https://github.com/drisspg
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
…ors (pytorch#175760)" (pytorch#182693) (pytorch#182693)

Summary:

D94314062 introduced a VecSize=4 fast path in indexFuncLargeIndex that amortizes divmod and index lookup by having each thread process consecutive elements.

On uniform-random workloads this gives a ~1.8-2.0x speedup. However, when the index distribution is heavy-tailed (e.g. zipf, or skewed where a few hot rows receive millions of writes), the fast path issues 4 atomicAdds back-to-back from the same warp into consecutive cache lines of the same destination row.

The L2 atomic queue cannot drain between the unrolled rounds, and the resulting serialization causes a 4.7x slowdown on fp32 zipf inputs (and ~2x on bf16). Measured on a B200 with dst=[1.72M,128] and nIdx=7.77M:

{F1989310065}

Proposal https://fb.workplace.com/groups/482605989533128/permalink/1656067795520269/  exhibits highly skewed behavior and saw a regression with the diffs

We back the current implementation out temporarily and will be following the approach of pytorch#182675 instead and address the contention problem

Test Plan: CI

Reviewed By: yjhao

Differential Revision: D104098792

Pull Request resolved: pytorch#182693
Approved by: https://github.com/drisspg
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
…ors (pytorch#175760)" (pytorch#182693) (pytorch#182693)

Summary:

D94314062 introduced a VecSize=4 fast path in indexFuncLargeIndex that amortizes divmod and index lookup by having each thread process consecutive elements.

On uniform-random workloads this gives a ~1.8-2.0x speedup. However, when the index distribution is heavy-tailed (e.g. zipf, or skewed where a few hot rows receive millions of writes), the fast path issues 4 atomicAdds back-to-back from the same warp into consecutive cache lines of the same destination row.

The L2 atomic queue cannot drain between the unrolled rounds, and the resulting serialization causes a 4.7x slowdown on fp32 zipf inputs (and ~2x on bf16). Measured on a B200 with dst=[1.72M,128] and nIdx=7.77M:

{F1989310065}

Proposal https://fb.workplace.com/groups/482605989533128/permalink/1656067795520269/  exhibits highly skewed behavior and saw a regression with the diffs

We back the current implementation out temporarily and will be following the approach of pytorch#182675 instead and address the contention problem

Test Plan: CI

Reviewed By: yjhao

Differential Revision: D104098792

Pull Request resolved: pytorch#182693
Approved by: https://github.com/drisspg
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 fb-exported Merged meta-exported topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants