Skip to content

[Umbrella] FSDP2 × expert-parallelism fixes (do not merge) - #4178

Draft
qgallouedec wants to merge 7 commits into
mainfrom
fsdp2-ep-integration
Draft

[Umbrella] FSDP2 × expert-parallelism fixes (do not merge)#4178
qgallouedec wants to merge 7 commits into
mainfrom
fsdp2-ep-integration

Conversation

@qgallouedec

@qgallouedec qgallouedec commented Aug 22, 2026

Copy link
Copy Markdown
Member

Install-only umbrella for FSDP2 × expert parallelism (huggingface/transformers#48204): merges

so colleagues can install one branch. Not meant to merge.

Used by the runnable 100B–753B MoE training examples in huggingface/trl#6869.

…nsion

`ParallelismConfig.fsdp_dim_names` always asks for `dp_shard_cp`, but that joint
dimension is only flattened into the device mesh when `dp_shard` or `cp` is enabled.
Launching an already-parallelized model -- e.g. one loaded with
`DistributedConfig(tp_size=world_size)` or `enable_expert_parallel=True` -- under an
FSDP config therefore slices a tp-only mesh by a name it does not contain, and the user
sees a bare `KeyError` from `torch.distributed.device_mesh`, several frames below any
code they wrote. Say what is actually wrong instead.
is_peft_available() checks importlib metadata, so a peft provided only through
PYTHONPATH (source checkout, shipped environment) makes is_peft_model() return
False even while a PeftModel instance is right there in the model tree. Callers
then treat the wrapper as a plain model; in TRL this patched a fused-loss
forward onto the PeftModel, where transformers' base_model property resolves to
peft's LoraModel and training crashes with an unrelated-looking AttributeError.

If peft is already in sys.modules, isinstance against it directly; fall back to
the metadata check only to trigger the first import.
A model sharded at load time (e.g. transformers DistributedConfig with FSDP2,
optionally CPU-offloaded) manages its own parameter placement, and .to() on
FSDP2-managed parameters raises RuntimeError: _apply(): Couldn't swap
FSDPLinear.weight. model_has_dtensor already exists and is checked a few lines
below for the DDP case; use it to skip the device move too.
@qgallouedec
qgallouedec marked this pull request as draft August 22, 2026 19:57
@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants