Skip to content

[Checkpointer] Refresh ModelWrapper hook-produced tensors in place - #3675

Merged
fegin merged 6 commits into
mainfrom
gh/fegin/139/head
Jun 15, 2026
Merged

fegin merged 6 commits into
mainfrom
gh/fegin/139/head

Conversation

@fegin

@fegin fegin commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

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.

fegin added 2 commits June 15, 2026 11:26
[ghstack-poisoned]
[ghstack-poisoned]
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jun 15, 2026
fegin added 2 commits June 15, 2026 11:44
[ghstack-poisoned]
[ghstack-poisoned]
@fegin
fegin marked this pull request as ready for review June 15, 2026 19:27
fegin added 2 commits June 15, 2026 14:30
[ghstack-poisoned]
[ghstack-poisoned]
@fegin
fegin changed the base branch from gh/fegin/139/base to main June 15, 2026 22:12
@fegin
fegin merged commit 2e1ce04 into main Jun 15, 2026
11 of 13 checks passed
fegin added a commit that referenced this pull request Jun 15, 2026
…Forward (#3638)

Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.15.0)
(oldest at bottom):
* __->__ #3638
* #3675

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/8gpu 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.

2 participants