Repository navigation
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/180428
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: ✅ You can merge normally! (14 Unrelated Failures)As of commit 773254b with merge base 12c7b75 ( FLAKY - The following jobs failed but were likely due to flakiness present on trunk:
BROKEN TRUNK - The following job 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. |
We have `fully_shard([norm, head])` in torchtitan. Without chunked loss, norm and head execute together — FSDP2 uses `_modules_to_run` to unshard once before norm and reshard once after head. With chunked loss, the model forward runs norm but skips head. Then head is called standalone per chunk. It's wrong to depend on `_modules_to_run` to trigger unshard/reshard. Three changes: 1. Trigger unshard based on `is_unsharded`, regardless of `_modules_to_run`. `modules_to_run` is only used by the post-hook for reshard. 2. Root post-forward cleanup — force reshard and register backward hooks for incomplete `_modules_to_run_forward`. 3. Clear stale `iter_forward_root` in post-backward — `model.head(chunk)` claims forward root but never clears it because the group's `_post_forward` doesn't fire. Without this, iteration 2+ skips root init. ghstack-source-id: 98b413f Pull-Request: #180428
We have `fully_shard([norm, head])` in torchtitan. Without chunked loss, norm and head execute together — FSDP2 uses `_modules_to_run` to unshard once before norm and reshard once after head. With chunked loss, the model forward runs norm but skips head. Then head is called standalone per chunk. It's wrong to depend on `_modules_to_run` to trigger unshard/reshard. Three changes: 1. Trigger unshard based on `is_unsharded`, regardless of `_modules_to_run`. `modules_to_run` is only used by the post-hook for reshard. 2. Root post-forward cleanup — force reshard and register backward hooks for incomplete `_modules_to_run_forward`. 3. Clear stale `iter_forward_root` in post-backward — `model.head(chunk)` claims forward root but never clears it because the group's `_post_forward` doesn't fire. Without this, iteration 2+ skips root init. ghstack-source-id: d2eb4b8 Pull-Request: #180428
We have `fully_shard([norm, head])` in torchtitan. Without chunked loss, norm and head execute together — FSDP2 uses `_modules_to_run` to unshard once before norm and reshard once after head. With chunked loss, the model forward runs norm but skips head. Then head is called standalone per chunk. It's wrong to depend on `_modules_to_run` to trigger unshard/reshard. Three changes: 1. Trigger unshard based on `is_unsharded`, regardless of `_modules_to_run`. `modules_to_run` is only used by the post-hook for reshard. 2. Root post-forward cleanup — force reshard and register backward hooks for incomplete `_modules_to_run_forward`. 3. Clear stale `iter_forward_root` in post-backward — `model.head(chunk)` claims forward root but never clears it because the group's `_post_forward` doesn't fire. Without this, iteration 2+ skips root init. ghstack-source-id: 5ace01f Pull-Request: #180428
We have `fully_shard([norm, head])` in torchtitan. Without chunked loss, norm and head execute together — FSDP2 uses `_modules_to_run` to unshard once before norm and reshard once after head. With chunked loss, the model forward runs norm but skips head. Then head is called standalone per chunk. It's wrong to depend on `_modules_to_run` to trigger unshard/reshard. Three changes: 1. Trigger unshard based on `is_unsharded`, regardless of `_modules_to_run`. `modules_to_run` is only used by the post-hook for reshard. 2. Root post-forward cleanup — force reshard and register backward hooks for incomplete `_modules_to_run_forward`. 3. Clear stale `iter_forward_root` in post-backward — `model.head(chunk)` claims forward root but never clears it because the group's `_post_forward` doesn't fire. Without this, iteration 2+ skips root init. ghstack-source-id: 951552b Pull-Request: #180428
We have `fully_shard([norm, head])` in torchtitan. Without chunked loss, norm and head execute together — FSDP2 uses `_modules_to_run` to unshard once before norm and reshard once after head. With chunked loss, the model forward runs norm but skips head. Then head is called standalone per chunk. It's wrong to depend on `_modules_to_run` to trigger unshard/reshard. Three changes: 1. Trigger unshard based on `is_unsharded`, regardless of `_modules_to_run`. `modules_to_run` is only used by the post-hook for reshard. 2. Root post-forward cleanup — force reshard and register backward hooks for incomplete `_modules_to_run_forward`. Extracted into `_force_complete_incomplete_states` helper. 3. Clear stale `iter_forward_root` in post-backward — `model.head(chunk)` claims forward root but never clears it because the group's `_post_forward` doesn't fire. Without this, iteration 2+ skips root init. Cleared unconditionally (not gated on `is_last_backward`) so gradient-accumulation between micro-batches also recovers. 4. (Latent bug fix) `cast_forward_inputs` now applies to every module in a group. Previously the group pre-hook only fired on the first module, so non-first modules in `fully_shard([...])` skipped input mp_policy casting. Co-authored-by: Claude <[email protected]> ghstack-source-id: 9bd832f Pull-Request: #180428
We have `fully_shard([norm, head])` in torchtitan. Without chunked loss, norm and head execute together — FSDP2 uses `_modules_to_run` to unshard once before norm and reshard once after head. With chunked loss, the model forward runs norm but skips head. Then head is called standalone per chunk. It's wrong to depend on `_modules_to_run` to trigger unshard/reshard. Three changes: 1. Trigger unshard based on `is_unsharded`, regardless of `_modules_to_run`. `modules_to_run` is only used by the post-hook for reshard. 2. Root post-forward cleanup — force reshard and register backward hooks for incomplete `_modules_to_run_forward`. Extracted into `_force_complete_incomplete_states` helper. 3. Clear stale `iter_forward_root` in post-backward — `model.head(chunk)` claims forward root but never clears it because the group's `_post_forward` doesn't fire. Without this, iteration 2+ skips root init. Cleared unconditionally (not gated on `is_last_backward`) so gradient-accumulation between micro-batches also recovers. 4. (Latent bug fix) `cast_forward_inputs` now applies to every module in a group. Previously the group pre-hook only fired on the first module, so non-first modules in `fully_shard([...])` skipped input mp_policy casting. Co-authored-by: Claude <[email protected]> ghstack-source-id: b7f1bf4 Pull-Request: #180428
We have `fully_shard([norm, head])` in torchtitan. Without chunked loss, norm and head execute together — FSDP2 uses `_modules_to_run` to unshard once before norm and reshard once after head. With chunked loss, the model forward runs norm but skips head. Then head is called standalone per chunk. It's wrong to depend on `_modules_to_run` to trigger unshard/reshard. Changes: 1. Trigger unshard based on `is_unsharded`, regardless of `_modules_to_run`. `modules_to_run` is only used by the post-hook for reshard. 2. Root post-forward cleanup — force reshard, register backward hooks, and apply the inner state's ``mp_policy.output_dtype`` cast for any incomplete `_modules_to_run_forward`. Extracted into `_force_complete_incomplete_states` helper (decorated `@_dynamo_disable`). 3. Clear stale `iter_forward_root` in post-backward — `model.head(chunk)` claims forward root but never clears it because the group's `_post_forward` doesn't fire. Without this, iteration 2+ skips root init. Cleared unconditionally (not gated on `is_last_backward`) so gradient-accumulation between micro-batches also recovers. 4. (Latent bug fix) `cast_forward_inputs` now applies to every module in a group. Previously the group pre-hook only fired on the first module, so non-first modules in `fully_shard([...])` skipped input mp_policy casting. 5. Gate state-level one-shot work (``_root_pre_forward`` and ``_states_to_forward_prefetch``) on ``state_first_in_pass`` so per-module pre-hook firing (needed for #4) doesn't multiply forward-prefetch cost by group size. ``cast_forward_inputs`` and ``fsdp_param_group.pre_forward`` still fire per module as intended. Co-authored-by: Claude <[email protected]> ghstack-source-id: 592276e Pull-Request: #180428
We have `fully_shard([norm, head])` in torchtitan. Without chunked loss, norm and head execute together — FSDP2 uses `_modules_to_run` to unshard once before norm and reshard once after head. With chunked loss, the model forward runs norm but skips head. Then head is called standalone per chunk. It's wrong to depend on `_modules_to_run` to trigger unshard/reshard. Changes: 1. Trigger unshard based on `is_unsharded`, regardless of `_modules_to_run`. `modules_to_run` is only used by the post-hook for reshard. 2. Root post-forward cleanup — force reshard, register backward hooks, and apply the inner state's ``mp_policy.output_dtype`` cast for any incomplete `_modules_to_run_forward`. Extracted into `_force_complete_incomplete_states` helper (decorated `@_dynamo_disable`). 3. Clear stale `iter_forward_root` in post-backward — `model.head(chunk)` claims forward root but never clears it because the group's `_post_forward` doesn't fire. Without this, iteration 2+ skips root init. Cleared unconditionally (not gated on `is_last_backward`) so gradient-accumulation between micro-batches also recovers. 4. (Latent bug fix) `cast_forward_inputs` now applies to every module in a group. Previously the group pre-hook only fired on the first module, so non-first modules in `fully_shard([...])` skipped input mp_policy casting. 5. Gate state-level one-shot work (``_root_pre_forward`` and ``_states_to_forward_prefetch``) on ``state_first_in_pass`` so per-module pre-hook firing (needed for #4) doesn't multiply forward-prefetch cost by group size. ``cast_forward_inputs`` and ``fsdp_param_group.pre_forward`` still fire per module as intended. Co-authored-by: Claude <[email protected]> ghstack-source-id: 551b104 Pull-Request: #180428
We have `fully_shard([norm, head])` in torchtitan. Without chunked loss, norm and head execute together — FSDP2 uses `_modules_to_run` to unshard once before norm and reshard once after head. With chunked loss, the model forward runs norm but skips head. Then head is called standalone per chunk. It's wrong to depend on `_modules_to_run` to trigger unshard/reshard. Changes: 1. Trigger unshard based on `is_unsharded`, regardless of `_modules_to_run`. `modules_to_run` is only used by the post-hook for reshard. 2. Root post-forward cleanup — force reshard, register backward hooks, and apply the inner state's ``mp_policy.output_dtype`` cast for any incomplete `_modules_to_run_forward`. Extracted into `_force_complete_incomplete_states` helper (decorated `@_dynamo_disable`). 3. Clear stale `iter_forward_root` in post-backward — `model.head(chunk)` claims forward root but never clears it because the group's `_post_forward` doesn't fire. Without this, iteration 2+ skips root init. Cleared unconditionally (not gated on `is_last_backward`) so gradient-accumulation between micro-batches also recovers. 4. (Latent bug fix) `cast_forward_inputs` now applies to every module in a group. Previously the group pre-hook only fired on the first module, so non-first modules in `fully_shard([...])` skipped input mp_policy casting. 5. Gate state-level one-shot work (``_root_pre_forward`` and ``_states_to_forward_prefetch``) on ``state_first_in_pass`` so per-module pre-hook firing (needed for #4) doesn't multiply forward-prefetch cost by group size. ``cast_forward_inputs`` and ``fsdp_param_group.pre_forward`` still fire per module as intended. Co-authored-by: Claude <[email protected]> ghstack-source-id: 7222048 Pull-Request: #180428
We have `fully_shard([norm, head])` in torchtitan. Without chunked loss, norm and head execute together — FSDP2 uses `_modules_to_run` to unshard once before norm and reshard once after head. With chunked loss, the model forward runs norm but skips head. Then head is called standalone per chunk. It's wrong to depend on `_modules_to_run` to trigger unshard/reshard. Changes: 1. Trigger unshard based on `is_unsharded`, regardless of `_modules_to_run`. `modules_to_run` is only used by the post-hook for reshard. 2. Root post-forward cleanup — force reshard, register backward hooks, and apply the inner state's ``mp_policy.output_dtype`` cast for any incomplete `_modules_to_run_forward`. Extracted into `_force_complete_incomplete_states` helper (decorated `@_dynamo_disable`). 3. Clear stale `iter_forward_root` in post-backward — `model.head(chunk)` claims forward root but never clears it because the group's `_post_forward` doesn't fire. Without this, iteration 2+ skips root init. Cleared unconditionally (not gated on `is_last_backward`) so gradient-accumulation between micro-batches also recovers. 4. (Latent bug fix) `cast_forward_inputs` now applies to every module in a group. Previously the group pre-hook only fired on the first module, so non-first modules in `fully_shard([...])` skipped input mp_policy casting. 5. Gate state-level one-shot work (``_root_pre_forward`` and ``_states_to_forward_prefetch``) on ``state_first_in_pass`` so per-module pre-hook firing (needed for #4) doesn't multiply forward-prefetch cost by group size. ``cast_forward_inputs`` and ``fsdp_param_group.pre_forward`` still fire per module as intended. Co-authored-by: Claude <[email protected]> ghstack-source-id: 718ea74 Pull-Request: #180428
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: 13 jobs have failed, first few of them are: trunk / linux-jammy-cuda13.0-py3.10-gcc11 / test (pr_time_benchmarks, 1, 1, lf.linux.g4dn.metal.nvidia.gpu), pull / linux-jammy-py3.14-clang18 / test (default, 2, 5, linux.4xlarge), pull / linux-jammy-py3.14-clang18 / test (crossref, 2, 2, linux.2xlarge), pull / linux-jammy-aarch64-py3.10 / test (default, 2, 5, linux.arm64.m8g.4xlarge), pull / linux-jammy-py3.14t-clang18 / test (default, 2, 5, linux.4xlarge) Details for Dev Infra teamRaised by workflow job |
|
@pytorchmergebot merge -i |
Merge failedReason: 13 jobs have failed, first few of them are: trunk / linux-jammy-cuda13.0-py3.10-gcc11 / test (pr_time_benchmarks, 1, 1, lf.linux.g4dn.metal.nvidia.gpu), pull / linux-jammy-py3.14-clang18 / test (default, 2, 5, linux.4xlarge), pull / linux-jammy-py3.14-clang18 / test (crossref, 2, 2, linux.2xlarge), pull / linux-jammy-aarch64-py3.10 / test (default, 2, 5, linux.arm64.m8g.4xlarge), pull / linux-jammy-py3.14t-clang18 / test (default, 2, 5, linux.4xlarge) Details for Dev Infra teamRaised by workflow job |
|
@pytorchmergebot merge -f “unrelated errors” |
|
❌ 🤖 pytorchbot command failed: Try |
|
@pytorchmergebot merge -f ‘unrelated ci errors’ |
|
❌ 🤖 pytorchbot command failed: Try |
|
@pytorchmergebot merge -f "unrelated CI error" |
Merge startedYour change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes). Please use Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
ChunkedCELoss implementation in eager. ## Implementation When FSDP enabled: ~- separate [norm, lm_head] FSDP group: separate backward (lm_head, decoder) will double fire reduce-scatters on the same FSDP module~ Need pytorch/pytorch#180428 to be landed - set_reshard_after_forward = false - set_reshard_after_backward = false - Reduce-scatter (SUM reduce) fires per-chunk for lm_head weights’ gradients - h_chunk.grad is populated via plain autograd, collected by GradAccumulator When TP is enabled: - If SP is applied, all-gather on TP mesh to be Replicate(). Local tensor shape[B, L/N, D] - Then Detach - Apply chunk: chunk on sequence dimension. Local shape: [B, L/N, D]. - Calculate CE loss on each chunk sequentially. Loss parallel is applied when calculating each chunk. ## Memory Profiling Qwen3-0.6B model FSDP=4 w/o ChunkedLoss: <img width="1920" height="610" alt="Screenshot 2026-04-14 at 3 47 00 PM" src="https://github.com/user-attachments/assets/36f6f0d4-484c-4524-b143-cb98a6b33b2a" /> With ChunkedCELoss: <img width="1920" height="610" alt="Screenshot 2026-04-14 at 3 45 44 PM" src="https://github.com/user-attachments/assets/b80398f5-21e9-4007-9bbf-142e763f3060" /> ## Compatibility Test (llama3 debug model) TP + no SP TP + SP CP <img width="564" height="294" alt="Screenshot 2026-04-14 at 2 38 59 PM" src="https://github.com/user-attachments/assets/cc6e9062-54e4-4b0d-ae65-0d25eec1ed52" /> PP - Not supported for now. - Waiting for #2972 to be fixed Compile <img width="565" height="268" alt="Screenshot 2026-04-14 at 4 14 19 PM" src="https://github.com/user-attachments/assets/33825d6f-06ad-4026-a91b-684e5723e39e" />
…orch#180428) torchtitan wraps `fully_shard([norm, lm_head])`. Two execution patterns: - **Full forward** (no chunked loss): `norm` and `lm_head` run together - **Chunked loss**: the model forward runs `norm`-only. Then `lm_head(chunk)` is called standalone per chunk with per-chunk backward Depending on `_modules_to_run_forward` to drive unshard/reshard is wrong for the chunked-loss pattern ## Changes 1. **Unshard gated on `is_unsharded`, not `_modules_to_run_forward`.** The pre-hook unshards whenever the group isn't already unsharded, independent of `_modules_to_run_forward` 2. **Root post-forward cleanup for incomplete groups.** `_force_complete_incomplete_states` runs at the root's `post_forward` 3. **Clear `iter_forward_root` in post-backward unconditionally.** When `model.lm_head(chunk)` claims `iter_forward_root` via its pre_forward, the group's `_post_forward` never fires to clear it (partial group) ## Why this design Any call pattern that runs some submodule of the wrapped tree leaves correctly reduced sharded grads after `.backward()` — across: - Normal `model(x).backward()`. - Unused-param cases (some modules don't run). - Chunked-loss (standalone per-chunk calls). - Grad accumulation (`set_requires_gradient_sync(False)`). - Multiple forward passes before one backward. chunked-loss fires N+1 reduce-scatters (one per chunk + one for `h.backward`) instead of 1. Users who know their pattern can reclaim the single-RS behavior explicitly via `set_requires_gradient_sync(False)`: see torchtitan pytorch/torchtitan#2937 Pull Request resolved: pytorch#180428 Approved by: https://github.com/tianyu-l
…orch#180428) torchtitan wraps `fully_shard([norm, lm_head])`. Two execution patterns: - **Full forward** (no chunked loss): `norm` and `lm_head` run together - **Chunked loss**: the model forward runs `norm`-only. Then `lm_head(chunk)` is called standalone per chunk with per-chunk backward Depending on `_modules_to_run_forward` to drive unshard/reshard is wrong for the chunked-loss pattern ## Changes 1. **Unshard gated on `is_unsharded`, not `_modules_to_run_forward`.** The pre-hook unshards whenever the group isn't already unsharded, independent of `_modules_to_run_forward` 2. **Root post-forward cleanup for incomplete groups.** `_force_complete_incomplete_states` runs at the root's `post_forward` 3. **Clear `iter_forward_root` in post-backward unconditionally.** When `model.lm_head(chunk)` claims `iter_forward_root` via its pre_forward, the group's `_post_forward` never fires to clear it (partial group) ## Why this design Any call pattern that runs some submodule of the wrapped tree leaves correctly reduced sharded grads after `.backward()` — across: - Normal `model(x).backward()`. - Unused-param cases (some modules don't run). - Chunked-loss (standalone per-chunk calls). - Grad accumulation (`set_requires_gradient_sync(False)`). - Multiple forward passes before one backward. chunked-loss fires N+1 reduce-scatters (one per chunk + one for `h.backward`) instead of 1. Users who know their pattern can reclaim the single-RS behavior explicitly via `set_requires_gradient_sync(False)`: see torchtitan pytorch/torchtitan#2937 Pull Request resolved: pytorch#180428 Approved by: https://github.com/tianyu-l
…orch#180428) torchtitan wraps `fully_shard([norm, lm_head])`. Two execution patterns: - **Full forward** (no chunked loss): `norm` and `lm_head` run together - **Chunked loss**: the model forward runs `norm`-only. Then `lm_head(chunk)` is called standalone per chunk with per-chunk backward Depending on `_modules_to_run_forward` to drive unshard/reshard is wrong for the chunked-loss pattern ## Changes 1. **Unshard gated on `is_unsharded`, not `_modules_to_run_forward`.** The pre-hook unshards whenever the group isn't already unsharded, independent of `_modules_to_run_forward` 2. **Root post-forward cleanup for incomplete groups.** `_force_complete_incomplete_states` runs at the root's `post_forward` 3. **Clear `iter_forward_root` in post-backward unconditionally.** When `model.lm_head(chunk)` claims `iter_forward_root` via its pre_forward, the group's `_post_forward` never fires to clear it (partial group) ## Why this design Any call pattern that runs some submodule of the wrapped tree leaves correctly reduced sharded grads after `.backward()` — across: - Normal `model(x).backward()`. - Unused-param cases (some modules don't run). - Chunked-loss (standalone per-chunk calls). - Grad accumulation (`set_requires_gradient_sync(False)`). - Multiple forward passes before one backward. chunked-loss fires N+1 reduce-scatters (one per chunk + one for `h.backward`) instead of 1. Users who know their pattern can reclaim the single-RS behavior explicitly via `set_requires_gradient_sync(False)`: see torchtitan pytorch/torchtitan#2937 Pull Request resolved: pytorch#180428 Approved by: https://github.com/tianyu-l
Stack from ghstack (oldest at bottom):
torchtitan wraps
fully_shard([norm, lm_head]). Two execution patterns:normandlm_headrun togethernorm-only. Thenlm_head(chunk)is called standalone per chunk with per-chunk backwardDepending on
_modules_to_run_forwardto drive unshard/reshard is wrongfor the chunked-loss pattern
Changes
Unshard gated on
is_unsharded, not_modules_to_run_forward.The pre-hook unshards whenever the group isn't already unsharded,
independent of
_modules_to_run_forwardRoot post-forward cleanup for incomplete groups.
_force_complete_incomplete_statesruns at the root'spost_forwardClear
iter_forward_rootin post-backward unconditionally.When
model.lm_head(chunk)claimsiter_forward_rootvia itspre_forward, the group's
_post_forwardnever fires to clear it(partial group)
Why this design
Any call pattern that runs some submodule of the wrapped tree
leaves correctly reduced sharded grads after
.backward()— across:model(x).backward().set_requires_gradient_sync(False)).chunked-loss fires N+1 reduce-scatters (one per chunk + one for
h.backward) instead of 1.Users who know their pattern can reclaim the
single-RS behavior explicitly via
set_requires_gradient_sync(False): see torchtitan pytorch/torchtitan#2937