Extend Cosmos3 CPU offloading to component and layerwise paths (#4695)
This commit is contained in:
1 parent
98229b08ba
commit
66b9ad287a
11 files changed
+653
-160
No files matched your search
@@ -22,6 +22,38 @@ class PipelineModules:
|
||||
resident_modules: list[nn.Module] = field(default_factory=list)
|
||||
resident_names: list[str] = field(default_factory=list)
|
||||
|
||||
def outermost_dits(self) -> tuple[list[str], list[nn.Module]]:
|
||||
"""Discovered DiTs that are not nested inside another discovered DiT.
|
||||
|
||||
Some pipelines declare a DiT and one of its own submodules as separate
|
||||
DiTs (e.g. Cosmos3 lists both ``transformer`` and the nested
|
||||
``transformer.language_model``) so that offloading can treat them as
|
||||
independent rings. HSDP instead shards each DiT through that DiT's own
|
||||
``_hsdp_shard_conditions``; an inner DiT's blocks are already covered by
|
||||
its ancestor's conditions, so sharding it again would double-wrap them
|
||||
(and the inner stack may not declare conditions at all). Keeping only the
|
||||
outermost DiTs leaves the ancestor's conditions as the single source of
|
||||
truth for every nested block. Order follows ``dit_names``.
|
||||
"""
|
||||
|
||||
def is_nested_in_another_dit(dit: nn.Module) -> bool:
|
||||
for other in self.dits:
|
||||
if other is dit:
|
||||
continue
|
||||
for submodule in other.modules():
|
||||
if submodule is dit:
|
||||
return True
|
||||
return False
|
||||
|
||||
outer_names: list[str] = []
|
||||
outer_modules: list[nn.Module] = []
|
||||
for name, dit in zip(self.dit_names, self.dits):
|
||||
if is_nested_in_another_dit(dit):
|
||||
continue
|
||||
outer_names.append(name)
|
||||
outer_modules.append(dit)
|
||||
return outer_names, outer_modules
|
||||
|
||||
|
||||
class ModuleDiscovery:
|
||||
"""Discovers pipeline components.
|
||||
|
||||
Reference in new issue
Block a user