-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from huggingface/phuc/feature_add_parallel_con…
…text [Refactor] Add minimal ParallelContext
- Loading branch information
Showing
41 changed files
with
1,198 additions
and
947 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,18 @@ | ||
from torch import nn | ||
|
||
from nanotron.core import distributed as dist | ||
from nanotron.core.parallel.tied_parameters import get_tied_id_to_param | ||
from nanotron.core.process_groups import DistributedProcessGroups | ||
from nanotron.distributed import ParallelContext | ||
from torch import nn | ||
|
||
|
||
def initial_sync(model: nn.Module, dpg: DistributedProcessGroups): | ||
def initial_sync(model: nn.Module, parallel_context: ParallelContext): | ||
# Synchronize across dp: basic assumption | ||
sorted_name_params = sorted(model.named_parameters(), key=lambda x: x[0]) | ||
for name, param in sorted_name_params: | ||
dist.all_reduce(param, op=dist.ReduceOp.AVG, group=dpg.dp_pg) | ||
dist.all_reduce(param, op=dist.ReduceOp.AVG, group=parallel_context.dp_pg) | ||
|
||
# Synchronize across tied weights: basic assumption | ||
for (_, group_ranks), param in sorted( | ||
get_tied_id_to_param(parameters=model.parameters(), root_module=model).items(), key=lambda x: x[0] | ||
): | ||
group = dpg.world_ranks_to_pg[group_ranks] | ||
group = parallel_context.world_ranks_to_pg[group_ranks] | ||
dist.all_reduce(param, op=dist.ReduceOp.AVG, group=group) |
Oops, something went wrong.