Repository navigation
Add outer-product-decomo - #176552
Add outer-product-decomo#176552drisspg wants to merge 3 commits into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/176552
Note: Links to docs will display an error until the docs builds have been completed. ⏳ 2 Pending, 5 Unrelated FailuresAs of commit e375e41 with merge base 2bf9338 ( FLAKY - The following jobs failed but were likely due to flakiness present on trunk:
BROKEN TRUNK - The following jobs failed but were present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
UNSTABLE - The following job is marked as unstable, possibly due to flakiness on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
|
@pytorchbot merge |
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 |
This PR needs a
|
|
@drisspg That was quick, thanks for this! 👍 |
## Summary cublas sucks at fp32 outer reduction, One commit before this PR: Eager Perf: <img width="524" height="386" alt="image" src="https://github.com/user-attachments/assets/ad349a62-5fce-4bb9-8d87-3b088077d1e5" /> Compiled Perf: <img width="497" height="392" alt="image" src="https://github.com/user-attachments/assets/1f7f436d-7750-4b65-ad0d-c2c627edef0c" /> You can see grad_routed is no bueno. I wrote a small triton kernel that does a pretty naive tiled product and got near roofline. If we add this decomp: <img width="538" height="405" alt="image" src="https://github.com/user-attachments/assets/cd54591c-706d-480e-b951-df89bbb388b3" /> Reported: pytorch/torchtitan#2225 Eager: <img width="995" height="231" alt="image" src="https://github.com/user-attachments/assets/f1d33908-3372-46ad-a854-ca7af736be2e" /> Compile <img width="780" height="250" alt="image" src="https://github.com/user-attachments/assets/8c8881f9-b19a-40f3-91f2-d353e3d80071" /> cc ptrblck msaroufim eqy jerryzh168 tinglvv nWEIdia voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx ipiszy kadeng muchulee8 amjames chauhang aakhundov coconutruben jataylo [ghstack-poisoned]
|
@pytorchbot merge |
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 |
This PR needs a
|
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Merge failedReason: HTTP Error 502: Bad Gateway Details for Dev Infra teamRaised by workflow job |
|
@pytorchbot merge -i |
Merge startedYour change will be merged while ignoring the following 5 checks: trunk / linux-jammy-rocm-py3.10 / test (default, 6, 6, linux.rocm.gpu.gfx950.1), linux-aarch64 / linux-jammy-aarch64-py3.10 / test (openreg, 1, 1, lf.linux.arm64.m7g.4xlarge), linux-aarch64 / linux-jammy-aarch64-py3.10 / test (openreg, 1, 1, lf.linux.arm64.m8g.4xlarge), inductor / unit-test / inductor-test / test (inductor_cpp_wrapper, 1, 2, linux.g5.4xlarge.nvidia.gpu), inductor / inductor-cpu-test / test (cpu_inductor_torchbench, 1, 2, linux.2xlarge.amx, unstable) Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
## Summary cublas sucks at fp32 outer reduction, One commit before this PR: Eager Perf: <img width="524" height="386" alt="image" src="https://github.com/user-attachments/assets/ad349a62-5fce-4bb9-8d87-3b088077d1e5" /> Compiled Perf: <img width="497" height="392" alt="image" src="https://github.com/user-attachments/assets/1f7f436d-7750-4b65-ad0d-c2c627edef0c" /> You can see grad_routed is no bueno. I wrote a small triton kernel that does a pretty naive tiled product and got near roofline. If we add this decomp: <img width="538" height="405" alt="image" src="https://github.com/user-attachments/assets/cd54591c-706d-480e-b951-df89bbb388b3" /> Reported: pytorch/torchtitan#2225 Eager: <img width="995" height="231" alt="image" src="https://github.com/user-attachments/assets/f1d33908-3372-46ad-a854-ca7af736be2e" /> Compile <img width="780" height="250" alt="image" src="https://github.com/user-attachments/assets/8c8881f9-b19a-40f3-91f2-d353e3d80071" /> Pull Request resolved: pytorch#176552 Approved by: https://github.com/ngimel, https://github.com/eellison
### Change scatter_add was replaced by torch.bmm in #1974 due to its non determinism. However, bmm backward kernel was reported to be slow in #2225. Although @drisspg has pytorch/pytorch#176552 which greatly optimized the bmm backward time under compile, eager mode backward is still slow. Therefore we try to switch back to scatter_add with `torch.use_deterministic_algorithms(True)`, see more in https://docs.pytorch.org/docs/stable/notes/randomness.html#avoiding-nondeterministic-algorithms. We tested out the determinism part using [this test script. ](https://gist.github.com/acisseJZhong/c56dbc331d3248e488edb24894dc4565), updated [test](https://gist.github.com/acisseJZhong/562b635e6ef96d4f2ca68769dbdbad82) ### Test with topk=2 llama4 debug model(topk=2), qwen3 debug model(topk=8) ``` NCCL_NVLS_ENABLE=0 NGPU=8 ./run_train.sh --module llama4 --config llama4_debugmodel --parallelism.pipeline_parallel_degree 1 --parallelism.data_parallel_shard_degree 4 --parallelism.tensor_parallel_degree 2 --parallelism.expert_parallel_degree 2 --parallelism.expert_tensor_parallel_degree 2 --metrics.enable_wandb --training.steps 100 ``` <img width="1075" height="288" alt="image" src="https://github.com/user-attachments/assets/81e7523b-e833-4351-ad57-f5e1276807f3" /> ### Loss compare ``` NCCL_NVLS_ENABLE=0 python scripts/loss_compare.py . main --baseline-module='llama4' --baseline-config='llama4_debugmodel' --baseline-options="--parallelism.pipeline_parallel_degree 1 --parallelism.data_parallel_shard_degree 2 --parallelism.tensor_parallel_degree 2 --parallelism.expert_parallel_degree 4 --parallelism.expert_tensor_parallel_degree 1" --baseline-ngpus=4 --test-module='llama4' --test-config='llama4_debugmodel' --test-options="--parallelism.pipeline_parallel_degree 1 --parallelism.data_parallel_shard_degree 2 --parallelism.tensor_parallel_degree 2 --parallelism.expert_parallel_degree 4 --parallelism.expert_tensor_parallel_degree 1" --test-ngpus=4 --assert-equal --no-seed-checkpoint ``` Testing with llama4 debug model, scatter_add with torch deterministic mode on seems still slightly faster than torch.bmm. cc @garrett361 @chelsea0x3b @rakkit @drisspg
### Change scatter_add was replaced by torch.bmm in pytorch#1974 due to its non determinism. However, bmm backward kernel was reported to be slow in pytorch#2225. Although @drisspg has pytorch/pytorch#176552 which greatly optimized the bmm backward time under compile, eager mode backward is still slow. Therefore we try to switch back to scatter_add with `torch.use_deterministic_algorithms(True)`, see more in https://docs.pytorch.org/docs/stable/notes/randomness.html#avoiding-nondeterministic-algorithms. We tested out the determinism part using [this test script. ](https://gist.github.com/acisseJZhong/c56dbc331d3248e488edb24894dc4565), updated [test](https://gist.github.com/acisseJZhong/562b635e6ef96d4f2ca68769dbdbad82) ### Test with topk=2 llama4 debug model(topk=2), qwen3 debug model(topk=8) ``` NCCL_NVLS_ENABLE=0 NGPU=8 ./run_train.sh --module llama4 --config llama4_debugmodel --parallelism.pipeline_parallel_degree 1 --parallelism.data_parallel_shard_degree 4 --parallelism.tensor_parallel_degree 2 --parallelism.expert_parallel_degree 2 --parallelism.expert_tensor_parallel_degree 2 --metrics.enable_wandb --training.steps 100 ``` <img width="1075" height="288" alt="image" src="https://github.com/user-attachments/assets/81e7523b-e833-4351-ad57-f5e1276807f3" /> ### Loss compare ``` NCCL_NVLS_ENABLE=0 python scripts/loss_compare.py . main --baseline-module='llama4' --baseline-config='llama4_debugmodel' --baseline-options="--parallelism.pipeline_parallel_degree 1 --parallelism.data_parallel_shard_degree 2 --parallelism.tensor_parallel_degree 2 --parallelism.expert_parallel_degree 4 --parallelism.expert_tensor_parallel_degree 1" --baseline-ngpus=4 --test-module='llama4' --test-config='llama4_debugmodel' --test-options="--parallelism.pipeline_parallel_degree 1 --parallelism.data_parallel_shard_degree 2 --parallelism.tensor_parallel_degree 2 --parallelism.expert_parallel_degree 4 --parallelism.expert_tensor_parallel_degree 1" --test-ngpus=4 --assert-equal --no-seed-checkpoint ``` Testing with llama4 debug model, scatter_add with torch deterministic mode on seems still slightly faster than torch.bmm. cc @garrett361 @chelsea0x3b @rakkit @drisspg
### Change scatter_add was replaced by torch.bmm in pytorch#1974 due to its non determinism. However, bmm backward kernel was reported to be slow in pytorch#2225. Although @drisspg has pytorch/pytorch#176552 which greatly optimized the bmm backward time under compile, eager mode backward is still slow. Therefore we try to switch back to scatter_add with `torch.use_deterministic_algorithms(True)`, see more in https://docs.pytorch.org/docs/stable/notes/randomness.html#avoiding-nondeterministic-algorithms. We tested out the determinism part using [this test script. ](https://gist.github.com/acisseJZhong/c56dbc331d3248e488edb24894dc4565), updated [test](https://gist.github.com/acisseJZhong/562b635e6ef96d4f2ca68769dbdbad82) ### Test with topk=2 llama4 debug model(topk=2), qwen3 debug model(topk=8) ``` NCCL_NVLS_ENABLE=0 NGPU=8 ./run_train.sh --module llama4 --config llama4_debugmodel --parallelism.pipeline_parallel_degree 1 --parallelism.data_parallel_shard_degree 4 --parallelism.tensor_parallel_degree 2 --parallelism.expert_parallel_degree 2 --parallelism.expert_tensor_parallel_degree 2 --metrics.enable_wandb --training.steps 100 ``` <img width="1075" height="288" alt="image" src="https://github.com/user-attachments/assets/81e7523b-e833-4351-ad57-f5e1276807f3" /> ### Loss compare ``` NCCL_NVLS_ENABLE=0 python scripts/loss_compare.py . main --baseline-module='llama4' --baseline-config='llama4_debugmodel' --baseline-options="--parallelism.pipeline_parallel_degree 1 --parallelism.data_parallel_shard_degree 2 --parallelism.tensor_parallel_degree 2 --parallelism.expert_parallel_degree 4 --parallelism.expert_tensor_parallel_degree 1" --baseline-ngpus=4 --test-module='llama4' --test-config='llama4_debugmodel' --test-options="--parallelism.pipeline_parallel_degree 1 --parallelism.data_parallel_shard_degree 2 --parallelism.tensor_parallel_degree 2 --parallelism.expert_parallel_degree 4 --parallelism.expert_tensor_parallel_degree 1" --test-ngpus=4 --assert-equal --no-seed-checkpoint ``` Testing with llama4 debug model, scatter_add with torch deterministic mode on seems still slightly faster than torch.bmm. cc @garrett361 @chelsea0x3b @rakkit @drisspg
### Change scatter_add was replaced by torch.bmm in pytorch#1974 due to its non determinism. However, bmm backward kernel was reported to be slow in pytorch#2225. Although @drisspg has pytorch/pytorch#176552 which greatly optimized the bmm backward time under compile, eager mode backward is still slow. Therefore we try to switch back to scatter_add with `torch.use_deterministic_algorithms(True)`, see more in https://docs.pytorch.org/docs/stable/notes/randomness.html#avoiding-nondeterministic-algorithms. We tested out the determinism part using [this test script. ](https://gist.github.com/acisseJZhong/c56dbc331d3248e488edb24894dc4565), updated [test](https://gist.github.com/acisseJZhong/562b635e6ef96d4f2ca68769dbdbad82) ### Test with topk=2 llama4 debug model(topk=2), qwen3 debug model(topk=8) ``` NCCL_NVLS_ENABLE=0 NGPU=8 ./run_train.sh --module llama4 --config llama4_debugmodel --parallelism.pipeline_parallel_degree 1 --parallelism.data_parallel_shard_degree 4 --parallelism.tensor_parallel_degree 2 --parallelism.expert_parallel_degree 2 --parallelism.expert_tensor_parallel_degree 2 --metrics.enable_wandb --training.steps 100 ``` <img width="1075" height="288" alt="image" src="https://github.com/user-attachments/assets/81e7523b-e833-4351-ad57-f5e1276807f3" /> ### Loss compare ``` NCCL_NVLS_ENABLE=0 python scripts/loss_compare.py . main --baseline-module='llama4' --baseline-config='llama4_debugmodel' --baseline-options="--parallelism.pipeline_parallel_degree 1 --parallelism.data_parallel_shard_degree 2 --parallelism.tensor_parallel_degree 2 --parallelism.expert_parallel_degree 4 --parallelism.expert_tensor_parallel_degree 1" --baseline-ngpus=4 --test-module='llama4' --test-config='llama4_debugmodel' --test-options="--parallelism.pipeline_parallel_degree 1 --parallelism.data_parallel_shard_degree 2 --parallelism.tensor_parallel_degree 2 --parallelism.expert_parallel_degree 4 --parallelism.expert_tensor_parallel_degree 1" --test-ngpus=4 --assert-equal --no-seed-checkpoint ``` Testing with llama4 debug model, scatter_add with torch deterministic mode on seems still slightly faster than torch.bmm. cc @garrett361 @chelsea0x3b @rakkit @drisspg
Stack from ghstack (oldest at bottom):
Summary
cublas sucks at fp32 outer reduction,
One commit before this PR:

Eager Perf:
Compiled Perf:

You can see grad_routed is no bueno. I wrote a small triton kernel that does a pretty naive tiled product and got near roofline.
If we add this decomp:
Reported: pytorch/torchtitan#2225
Eager:

Compile

cc @ptrblck @msaroufim @eqy @jerryzh168 @tinglvv @nWEIdia @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo @mlazos