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

Distributed optimizer reduces GPT embedding grads in FP32 #8792

Merged
merged 6 commits into from
Apr 5, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -770,8 +770,28 @@ def get_config_arg(key: str, default_value: Optional[Any] = None) -> Any:

# Make sure embedding grad reductions are in FP32
if optim_dtype == torch.float32:
for name, param in self.named_parameters():
if 'word_embedding' in name or 'position_embedding' in name or 'output_layer' in name:
fp32_params = []
modules = self.get_model_module_list()
if parallel_state.is_pipeline_first_stage(ignore_virtual=True):
if self.mcore_gpt:
fp32_params.append(modules[0].shared_embedding_or_output_weight())
fp32_params.append(modules[0].embedding.position_embeddings.weight)
else:
fp32_params.append(modules[0].word_embeddings_weight())
fp32_params.append(modules[0].position_embeddings_weight())
if parallel_state.is_pipeline_last_stage(ignore_virtual=True):
share_embeddings_and_output_weights = (
modules[-1].share_embeddings_and_output_weights
if self.mcore_gpt
else modules[-1].share_token_embeddings
)
if share_embeddings_and_output_weights:
if self.mcore_gpt:
fp32_params.append(modules[-1].shared_embedding_or_output_weight())
else:
fp32_params.append(modules[-1].word_embeddings_weight())
for param in fp32_params:
if param is not None:
param._with_fp32_optimizer = True

# Match param allgather with model dtype
Expand Down
Loading