from_pretrained distributed refactor (FSDP2 + TP)#44996
Merged
3outeille merged 13 commits intofsdp-core-model-loadingfrom Mar 26, 2026
Merged
from_pretrained distributed refactor (FSDP2 + TP)#449963outeille merged 13 commits intofsdp-core-model-loadingfrom
3outeille merged 13 commits intofsdp-core-model-loadingfrom
Conversation
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
1436e31 to
4972eae
Compare
4972eae to
091eaa2
Compare
…dConfig) - Expand DistributedConfig with tp_size, tp_plan, fsdp_size, fsdp_plan - Add init_device_mesh() for building 2D DeviceMesh from DistributedConfig - Reuse apply_fsdp2() from PR #44083 for FSDP2 fully_shard wrapping - Rewire from_pretrained with two clean separated paths: 1. distributed_config → native torch.distributed (no accelerate) 2. Everything else → accelerate (unchanged) - Export DistributedConfig from top-level transformers package - Add unit tests for DistributedConfig
502a09f to
c758c59
Compare
Contributor
|
[For maintainers] Suggested jobs to run (before merge) run-slow: clap, deit |
Contributor
|
View the CircleCI Test Summary for this PR: https://huggingface.co/spaces/transformers-community/circle-ci-viz?pr=44996&sha=0b8b77 |
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.
DistributedConfigDistributedConfig(tp_size=2, fsdp_size=2) # plans default to "auto"replaces passing separatetp_plan, tp_size, fsdp_plan kwargs. Sizes auto-fill (specify one, the other defaults to 1). Plans default to "auto" when a size is given.init_device_mesh+distribute_modelinit_device_mesh(distributed_config)→ builds a 2DDeviceMesh("fsdp", "tp"), inits process group if neededdistribute_model(model, distributed_config, device_mesh)→ attaches TP hooks before weight loadingapply_fsdp2(model, mesh, plan)→ wraps with FSDP2 after weight loadingaccelerateandtransformers.distributeddont overlap. Separate codepathdistributed_configpathinit_device_mesh()check_and_set_device_map()distribute_model()(TP hooks)distribute_model()+_get_device_map()apply_fsdp2()accelerate_dispatch()Note:
apply_fsdp2will be moved to pre-loading soon as we dont want to to apply it full weights.We can now train like this: