Skip to content

support AMP for DDP / single-device training - #1303

Merged
tianyu-l merged 1 commit into
mainfrom
amp
Jun 16, 2025
Merged

tianyu-l merged 1 commit into
mainfrom
amp

Conversation

@tianyu-l

Copy link
Copy Markdown
Contributor

There have been several requests / questions / attempts around this feature. See

Hence this PR, even though AMP does not provide full support when fully_shard is not used.
My local testing shows:

  • under TP, with AMP the throughput drops.
  • under PP, there is not a way to wrap the forward pass only @H-Huang ; if the forward+backward is wrapped, the program hangs.
  • It works fine under DDP / single-device training.

This PR also adds logging on if mixed precision is enabled, and if so under what mechanism, fully_shard or AMP.

@tianyu-l
tianyu-l requested review from fegin and wwwjn as code owners June 16, 2025 02:13
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jun 16, 2025
@tianyu-l tianyu-l linked an issue Jun 16, 2025 that may be closed by this pull request
@fegin

fegin commented Jun 16, 2025

Copy link
Copy Markdown
Contributor

Just want to note that AMP + DDP could be slow. We may want to add warnings.

@fegin fegin left a comment

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.

LGTM

Comment thread torchtitan/distributed/utils.py Outdated
def maybe_enable_amp(
parallel_dims: ParallelDims, mixed_precision_param: str, device_type: torch.device
) -> Generator[None, None, None]:
fsdp_enabled = parallel_dims.dp_shard_enabled or parallel_dims.cp_enabled

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.

Can we make this a property of ParallelDims? It seems that this is pretty commonly used.

@tianyu-l

Copy link
Copy Markdown
Contributor Author

Just want to note that AMP + DDP could be slow. We may want to add warnings.

@fegin
On 8 GPUs debug model under DDP, the throughput doubles with AMP. This is similar speedup to single-device training.

without amp
image

with amp
image

@fegin

fegin commented Jun 16, 2025

Copy link
Copy Markdown
Contributor

Oh, I meant slow if it is compared to FSDP's mixed precision.

@tianyu-l
tianyu-l merged commit 0b44d4c into main Jun 16, 2025
@tianyu-l
tianyu-l deleted the amp branch June 16, 2025 20:18
H-Huang pushed a commit to H-Huang/torchtitan that referenced this pull request Jun 26, 2025
There have been several requests / questions / attempts around this
feature. See
- pytorch#630
- pytorch#700
- pytorch#1278
- pytorch#1293

Hence this PR, even though AMP does not provide full support when
`fully_shard` is not used.
My local testing shows:
- under TP, with AMP the throughput drops.
- under PP, there is not a way to wrap the forward pass only @H-Huang ;
if the forward+backward is wrapped, the program hangs.
- It works fine under DDP / single-device training.

This PR also adds logging on if mixed precision is enabled, and if so
under what mechanism, `fully_shard` or AMP.
wwwjn pushed a commit that referenced this pull request Jul 1, 2025
There have been several requests / questions / attempts around this
feature. See
- #630
- #700
- #1278
- #1293

Hence this PR, even though AMP does not provide full support when
`fully_shard` is not used.
My local testing shows:
- under TP, with AMP the throughput drops.
- under PP, there is not a way to wrap the forward pass only @H-Huang ;
if the forward+backward is wrapped, the program hangs.
- It works fine under DDP / single-device training.

This PR also adds logging on if mixed precision is enabled, and if so
under what mechanism, `fully_shard` or AMP.
xrsrke pushed a commit to NousResearch/torchtitan that referenced this pull request Feb 13, 2026
There have been several requests / questions / attempts around this
feature. See
- pytorch#630
- pytorch#700
- pytorch#1278
- pytorch#1293

Hence this PR, even though AMP does not provide full support when
`fully_shard` is not used.
My local testing shows:
- under TP, with AMP the throughput drops.
- under PP, there is not a way to wrap the forward pass only @H-Huang ;
if the forward+backward is wrapped, the program hangs.
- It works fine under DDP / single-device training.

This PR also adds logging on if mixed precision is enabled, and if so
under what mechanism, `fully_shard` or AMP.
xrsrke pushed a commit to NousResearch/torchtitan that referenced this pull request Feb 25, 2026
There have been several requests / questions / attempts around this
feature. See
- pytorch#630
- pytorch#700
- pytorch#1278
- pytorch#1293

Hence this PR, even though AMP does not provide full support when
`fully_shard` is not used.
My local testing shows:
- under TP, with AMP the throughput drops.
- under PP, there is not a way to wrap the forward pass only @H-Huang ;
if the forward+backward is wrapped, the program hangs.
- It works fine under DDP / single-device training.

This PR also adds logging on if mixed precision is enabled, and if so
under what mechanism, `fully_shard` or AMP.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Non-DP runs default to float32 precision

3 participants