Repository navigation
[Override] Make FusedSwiGLU checkpoints interoperable with stock FeedForward - #3638
Merged
Merged
Conversation
[ghstack-poisoned]
tianyu-l
reviewed
Jun 11, 2026
fegin
added a commit
that referenced
this pull request
Jun 12, 2026
…ict APIs (#3623) Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.15.0) (oldest at bottom): * #3638 * __->__ #3623 **Summary:** Same as #2441 but with new implementation to be compatiblewith the latest OptimizerContainer **Verification:** | Check | Result | |---|---| | Checkpoint compat, FSDP (old saves -> new loads, resume to step 100) | PASS - bit-identical all 100 steps | | Checkpoint compat, PP=2 (old saves -> new loads) | PASS - bit-identical | | loss_compare, FSDP (old vs new, 100 steps, seed checkpoint) | PASS - identical loss | | CPU unit tests (lr_scheduler, optimizer_param_groups, state_dict_keys, checkpoint) | 51 passed | | Full unit suite | 411 passed (2 unrelated tokenizer-download failures) | | Lint (ufmt, flake8, pydoclint) | pass |
saforem2
pushed a commit
to saforem2/torchtitan
that referenced
this pull request
Jun 12, 2026
…ict APIs (pytorch#3623) Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.15.0) (oldest at bottom): * pytorch#3638 * __->__ pytorch#3623 **Summary:** Same as pytorch#2441 but with new implementation to be compatiblewith the latest OptimizerContainer **Verification:** | Check | Result | |---|---| | Checkpoint compat, FSDP (old saves -> new loads, resume to step 100) | PASS - bit-identical all 100 steps | | Checkpoint compat, PP=2 (old saves -> new loads) | PASS - bit-identical | | loss_compare, FSDP (old vs new, 100 steps, seed checkpoint) | PASS - identical loss | | CPU unit tests (lr_scheduler, optimizer_param_groups, state_dict_keys, checkpoint) | 51 passed | | Full unit suite | 411 passed (2 unrelated tokenizer-download failures) | | Lint (ufmt, flake8, pydoclint) | pass |
sdmyzlp
reviewed
Jun 13, 2026
| """ | ||
| w13 = state_dict.pop(f"{prefix}w13") | ||
| state_dict[f"{prefix}w1.weight"] = w13[:, 0].contiguous() | ||
| state_dict[f"{prefix}w3.weight"] = w13[:, 1].contiguous() |
Collaborator
There was a problem hiding this comment.
This seems to conflict with ModelWrapper's caching behavior for model.state_dict() at init time.
The _split_w13_on_save hook's .contiguous() creates copies that are detached from the parameter storage. After optimizer steps update w13.weight in‑place, the cache holds stale values, causing DCP to save incorrect weights.
I have attempted to address this issue in PR #3656 . Could you please take a look and let me know if anything looks off?
[ghstack-poisoned]
fegin
added a commit
that referenced
this pull request
Jun 15, 2026
…Forward FusedSwiGLU now checkpoints in the stock FeedForward layout (w1.weight/w3.weight) via register_state_dict_post_hook / register_load_state_dict_pre_hook, so its checkpoints interoperate with the non-fused module and the HF state-dict adapter (a native w13 key is still accepted). This is possible now that we removed the usage of get_model_state_dict/set_model_state_dict. Also moves the override design doc to torchtitan/overrides/README.md for discoverability. Adds CPU unit tests for both load directions, native-w13 back-compat, and HF-adapter interop. ghstack-source-id: 3efb0ec Pull-Request: #3638
[ghstack-poisoned]
fegin
added a commit
that referenced
this pull request
Jun 15, 2026
…Forward FusedSwiGLU now checkpoints in the stock FeedForward layout (w1.weight/w3.weight) via register_state_dict_post_hook / register_load_state_dict_pre_hook, so its checkpoints interoperate with the non-fused module and the HF state-dict adapter (a native w13 key is still accepted). This is possible now that we removed the usage of get_model_state_dict/set_model_state_dict. Also moves the override design doc to torchtitan/overrides/README.md for discoverability. Adds CPU unit tests for both load directions, native-w13 back-compat, and HF-adapter interop. ghstack-source-id: cfe40dd Pull-Request: #3638
[ghstack-poisoned]
fegin
added a commit
that referenced
this pull request
Jun 15, 2026
…Forward FusedSwiGLU now checkpoints in the stock FeedForward layout (w1.weight/w3.weight) via register_state_dict_post_hook / register_load_state_dict_pre_hook, so its checkpoints interoperate with the non-fused module and the HF state-dict adapter (a native w13 key is still accepted). This is possible now that we removed the usage of get_model_state_dict/set_model_state_dict. Also moves the override design doc to torchtitan/overrides/README.md for discoverability. Adds CPU unit tests for both load directions, native-w13 back-compat, and HF-adapter interop. ghstack-source-id: eac80aa Pull-Request: #3638
Contributor
Author
tianyu-l
approved these changes
Jun 15, 2026
[ghstack-poisoned]
fegin
added a commit
that referenced
this pull request
Jun 15, 2026
…Forward FusedSwiGLU now checkpoints in the stock FeedForward layout (w1.weight/w3.weight) via register_state_dict_post_hook / register_load_state_dict_pre_hook, so its checkpoints interoperate with the non-fused module and the HF state-dict adapter (a native w13 key is still accepted). This is possible now that we removed the usage of get_model_state_dict/set_model_state_dict. Also moves the override design doc to torchtitan/overrides/README.md for discoverability. Adds CPU unit tests for both load directions, native-w13 back-compat, and HF-adapter interop. ghstack-source-id: e069c42 Pull-Request: #3638
fegin
added a commit
that referenced
this pull request
Jun 15, 2026
…3675) Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.15.0) (oldest at bottom): * #3638 * __->__ #3675 **TLDR** We need cached state_dict for the pinned memory copy. But state_dict hooks can invalidate the cache. This PR fixes by using `copy_` for those tensors that storages change. **Summary** ModelWrapper caches the flattened model state dict so async DCP staging reuses its pinned host buffers (the stager keys them by source storage). A module state_dict hook that emits a freshly allocated tensor (e.g. splitting a fused parameter into the stock layout) is disconnected from the parameter, so once training updates the parameter the cached copy goes stale and the checkpoint saves init-time values. state_dict() now refreshes only those hook-produced tensors in place, so their storage stays stable (pinned buffers stay reusable) while values stay current. Parameter-backed tensors share storage with the live parameter and need no copy; models without such hooks return the cache unchanged. Adds CPU unit tests for stable storage plus in-place refresh.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stack from ghstack (oldest at bottom):
FusedSwiGLU now checkpoints in the stock FeedForward layout (w1.weight/w3.weight) via register_state_dict_post_hook / register_load_state_dict_pre_hook, so its checkpoints interoperate with the non-fused module and the HF adapter (a native w13 key is still accepted). This is possible now that we removed the usage of get_model_state_dict/set_model_state_dict. Resolves #3569.
Adds CPU unit tests for both load directions and native-w13 back-compat.