Repository navigation
[Reland] Port D104346887/PR 182675 for index_add fast path (#184824) - #189506
AlbertDachiChen wants to merge 1 commit into
Conversation
…84824) Summary: Second reland of the `index_add -> scatter_add` delegation. This reland sits on top of D110978969 ([native] Move scatter-add N-dim to dynamic, pytorch#188820), which moves the scatter_add CuTeDSL override's compile-cache key for the inner dimension to dynamic, so a single compile serves all N sizes instead of recompiling per application (dtype and contig/non-contig still recompile). With D110978969 landed, the issue behind the most recent revert of this diff is resolved, so the delegation is re-applied here unchanged. Adopts the vectorized scatter_add(dim=0) kernel from D104346887 / PR pytorch#182675 as a fast path for `index_add_` on CUDA. `index_add_(0, idx, src)` is mathematically equivalent to `self.scatter_add_(0, idx.unsqueeze(-1).expand_as(src), src)` when `alpha == 1`, so we delegate so scatter_add's own TMA/vectorized eligibility check + dispatch is the single source of truth. Eligibility (all required to enter the fast path): - `dim == 0` - `alpha == 1` - dtype supported by scatter_add (excludes complex + bool) - `index.dim() <= 1` and contiguous, `numIndex > 0` - scatter_add gates internally per-dtype: TMA sm_90+; vec-scatter sm_60+/sm_70+/sm_90+ for fp32/fp16/bf16 - CUDA 12.8+ at compile time Outside the eligible regime, falls through to the existing `indexFunc{Small,Large}Index` dispatch (untouched). ## Benchmarks Kernel-side perf is unchanged from D104669063 (the delegation forwards to the same scatter_add kernel, now with PR pytorch#184554's smem padding). See D104669063 summary for full B200 and H100 benchmark tables. Highlights: - Real workloads: B200 4.52x (bf16) / 2.74x (fp32); H100 2.97x (bf16) / 1.42x (fp32). - bf16 sweeps up to 7.40x on B200; zipf high-contention is neutral on both arches (atomic-contention-bound, not bandwidth-bound). PR pytorch#184554's stage-stride padding is a one-extra-smem-byte change in the worst case (chunk_bytes already padded for chunk_bytes >= 128), so no measurable perf delta from the parent commit. bypass-github-export-checks unrelated failure Test Plan: Re-running the original D104669063 test suite plus the new small-D + high-M_src regression added in this diff: ``` buck2 test fbcode//mode/opt -c fbcode.enable_gpu_sections=true \ -c fbcode.platform010_cuda_version=12.8 -c fbcode.nvcc_arch=h100a \ fbcode//caffe2/test:test_others_cuda -- \ --regex 'test_index_add_fast_path|test_index_add_excluded_dtypes|test_index_add_smem_stage_alignment_regression' ``` Expected: pass on all parametrized variants (fp32 / fp64 / half / bf16 across 3 shapes x 2 index dtypes for `test_index_add_fast_path`; complex64 / complex128 / bool for `test_index_add_excluded_dtypes`; fp32 / bf16 for the new regression). `test_index_add_smem_stage_alignment_regression` specifically reproduces the SEV-class shape (D=8, M_src = sm * 64 + 256 so every CTA enters stage 1) and asserts numerical equality against a CPU reference. Without PR pytorch#184554 in the same build, this test crashes with `cudaErrorMisalignedAddress`; with the parent commit present, it passes cleanly. No regressions in existing `index_add` tests. Check that issues gone in https://www.internalfb.com/mlhub/pipelines/runs/mast/fire-albertchen-train-f1110230424?job_attempt=1&version=0&tab=summary https://www.internalfb.com/mlhub/pipelines/runs/mast/fire-albertchen-train-mast-UDD-2026-06-27-3d-f958b44a?job_attempt=1&version=0&tab=summary&env=PRODUCTION https://www.internalfb.com/mlhub/pipelines/runs/mast/mvai-training-online-2115904614?version=0&env=PRODUCTION Differential Revision: D111254885
|
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. |
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/189506
Note: Links to docs will display an error until the docs builds have been completed. ❗ 1 Active SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below: ✅ No FailuresAs of commit 55fd059 with merge base 68fb12e ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@AlbertDachiChen has exported this pull request. If you are a Meta employee, you can view the originating Diff in D111254885. |
|
@pytorchbot merge -i (Initiating merge automatically since Phabricator Diff has merged, merging with -i because oss signals were bypassed internally) |
|
This PR needs to be approved by an authorized maintainer before merge. |
|
@pytorchbot merge -i |
Merge failedReason: This PR needs a If not, please add the To add a label, you can comment to pytorchbot, for example For more information, see Details for Dev Infra teamRaised by workflow job |
|
@pytorchbot merge -i |
Merge startedYour change will be merged while ignoring the following 0 checks: Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
…84824) (pytorch#189506) Summary: Second reland of the `index_add -> scatter_add` delegation. This reland sits on top of D110978969 ([native] Move scatter-add N-dim to dynamic, pytorch#188820), which moves the scatter_add CuTeDSL override's compile-cache key for the inner dimension to dynamic, so a single compile serves all N sizes instead of recompiling per application (dtype and contig/non-contig still recompile). With D110978969 landed, the issue behind the most recent revert of this diff is resolved, so the delegation is re-applied here unchanged. Adopts the vectorized scatter_add(dim=0) kernel from D104346887 / PR pytorch#182675 as a fast path for `index_add_` on CUDA. `index_add_(0, idx, src)` is mathematically equivalent to `self.scatter_add_(0, idx.unsqueeze(-1).expand_as(src), src)` when `alpha == 1`, so we delegate so scatter_add's own TMA/vectorized eligibility check + dispatch is the single source of truth. Eligibility (all required to enter the fast path): - `dim == 0` - `alpha == 1` - dtype supported by scatter_add (excludes complex + bool) - `index.dim() <= 1` and contiguous, `numIndex > 0` - scatter_add gates internally per-dtype: TMA sm_90+; vec-scatter sm_60+/sm_70+/sm_90+ for fp32/fp16/bf16 - CUDA 12.8+ at compile time Outside the eligible regime, falls through to the existing `indexFunc{Small,Large}Index` dispatch (untouched). ## Benchmarks Kernel-side perf is unchanged from D104669063 (the delegation forwards to the same scatter_add kernel, now with PR pytorch#184554's smem padding). See D104669063 summary for full B200 and H100 benchmark tables. Highlights: - Real workloads: B200 4.52x (bf16) / 2.74x (fp32); H100 2.97x (bf16) / 1.42x (fp32). - bf16 sweeps up to 7.40x on B200; zipf high-contention is neutral on both arches (atomic-contention-bound, not bandwidth-bound). PR pytorch#184554's stage-stride padding is a one-extra-smem-byte change in the worst case (chunk_bytes already padded for chunk_bytes >= 128), so no measurable perf delta from the parent commit. bypass-github-export-checks unrelated failure Test Plan: Re-running the original D104669063 test suite plus the new small-D + high-M_src regression added in this diff: ``` buck2 test fbcode//mode/opt -c fbcode.enable_gpu_sections=true \ -c fbcode.platform010_cuda_version=12.8 -c fbcode.nvcc_arch=h100a \ fbcode//caffe2/test:test_others_cuda -- \ --regex 'test_index_add_fast_path|test_index_add_excluded_dtypes|test_index_add_smem_stage_alignment_regression' ``` Expected: pass on all parametrized variants (fp32 / fp64 / half / bf16 across 3 shapes x 2 index dtypes for `test_index_add_fast_path`; complex64 / complex128 / bool for `test_index_add_excluded_dtypes`; fp32 / bf16 for the new regression). `test_index_add_smem_stage_alignment_regression` specifically reproduces the SEV-class shape (D=8, M_src = sm * 64 + 256 so every CTA enters stage 1) and asserts numerical equality against a CPU reference. Without PR pytorch#184554 in the same build, this test crashes with `cudaErrorMisalignedAddress`; with the parent commit present, it passes cleanly. No regressions in existing `index_add` tests. Check that issues gone in https://www.internalfb.com/mlhub/pipelines/runs/mast/fire-albertchen-train-f1110230424?job_attempt=1&version=0&tab=summary https://www.internalfb.com/mlhub/pipelines/runs/mast/fire-albertchen-train-mast-UDD-2026-06-27-3d-f958b44a?job_attempt=1&version=0&tab=summary&env=PRODUCTION https://www.internalfb.com/mlhub/pipelines/runs/mast/mvai-training-online-2115904614?version=0&env=PRODUCTION Differential Revision: D111254885 Pull Request resolved: pytorch#189506 Approved by: https://github.com/jeanschmidt
…84824) (pytorch#189506) Summary: Second reland of the `index_add -> scatter_add` delegation. This reland sits on top of D110978969 ([native] Move scatter-add N-dim to dynamic, pytorch#188820), which moves the scatter_add CuTeDSL override's compile-cache key for the inner dimension to dynamic, so a single compile serves all N sizes instead of recompiling per application (dtype and contig/non-contig still recompile). With D110978969 landed, the issue behind the most recent revert of this diff is resolved, so the delegation is re-applied here unchanged. Adopts the vectorized scatter_add(dim=0) kernel from D104346887 / PR pytorch#182675 as a fast path for `index_add_` on CUDA. `index_add_(0, idx, src)` is mathematically equivalent to `self.scatter_add_(0, idx.unsqueeze(-1).expand_as(src), src)` when `alpha == 1`, so we delegate so scatter_add's own TMA/vectorized eligibility check + dispatch is the single source of truth. Eligibility (all required to enter the fast path): - `dim == 0` - `alpha == 1` - dtype supported by scatter_add (excludes complex + bool) - `index.dim() <= 1` and contiguous, `numIndex > 0` - scatter_add gates internally per-dtype: TMA sm_90+; vec-scatter sm_60+/sm_70+/sm_90+ for fp32/fp16/bf16 - CUDA 12.8+ at compile time Outside the eligible regime, falls through to the existing `indexFunc{Small,Large}Index` dispatch (untouched). ## Benchmarks Kernel-side perf is unchanged from D104669063 (the delegation forwards to the same scatter_add kernel, now with PR pytorch#184554's smem padding). See D104669063 summary for full B200 and H100 benchmark tables. Highlights: - Real workloads: B200 4.52x (bf16) / 2.74x (fp32); H100 2.97x (bf16) / 1.42x (fp32). - bf16 sweeps up to 7.40x on B200; zipf high-contention is neutral on both arches (atomic-contention-bound, not bandwidth-bound). PR pytorch#184554's stage-stride padding is a one-extra-smem-byte change in the worst case (chunk_bytes already padded for chunk_bytes >= 128), so no measurable perf delta from the parent commit. bypass-github-export-checks unrelated failure Test Plan: Re-running the original D104669063 test suite plus the new small-D + high-M_src regression added in this diff: ``` buck2 test fbcode//mode/opt -c fbcode.enable_gpu_sections=true \ -c fbcode.platform010_cuda_version=12.8 -c fbcode.nvcc_arch=h100a \ fbcode//caffe2/test:test_others_cuda -- \ --regex 'test_index_add_fast_path|test_index_add_excluded_dtypes|test_index_add_smem_stage_alignment_regression' ``` Expected: pass on all parametrized variants (fp32 / fp64 / half / bf16 across 3 shapes x 2 index dtypes for `test_index_add_fast_path`; complex64 / complex128 / bool for `test_index_add_excluded_dtypes`; fp32 / bf16 for the new regression). `test_index_add_smem_stage_alignment_regression` specifically reproduces the SEV-class shape (D=8, M_src = sm * 64 + 256 so every CTA enters stage 1) and asserts numerical equality against a CPU reference. Without PR pytorch#184554 in the same build, this test crashes with `cudaErrorMisalignedAddress`; with the parent commit present, it passes cleanly. No regressions in existing `index_add` tests. Check that issues gone in https://www.internalfb.com/mlhub/pipelines/runs/mast/fire-albertchen-train-f1110230424?job_attempt=1&version=0&tab=summary https://www.internalfb.com/mlhub/pipelines/runs/mast/fire-albertchen-train-mast-UDD-2026-06-27-3d-f958b44a?job_attempt=1&version=0&tab=summary&env=PRODUCTION https://www.internalfb.com/mlhub/pipelines/runs/mast/mvai-training-online-2115904614?version=0&env=PRODUCTION Differential Revision: D111254885 Pull Request resolved: pytorch#189506 Approved by: https://github.com/jeanschmidt
…84824) (pytorch#189506) Summary: Second reland of the `index_add -> scatter_add` delegation. This reland sits on top of D110978969 ([native] Move scatter-add N-dim to dynamic, pytorch#188820), which moves the scatter_add CuTeDSL override's compile-cache key for the inner dimension to dynamic, so a single compile serves all N sizes instead of recompiling per application (dtype and contig/non-contig still recompile). With D110978969 landed, the issue behind the most recent revert of this diff is resolved, so the delegation is re-applied here unchanged. Adopts the vectorized scatter_add(dim=0) kernel from D104346887 / PR pytorch#182675 as a fast path for `index_add_` on CUDA. `index_add_(0, idx, src)` is mathematically equivalent to `self.scatter_add_(0, idx.unsqueeze(-1).expand_as(src), src)` when `alpha == 1`, so we delegate so scatter_add's own TMA/vectorized eligibility check + dispatch is the single source of truth. Eligibility (all required to enter the fast path): - `dim == 0` - `alpha == 1` - dtype supported by scatter_add (excludes complex + bool) - `index.dim() <= 1` and contiguous, `numIndex > 0` - scatter_add gates internally per-dtype: TMA sm_90+; vec-scatter sm_60+/sm_70+/sm_90+ for fp32/fp16/bf16 - CUDA 12.8+ at compile time Outside the eligible regime, falls through to the existing `indexFunc{Small,Large}Index` dispatch (untouched). ## Benchmarks Kernel-side perf is unchanged from D104669063 (the delegation forwards to the same scatter_add kernel, now with PR pytorch#184554's smem padding). See D104669063 summary for full B200 and H100 benchmark tables. Highlights: - Real workloads: B200 4.52x (bf16) / 2.74x (fp32); H100 2.97x (bf16) / 1.42x (fp32). - bf16 sweeps up to 7.40x on B200; zipf high-contention is neutral on both arches (atomic-contention-bound, not bandwidth-bound). PR pytorch#184554's stage-stride padding is a one-extra-smem-byte change in the worst case (chunk_bytes already padded for chunk_bytes >= 128), so no measurable perf delta from the parent commit. bypass-github-export-checks unrelated failure Test Plan: Re-running the original D104669063 test suite plus the new small-D + high-M_src regression added in this diff: ``` buck2 test fbcode//mode/opt -c fbcode.enable_gpu_sections=true \ -c fbcode.platform010_cuda_version=12.8 -c fbcode.nvcc_arch=h100a \ fbcode//caffe2/test:test_others_cuda -- \ --regex 'test_index_add_fast_path|test_index_add_excluded_dtypes|test_index_add_smem_stage_alignment_regression' ``` Expected: pass on all parametrized variants (fp32 / fp64 / half / bf16 across 3 shapes x 2 index dtypes for `test_index_add_fast_path`; complex64 / complex128 / bool for `test_index_add_excluded_dtypes`; fp32 / bf16 for the new regression). `test_index_add_smem_stage_alignment_regression` specifically reproduces the SEV-class shape (D=8, M_src = sm * 64 + 256 so every CTA enters stage 1) and asserts numerical equality against a CPU reference. Without PR pytorch#184554 in the same build, this test crashes with `cudaErrorMisalignedAddress`; with the parent commit present, it passes cleanly. No regressions in existing `index_add` tests. Check that issues gone in https://www.internalfb.com/mlhub/pipelines/runs/mast/fire-albertchen-train-f1110230424?job_attempt=1&version=0&tab=summary https://www.internalfb.com/mlhub/pipelines/runs/mast/fire-albertchen-train-mast-UDD-2026-06-27-3d-f958b44a?job_attempt=1&version=0&tab=summary&env=PRODUCTION https://www.internalfb.com/mlhub/pipelines/runs/mast/mvai-training-online-2115904614?version=0&env=PRODUCTION Differential Revision: D111254885 Pull Request resolved: pytorch#189506 Approved by: https://github.com/jeanschmidt
…84824) (pytorch#189506) Summary: Second reland of the `index_add -> scatter_add` delegation. This reland sits on top of D110978969 ([native] Move scatter-add N-dim to dynamic, pytorch#188820), which moves the scatter_add CuTeDSL override's compile-cache key for the inner dimension to dynamic, so a single compile serves all N sizes instead of recompiling per application (dtype and contig/non-contig still recompile). With D110978969 landed, the issue behind the most recent revert of this diff is resolved, so the delegation is re-applied here unchanged. Adopts the vectorized scatter_add(dim=0) kernel from D104346887 / PR pytorch#182675 as a fast path for `index_add_` on CUDA. `index_add_(0, idx, src)` is mathematically equivalent to `self.scatter_add_(0, idx.unsqueeze(-1).expand_as(src), src)` when `alpha == 1`, so we delegate so scatter_add's own TMA/vectorized eligibility check + dispatch is the single source of truth. Eligibility (all required to enter the fast path): - `dim == 0` - `alpha == 1` - dtype supported by scatter_add (excludes complex + bool) - `index.dim() <= 1` and contiguous, `numIndex > 0` - scatter_add gates internally per-dtype: TMA sm_90+; vec-scatter sm_60+/sm_70+/sm_90+ for fp32/fp16/bf16 - CUDA 12.8+ at compile time Outside the eligible regime, falls through to the existing `indexFunc{Small,Large}Index` dispatch (untouched). ## Benchmarks Kernel-side perf is unchanged from D104669063 (the delegation forwards to the same scatter_add kernel, now with PR pytorch#184554's smem padding). See D104669063 summary for full B200 and H100 benchmark tables. Highlights: - Real workloads: B200 4.52x (bf16) / 2.74x (fp32); H100 2.97x (bf16) / 1.42x (fp32). - bf16 sweeps up to 7.40x on B200; zipf high-contention is neutral on both arches (atomic-contention-bound, not bandwidth-bound). PR pytorch#184554's stage-stride padding is a one-extra-smem-byte change in the worst case (chunk_bytes already padded for chunk_bytes >= 128), so no measurable perf delta from the parent commit. bypass-github-export-checks unrelated failure Test Plan: Re-running the original D104669063 test suite plus the new small-D + high-M_src regression added in this diff: ``` buck2 test fbcode//mode/opt -c fbcode.enable_gpu_sections=true \ -c fbcode.platform010_cuda_version=12.8 -c fbcode.nvcc_arch=h100a \ fbcode//caffe2/test:test_others_cuda -- \ --regex 'test_index_add_fast_path|test_index_add_excluded_dtypes|test_index_add_smem_stage_alignment_regression' ``` Expected: pass on all parametrized variants (fp32 / fp64 / half / bf16 across 3 shapes x 2 index dtypes for `test_index_add_fast_path`; complex64 / complex128 / bool for `test_index_add_excluded_dtypes`; fp32 / bf16 for the new regression). `test_index_add_smem_stage_alignment_regression` specifically reproduces the SEV-class shape (D=8, M_src = sm * 64 + 256 so every CTA enters stage 1) and asserts numerical equality against a CPU reference. Without PR pytorch#184554 in the same build, this test crashes with `cudaErrorMisalignedAddress`; with the parent commit present, it passes cleanly. No regressions in existing `index_add` tests. Check that issues gone in https://www.internalfb.com/mlhub/pipelines/runs/mast/fire-albertchen-train-f1110230424?job_attempt=1&version=0&tab=summary https://www.internalfb.com/mlhub/pipelines/runs/mast/fire-albertchen-train-mast-UDD-2026-06-27-3d-f958b44a?job_attempt=1&version=0&tab=summary&env=PRODUCTION https://www.internalfb.com/mlhub/pipelines/runs/mast/mvai-training-online-2115904614?version=0&env=PRODUCTION Differential Revision: D111254885 Pull Request resolved: pytorch#189506 Approved by: https://github.com/jeanschmidt
…l) (#3594) ## Summary Carry-forward of ROCm-specific commits from `release/2.13` onto `release/2.14` ? the 2.14 analog of the 2.13 "IFU dedup" ([PR #3503](#3503)). Analyzes the full IFU delta from [PR #3591](#3591) at `release/2.13`'s tip (`6596a0d`): **81 commits** in `release/2.13` not in `release/2.14`, each either dropped (already in 2.14, or 2.13-only) or cherry-picked here. ## Method Same rules as the [release/2.13 cherry-pick process](https://amd.atlassian.net/wiki/spaces/MLSE/pages/1819593560): - **Drop ? already in 2.14**: patch-id equivalence (`git cherry`), upstream PR already present, or content already relocated/absorbed into 2.14 (verified during cherry-pick). - **Drop ? 2.13-only**: version bump, `related_commits`, dependency/requirements pins, release-line CD/build changes. - **Carry-forward**: ROCm-specific fixes not present in 2.14 in any form. ## Commits carried forward (13) | Source | Notes | |--------|-------| | Fix reentrant deadlock in `torch.cuda._lazy_call` (#3496) | clean | | Skip ROCm-failing tests in test_cuda/test_nn (#3504) | **conflict resolved** ? kept 2.14's `test_graph_capture_error...` cleanup + took `@skipIfRocm`; kept 2.14's `test_allocator_backend` (already fixes LD_LIBRARY_PATH via `subprocess_env()`) | | skip test_hip_device_count (rocprofiler-sdk) | clean | | skip flaky test_Embedding_discontiguous_cuda | clean | | Skip profiler check for foreach tests on ROCm (#3262) | clean | | Skip test_is_pinned_no_context on python 3.14+ | clean | | Skip flaky test_reentrant_parent_error_on_cpu | clean | | Filter out CK gemms for gfx1250-only arch (#3545) | clean | | Fix hipify skipping sources under Windows subst drives (ROCM-29365) (#3561) | clean | | Fixed gfx1250_preferred_backend test (#3546) | clean | | [ROCm] Optimize AMD normalization backward kernel (pytorch#189405) | clean | | [release/2.13] Build rocSHMEM for the requested gfx target (#3582) | clean | | fix PicklingError handling for Python 3.14 | clean | ## Removed from this PR (per team) - [RELEASE_ONLY] skip test_autoheuristic in-code (pytorch#180927) ? not needed on 2.14. Upstream [pytorch#180927](pytorch#180927) is `RELEASE_ONLY`, merged to upstream `release/2.12` only (never on `main` or upstream `release/2.14`). ## Reviewed and excluded (team decision: not needed for 2.14) | Commit | Reason | |--------|--------| | Update composable_kernel submodule with gfx1033 support (#3499) | 2.14's CK pin already includes gfx1033; carrying would move the submodule pointer **backward**. | | Revert "Skip cudagraphs for kernel-free inductor graphs" (pytorch#187347) | 2.14 already has the fixed upstream **re-land** on top of the revert; carrying = regressing 2.14. | | Revert "[Reland] Port index_add fast path" (pytorch#188196) | 2.14 already has the newer **re-land (pytorch#189506)** on top of the revert; carrying = regressing 2.14. | ## Dropped as already in 2.14 (verified during cherry-pick) - rocm-smi deprecation (#3434) ? 2.14 already has zero `rocm_smi` refs. - Enable linalg via hipSOLVER, remove Magma (#3455) ? all 6 upstream PRs already in 2.14. - Stabilize ROCm 7.14 testing (#3525) ? 2.14 already carries the guards + skip messages. - Add gfx1250 support in GroupedBlas (#3532) ? already in 2.14 via upstream pytorch#190703 (`ScaledBlasDeviceUtils`). - Fix uninitialized embedding indices `test_embedding_meta_indices` (pytorch#188002) ? upstream already in 2.14. - Unskip ROCSHMEM triton UTs on rocm 7.14 (#3578) ? targets a 2.13-only 7.14 module skip that 2.14 never had; tests already run on 2.14. Remaining commits drop as 2.13-only (version/pins/related_commits/CD) or as already-in-2.14 by patch-id/upstream. ## Test plan - [x] TheRock full-stack dev build (torch + torchaudio + torchvision + triton) on gfx94X-dcgpu for Python 3.10-3.14, all **Build** jobs green (ROCm `10.1.0a20260822`, on the `aws-linux-scale-rocm-prod` pool), after bringing the branch up to its base so `related_commits` resolves torchaudio/torchvision: - py3.10 https://github.com/ROCm/TheRock/actions/runs/32863299013 - py3.11 https://github.com/ROCm/TheRock/actions/runs/32863305363 - py3.12 https://github.com/ROCm/TheRock/actions/runs/32863311391 - py3.13 https://github.com/ROCm/TheRock/actions/runs/32863318109 - py3.14 https://github.com/ROCm/TheRock/actions/runs/32863325370 - [x] TheRock CI wheel build on gfx94X-dcgpu for Python 3.10-3.14 all green (ROCm `10.1.0a20260822`, torch-only, on the `aws-linux-scale-rocm-prod` pool, ~1h40m each): - py3.10 https://github.com/ROCm/TheRock/actions/runs/32818564344 - py3.11 https://github.com/ROCm/TheRock/actions/runs/32818568751 - py3.12 https://github.com/ROCm/TheRock/actions/runs/32818572249 - py3.13 https://github.com/ROCm/TheRock/actions/runs/32818576288 - py3.14 https://github.com/ROCm/TheRock/actions/runs/32818580229 ## Processed Commits List Spreasheet with each commit evaluated for cherry-pick & resolution (drop/include) with reasoning: [pr3594-commit-outcomes.xlsx](https://github.com/user-attachments/files/31390971/pr3594-commit-outcomes.xlsx) --------- Signed-off-by: pablo-garay <[email protected]> Co-authored-by: Iurii Paikov <[email protected]> Co-authored-by: Chinmay Dattanand Kuchinad <[email protected]> Co-authored-by: rocm-repo-management-api-6[bot] <212817015+rocm-repo-management-api-6[bot]@users.noreply.github.com> Co-authored-by: Dmitry Nikolaev <[email protected]> Co-authored-by: srinivamd <[email protected]> Co-authored-by: Subramanian <[email protected]> Co-authored-by: zjliu-amd <[email protected]> Co-authored-by: Andres Lugo <[email protected]> Co-authored-by: pablo-garay <[email protected]> Co-authored-by: Bo Li <[email protected]> Co-authored-by: Anatoliy Litvinenko <[email protected]> Co-authored-by: Jeff Daily <[email protected]> Co-authored-by: Luca Bruni <[email protected]> Co-authored-by: albmalamd <[email protected]>
Summary:
Second reland of the
index_add -> scatter_adddelegation. This reland sits on top of D110978969 ([native] Move scatter-add N-dim to dynamic, #188820), which moves the scatter_add CuTeDSL override's compile-cache key for the inner dimension to dynamic, so a single compile serves all N sizes instead of recompiling per application (dtype and contig/non-contig still recompile). With D110978969 landed, the issue behind the most recent revert of this diff is resolved, so the delegation is re-applied here unchanged.Adopts the vectorized scatter_add(dim=0) kernel from D104346887 / PR #182675 as a fast path for
index_add_on CUDA.index_add_(0, idx, src)is mathematically equivalent toself.scatter_add_(0, idx.unsqueeze(-1).expand_as(src), src)whenalpha == 1, so we delegate so scatter_add's own TMA/vectorized eligibility check + dispatch is the single source of truth.Eligibility (all required to enter the fast path):
dim == 0alpha == 1index.dim() <= 1and contiguous,numIndex > 0Outside the eligible regime, falls through to the existing
indexFunc{Small,Large}Indexdispatch (untouched).Benchmarks
Kernel-side perf is unchanged from D104669063 (the delegation forwards to the same scatter_add kernel, now with PR #184554's smem padding). See D104669063 summary for full B200 and H100 benchmark tables. Highlights:
PR #184554's stage-stride padding is a one-extra-smem-byte change in the worst case (chunk_bytes already padded for chunk_bytes >= 128), so no measurable perf delta from the parent commit.
bypass-github-export-checks unrelated failure
Test Plan:
Re-running the original D104669063 test suite plus the new small-D + high-M_src regression added in this diff:
Expected: pass on all parametrized variants (fp32 / fp64 / half / bf16 across 3 shapes x 2 index dtypes for
test_index_add_fast_path; complex64 / complex128 / bool fortest_index_add_excluded_dtypes; fp32 / bf16 for the new regression).test_index_add_smem_stage_alignment_regressionspecifically reproduces the SEV-class shape (D=8, M_src = sm * 64 + 256 so every CTA enters stage 1) and asserts numerical equality against a CPU reference. Without PR #184554 in the same build, this test crashes withcudaErrorMisalignedAddress; with the parent commit present, it passes cleanly.No regressions in existing
index_addtests.Check that issues gone in
https://www.internalfb.com/mlhub/pipelines/runs/mast/fire-albertchen-train-f1110230424?job_attempt=1&version=0&tab=summary
https://www.internalfb.com/mlhub/pipelines/runs/mast/fire-albertchen-train-mast-UDD-2026-06-27-3d-f958b44a?job_attempt=1&version=0&tab=summary&env=PRODUCTION
https://www.internalfb.com/mlhub/pipelines/runs/mast/mvai-training-online-2115904614?version=0&env=PRODUCTION
Differential Revision: D111254885