Skip to content

[fsdp2][mp] per-param mixed_precision policy - #196576

Closed
anshul-si wants to merge 1 commit into
gh/anshul-si/140/basefrom
gh/anshul-si/140/head
Closed

anshul-si wants to merge 1 commit into
gh/anshul-si/140/basefrom
gh/anshul-si/140/head

Conversation

@anshul-si

@anshul-si anshul-si commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 2 New Failures

As of commit 7ea6b1c with merge base 3d6eb40 (image):

NEW FAILURES - The following jobs have failed:

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

@pytorch-bot pytorch-bot Bot added ciflow/inductor ciflow/torchtitan Run TorchTitan integration tests release notes: distributed (fsdp) release notes category labels Sep 10, 2026
anshul-si added a commit that referenced this pull request Sep 10, 2026
anshul-si added a commit that referenced this pull request Sep 10, 2026
ghstack-source-id: 5de48e6
Pull-Request: #196576

ghstack-source-id: 5de48e6
Pull Request resolved: #196626
anshul-si added a commit that referenced this pull request Sep 10, 2026
anshul-si added a commit that referenced this pull request Sep 10, 2026
ghstack-source-id: 21e38a7
Pull-Request: #196576

ghstack-source-id: 21e38a7
Pull Request resolved: #196626
anshul-si added a commit that referenced this pull request Sep 11, 2026
**Summary:** We want to enable per-param mixed precision policy in FSDP2 for several reasons including KDA, etc. 

**Key Points**
All-gather: During all-gather, existing homogenous path remains unchanged. When parameters require different compute dtypes, FSDP groups staging copies by source/target dtype and invokes the existing uint8 communication buffer, keeping only one AG per fully_shard. 

Reduce-scatter: Parameters using different compute_dtypes inevitably results in gradients with different dtypes, but a reduce-scatter input buffer must have a single dtype. When all parameters share reduce_dtype, we want FSDP to preserve existing single-collective behavior. To support this efficiently, the existing _chunk_cat.out CUDA path was extended to read heterogeneous BF16/FP32 inputs and cast them directly into the reduction buffer while performing chunking and padding. Without this fused path, FSDP would need to materialize full-size tensors in the reduction dtype and then run the ordinary homogeneous packing kernel, adding another read/write pass and substantial temporary memory. The existing operator schema and homogeneous kernels remain intact. If parameters request genuinely different reduction dtypes, FSDP instead creates one bucket and one reduce-scatter per effective dtype.

Benchmarking: We first isolated reduce-scatter packing on an H100 using a transformer-like workload containing 50.3 million elements and small FP32 islands. Fused mixed BF16/FP32-to-FP32 packing took 0.1888 ms, compared with 0.3582 ms for pre-casting into FP32 staging tensors followed by homogeneous packing, reducing packing latency by approximately 47% while avoiding roughly 192 MiB of temporary FP32 storage. We then measured all-gather using real FSDP parameter objects and a KDA-style layout containing FP32 decay parameters, normalization weights, and a router gate. Across grouped and approximately 500-parameter layouts, raw packing was approximately 8.7–8.8%
slower, complete copy-in was approximately 2.4–2.5% slower, and copy-out was unchanged. Finally, we ran an eight-block, 1.75-billion-parameter KDA-style model through real FSDP2 forward and backward passes, including per-block unsharding, resharding, NCCL collectives, and gradient reduction. Across both benchmark orderings, total all-gather copy-in was 4.2–4.9% slower, copy-out varied from −0.6% to +0.3%, and synchronized forward-plus-backward time remained approximately 53 ms for both configurations, showing no measurable end-to-end regression.
 

Pull-Request: #196576

[ghstack-poisoned]
anshul-si added a commit that referenced this pull request Sep 11, 2026
ghstack-source-id: 1a4b41a
Pull-Request: #196576

ghstack-source-id: 1a4b41a
Pull Request resolved: #196626
anshul-si added a commit that referenced this pull request Sep 11, 2026
**Summary:** We want to enable per-param mixed precision policy in FSDP2 for several reasons including KDA, etc. 

**Key Points**
All-gather: During all-gather, existing homogenous path remains unchanged. When parameters require different compute dtypes, FSDP groups staging copies by source/target dtype and invokes the existing uint8 communication buffer, keeping only one AG per fully_shard. As seen in benchmarking results below, there is a small perf difference in the copy-in which can be attributed to foreach_copy uses a fixed four elements per thread, so for uint8 vs bf16, we have twice as much element-level scheduling and instruction work to transfer the same number of bytes. 

Reduce-scatter: Parameters using different compute_dtypes inevitably results in gradients with different dtypes, but a reduce-scatter input buffer must have a single dtype. When all parameters share reduce_dtype, we want FSDP to preserve existing single-collective behavior. To support this efficiently, the existing _chunk_cat.out CUDA path was extended to read heterogeneous BF16/FP32 inputs and cast them directly into the reduction buffer while performing chunking and padding. Without this fused path, FSDP would need to materialize full-size tensors in the reduction dtype and then run the ordinary homogeneous packing kernel, adding another read/write pass and substantial temporary memory. The existing operator schema and homogeneous kernels remain intact. If parameters request genuinely different reduction dtypes, FSDP instead creates one bucket and one reduce-scatter per effective dtype.

Benchmarking: We first isolated reduce-scatter packing on an H100 using a transformer-like workload containing 50.3 million elements and small FP32 islands. Fused mixed BF16/FP32-to-FP32 packing took 0.1888 ms, compared with 0.3582 ms for pre-casting into FP32 staging tensors followed by homogeneous packing, reducing packing latency by approximately 47% while avoiding roughly 192 MiB of temporary FP32 storage. We then measured all-gather using real FSDP parameter objects and a KDA-style layout containing FP32 decay parameters, normalization weights, and a router gate. Across grouped and approximately 500-parameter layouts, raw packing was approximately 8.7–8.8%
slower, complete copy-in was approximately 2.4–2.5% slower, and copy-out was unchanged. Finally, we ran an eight-block, 1.75-billion-parameter KDA-style model through real FSDP2 forward and backward passes, including per-block unsharding, resharding, NCCL collectives, and gradient reduction. Across both benchmark orderings, total all-gather copy-in was 4.2–4.9% slower, copy-out varied from −0.6% to +0.3%, and synchronized forward-plus-backward time remained approximately 53 ms for both configurations, showing no measurable end-to-end regression.
 

Pull-Request: #196576

[ghstack-poisoned]
anshul-si added a commit that referenced this pull request Sep 11, 2026
ghstack-source-id: 83f5ab2
Pull-Request: #196576

ghstack-source-id: 83f5ab2
Pull Request resolved: #196626
anshul-si added a commit that referenced this pull request Sep 11, 2026
**Summary:** We want to enable per-param mixed precision policy in FSDP2 for several reasons including KDA, etc. 

**Key Points**
All-gather: During all-gather, existing homogenous path remains unchanged. When parameters require different compute dtypes, FSDP groups staging copies by source/target dtype and invokes the existing uint8 communication buffer, keeping only one AG per fully_shard. As seen in benchmarking results below, there is a small perf difference in the copy-in which can be attributed to foreach_copy uses a fixed four elements per thread, so for uint8 vs bf16, we have twice as much element-level scheduling and instruction work to transfer the same number of bytes. 

Reduce-scatter: Parameters using different compute_dtypes inevitably results in gradients with different dtypes, but a reduce-scatter input buffer must have a single dtype. When all parameters share reduce_dtype, we want FSDP to preserve existing single-collective behavior. To support this efficiently, the existing _chunk_cat.out CUDA path was extended to read heterogeneous BF16/FP32 inputs and cast them directly into the reduction buffer while performing chunking and padding. Without this fused path, FSDP would need to materialize full-size tensors in the reduction dtype and then run the ordinary homogeneous packing kernel, adding another read/write pass and substantial temporary memory. The existing operator schema and homogeneous kernels remain intact. If parameters request genuinely different reduction dtypes, FSDP instead creates one bucket and one reduce-scatter per effective dtype.

Benchmarking: We first isolated reduce-scatter packing on an H100 using a transformer-like workload containing 50.3 million elements and small FP32 islands. Fused mixed BF16/FP32-to-FP32 packing took 0.1888 ms, compared with 0.3582 ms for pre-casting into FP32 staging tensors followed by homogeneous packing, reducing packing latency by approximately 47% while avoiding roughly 192 MiB of temporary FP32 storage. We then measured all-gather using real FSDP parameter objects and a KDA-style layout containing FP32 decay parameters, normalization weights, and a router gate. Across grouped and approximately 500-parameter layouts, raw packing was approximately 8.7–8.8%
slower, complete copy-in was approximately 2.4–2.5% slower, and copy-out was unchanged. Finally, we ran an eight-block, 1.75-billion-parameter KDA-style model through real FSDP2 forward and backward passes, including per-block unsharding, resharding, NCCL collectives, and gradient reduction. Across both benchmark orderings, total all-gather copy-in was 4.2–4.9% slower, copy-out varied from −0.6% to +0.3%, and synchronized forward-plus-backward time remained approximately 53 ms for both configurations, showing no measurable end-to-end regression.
 

Pull-Request: #196576

[ghstack-poisoned]
@anshul-si anshul-si closed this Sep 14, 2026
anshul-si added a commit that referenced this pull request Sep 16, 2026
**Summary:** We want to enable per-param mixed precision policy in FSDP2 for several reasons including KDA, etc. 

**Key Points**
All-gather: During all-gather, existing homogenous path remains unchanged. When parameters require different compute dtypes, FSDP groups staging copies by source/target dtype and invokes the existing uint8 communication buffer, keeping only one AG per fully_shard. As seen in benchmarking results below, there is a small perf difference in the copy-in which can be attributed to foreach_copy uses a fixed four elements per thread, so for uint8 vs bf16, we have twice as much element-level scheduling and instruction work to transfer the same number of bytes. 

Reduce-scatter: Parameters using different compute_dtypes inevitably results in gradients with different dtypes, but a reduce-scatter input buffer must have a single dtype. When all parameters share reduce_dtype, we want FSDP to preserve existing single-collective behavior. To support this efficiently, the existing _chunk_cat.out CUDA path was extended to read heterogeneous BF16/FP32 inputs and cast them directly into the reduction buffer while performing chunking and padding. Without this fused path, FSDP would need to materialize full-size tensors in the reduction dtype and then run the ordinary homogeneous packing kernel, adding another read/write pass and substantial temporary memory. The existing operator schema and homogeneous kernels remain intact. If parameters request genuinely different reduction dtypes, FSDP instead creates one bucket and one reduce-scatter per effective dtype.

Benchmarking: We first isolated reduce-scatter packing on an H100 using a transformer-like workload containing 50.3 million elements and small FP32 islands. Fused mixed BF16/FP32-to-FP32 packing took 0.1888 ms, compared with 0.3582 ms for pre-casting into FP32 staging tensors followed by homogeneous packing, reducing packing latency by approximately 47% while avoiding roughly 192 MiB of temporary FP32 storage. We then measured all-gather using real FSDP parameter objects and a KDA-style layout containing FP32 decay parameters, normalization weights, and a router gate. Across grouped and approximately 500-parameter layouts, raw packing was approximately 8.7–8.8%
slower, complete copy-in was approximately 2.4–2.5% slower, and copy-out was unchanged. Finally, we ran an eight-block, 1.75-billion-parameter KDA-style model through real FSDP2 forward and backward passes, including per-block unsharding, resharding, NCCL collectives, and gradient reduction. Across both benchmark orderings, total all-gather copy-in was 4.2–4.9% slower, copy-out varied from −0.6% to +0.3%, and synchronized forward-plus-backward time remained approximately 53 ms for both configurations, showing no measurable end-to-end regression.
 

Pull-Request: #196576

[ghstack-poisoned]
anshul-si added a commit that referenced this pull request Sep 16, 2026
**Summary:** We want to enable per-param mixed precision policy in FSDP2 for several reasons including KDA, etc. 

**Key Points**
All-gather: During all-gather, existing homogenous path remains unchanged. When parameters require different compute dtypes, FSDP groups staging copies by source/target dtype and invokes the existing uint8 communication buffer, keeping only one AG per fully_shard. As seen in benchmarking results below, there is a small perf difference in the copy-in which can be attributed to foreach_copy uses a fixed four elements per thread, so for uint8 vs bf16, we have twice as much element-level scheduling and instruction work to transfer the same number of bytes. 

Reduce-scatter: Parameters using different compute_dtypes inevitably results in gradients with different dtypes, but a reduce-scatter input buffer must have a single dtype. When all parameters share reduce_dtype, we want FSDP to preserve existing single-collective behavior. To support this efficiently, the existing _chunk_cat.out CUDA path was extended to read heterogeneous BF16/FP32 inputs and cast them directly into the reduction buffer while performing chunking and padding. Without this fused path, FSDP would need to materialize full-size tensors in the reduction dtype and then run the ordinary homogeneous packing kernel, adding another read/write pass and substantial temporary memory. The existing operator schema and homogeneous kernels remain intact. If parameters request genuinely different reduction dtypes, FSDP instead creates one bucket and one reduce-scatter per effective dtype.

Benchmarking: We first isolated reduce-scatter packing on an H100 using a transformer-like workload containing 50.3 million elements and small FP32 islands. Fused mixed BF16/FP32-to-FP32 packing took 0.1888 ms, compared with 0.3582 ms for pre-casting into FP32 staging tensors followed by homogeneous packing, reducing packing latency by approximately 47% while avoiding roughly 192 MiB of temporary FP32 storage. We then measured all-gather using real FSDP parameter objects and a KDA-style layout containing FP32 decay parameters, normalization weights, and a router gate. Across grouped and approximately 500-parameter layouts, raw packing was approximately 8.7–8.8%
slower, complete copy-in was approximately 2.4–2.5% slower, and copy-out was unchanged. Finally, we ran an eight-block, 1.75-billion-parameter KDA-style model through real FSDP2 forward and backward passes, including per-block unsharding, resharding, NCCL collectives, and gradient reduction. Across both benchmark orderings, total all-gather copy-in was 4.2–4.9% slower, copy-out varied from −0.6% to +0.3%, and synchronized forward-plus-backward time remained approximately 53 ms for both configurations, showing no measurable end-to-end regression.
 

Pull-Request: #196576

[ghstack-poisoned]
anshul-si added a commit that referenced this pull request Sep 16, 2026
ghstack-source-id: c072705
Pull-Request: #196576

ghstack-source-id: c072705
Pull Request resolved: #196626
pytorchmergebot pushed a commit that referenced this pull request Oct 3, 2026
**Summary:** We want to enable per-param mixed precision policy in FSDP2 for several reasons including KDA, etc.

**Key Points**
All-gather: During all-gather, existing homogenous path remains unchanged. When parameters require different compute dtypes, FSDP groups staging copies by source/target dtype and invokes the existing uint8 communication buffer, keeping only one AG per fully_shard. As seen in benchmarking results below, there is a small perf difference in the copy-in which can be attributed to foreach_copy uses a fixed four elements per thread, so for uint8 vs bf16, we have twice as much element-level scheduling and instruction work to transfer the same number of bytes.

Reduce-scatter: Parameters using different compute_dtypes inevitably results in gradients with different dtypes, but a reduce-scatter input buffer must have a single dtype. When all parameters share reduce_dtype, we want FSDP to preserve existing single-collective behavior. To support this efficiently, the existing _chunk_cat.out CUDA path was extended to read heterogeneous BF16/FP32 inputs and cast them directly into the reduction buffer while performing chunking and padding. Without this fused path, FSDP would need to materialize full-size tensors in the reduction dtype and then run the ordinary homogeneous packing kernel, adding another read/write pass and substantial temporary memory. The existing operator schema and homogeneous kernels remain intact. If parameters request genuinely different reduction dtypes, FSDP instead creates one bucket and one reduce-scatter per effective dtype.

Benchmarking: We first isolated reduce-scatter packing on an H100 using a transformer-like workload containing 50.3 million elements and small FP32 islands. Fused mixed BF16/FP32-to-FP32 packing took 0.1888 ms, compared with 0.3582 ms for pre-casting into FP32 staging tensors followed by homogeneous packing, reducing packing latency by approximately 47% while avoiding roughly 192 MiB of temporary FP32 storage. We then measured all-gather using real FSDP parameter objects and a KDA-style layout containing FP32 decay parameters, normalization weights, and a router gate. Across grouped and approximately 500-parameter layouts, raw packing was approximately 8.7–8.8%
slower, complete copy-in was approximately 2.4–2.5% slower, and copy-out was unchanged. Finally, we ran an eight-block, 1.75-billion-parameter KDA-style model through real FSDP2 forward and backward passes, including per-block unsharding, resharding, NCCL collectives, and gradient reduction. Across both benchmark orderings, total all-gather copy-in was 4.2–4.9% slower, copy-out varied from −0.6% to +0.3%, and synchronized forward-plus-backward time remained approximately 53 ms for both configurations, showing no measurable end-to-end regression.

Pull-Request: #196576
Pull Request resolved: #196626
Approved by: https://github.com/weifengpy
cyyever pushed a commit to BakeLab/pytorch that referenced this pull request Oct 11, 2026
**Summary:** We want to enable per-param mixed precision policy in FSDP2 for several reasons including KDA, etc.

**Key Points**
All-gather: During all-gather, existing homogenous path remains unchanged. When parameters require different compute dtypes, FSDP groups staging copies by source/target dtype and invokes the existing uint8 communication buffer, keeping only one AG per fully_shard. As seen in benchmarking results below, there is a small perf difference in the copy-in which can be attributed to foreach_copy uses a fixed four elements per thread, so for uint8 vs bf16, we have twice as much element-level scheduling and instruction work to transfer the same number of bytes.

Reduce-scatter: Parameters using different compute_dtypes inevitably results in gradients with different dtypes, but a reduce-scatter input buffer must have a single dtype. When all parameters share reduce_dtype, we want FSDP to preserve existing single-collective behavior. To support this efficiently, the existing _chunk_cat.out CUDA path was extended to read heterogeneous BF16/FP32 inputs and cast them directly into the reduction buffer while performing chunking and padding. Without this fused path, FSDP would need to materialize full-size tensors in the reduction dtype and then run the ordinary homogeneous packing kernel, adding another read/write pass and substantial temporary memory. The existing operator schema and homogeneous kernels remain intact. If parameters request genuinely different reduction dtypes, FSDP instead creates one bucket and one reduce-scatter per effective dtype.

Benchmarking: We first isolated reduce-scatter packing on an H100 using a transformer-like workload containing 50.3 million elements and small FP32 islands. Fused mixed BF16/FP32-to-FP32 packing took 0.1888 ms, compared with 0.3582 ms for pre-casting into FP32 staging tensors followed by homogeneous packing, reducing packing latency by approximately 47% while avoiding roughly 192 MiB of temporary FP32 storage. We then measured all-gather using real FSDP parameter objects and a KDA-style layout containing FP32 decay parameters, normalization weights, and a router gate. Across grouped and approximately 500-parameter layouts, raw packing was approximately 8.7–8.8%
slower, complete copy-in was approximately 2.4–2.5% slower, and copy-out was unchanged. Finally, we ran an eight-block, 1.75-billion-parameter KDA-style model through real FSDP2 forward and backward passes, including per-block unsharding, resharding, NCCL collectives, and gradient reduction. Across both benchmark orderings, total all-gather copy-in was 4.2–4.9% slower, copy-out varied from −0.6% to +0.3%, and synchronized forward-plus-backward time remained approximately 53 ms for both configurations, showing no measurable end-to-end regression.

Pull-Request: pytorch#196576
Pull Request resolved: pytorch#196626
Approved by: https://github.com/weifengpy
@github-actions
github-actions Bot deleted the gh/anshul-si/140/head branch November 17, 2026 01:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/inductor ciflow/torchtitan Run TorchTitan integration tests release notes: distributed (fsdp) release notes category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant