Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing planner to _shard_modules #2732

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions torchrec/distributed/shard.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ def _shard_modules( # noqa: C901
plan: Optional[ShardingPlan] = None,
sharders: Optional[List[ModuleSharder[torch.nn.Module]]] = None,
init_params: Optional[bool] = False,
planner: Optional[EmbeddingShardingPlanner] = None,
) -> nn.Module:
"""
See shard_modules
Expand Down Expand Up @@ -238,13 +239,14 @@ def _shard_modules( # noqa: C901
assert isinstance(
env, ShardingEnv
), "Currently hybrid sharding only support use manual sharding plan"
planner = EmbeddingShardingPlanner(
topology=Topology(
local_world_size=get_local_size(env.world_size),
world_size=env.world_size,
compute_device=device.type,
if planner is None:
planner = EmbeddingShardingPlanner(
topology=Topology(
local_world_size=get_local_size(env.world_size),
world_size=env.world_size,
compute_device=device.type,
)
)
)
pg = env.process_group
if pg is not None:
plan = planner.collective_plan(module, sharders, pg)
Expand Down
Loading