Repository navigation
[Cosmos3] Add native tensor parallelism - #15137
yzhautouskay wants to merge 5 commits into
Conversation
|
@sayakpaul @yiyixuxu Could you please this PR to enable native TP in Cosmos3? |
|
Hi @yzhautouskay, thanks for the PR! It does not appear to link an issue it fixes. If this PR addresses an existing issue, please add a closing keyword (e.g. Please note that PRs without a linked issue are likely to be automatically closed 10 days after this notice. Once the PR links an issue (or gets the |
sayakpaul
left a comment
There was a problem hiding this comment.
Thanks!
Some changes are a bit intrusive so I did some work in https://github.com/huggingface/diffusers/compare/cosmos3-tp-plan-resolution?expand=1 which should solve the issues in a less intrusive way. Does that work for you?
|
|
||
| if spec is None: | ||
| set_module_tensor_to_device(model, key, device, value=param) | ||
| set_module_tensor_to_device(model, key, device, value=param, dtype=param.dtype) |
There was a problem hiding this comment.
Before the change during Cosmos BF16 TP loading, the loader correctly kept time_embedder weights in FP32, but Accelerate cast them back to BF16 using the destination meta parameter’s dtype. Other models could hit the same issue whenever those dtypes differed
So passing dtype=param.dtype makes Accelerate preserve the loader's chosen dtype
There was a problem hiding this comment.
Can we open a new PR for this before this one is merged with a simple test?
Context
Cosmos TP/CP currently lives in the examples following #14054, where it was kept outside the core model while the library parallelism APIs were evolving. Those example helpers and their CLI behavior remain unchanged.
Diffusers now provides native model TP (#13718) and sharded checkpoint loading (#14544), so this PR integrates Cosmos with that infrastructure. Following the review direction in #14609, this PR is TP-only. Native Cosmos CP and TP+CP integration can follow separately after the generic composition work in #14725 is settled.
Cosmos native TP
Shared loading fixes
modeling_utils.pynow uses the constructed model’smodel._tp_planinstead ofcls._tp_planwhen calculating checkpoint shards and installing TP hooks. Cosmos ReLU2 overrides the instance plan to remove nonexistentgate_projentries, preventing the previous module-resolution failure. Other models are unaffected because, unless they define an instance-specific plan,model._tp_planresolves to the same class-level plan ascls._tp_planmodel_loading_utils.pypreserves the loader-selected dtype for replicated tensors. This prevents Accelerate from undoing FP32 module exceptions, such as Cosmos timestep weights during BF16 loading.Both changes are covered by focused regression tests. Non-TP loading behavior is unchanged.
Validation
make style,make fix-copiesandgit diff --checkpassed.Before submitting
self-reviewskill on the diff?documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.