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

[NeMo-UX] Use single instance of loss reductions in GPTModel #9801

Merged
merged 3 commits into from
Jul 24, 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
14 changes: 12 additions & 2 deletions nemo/collections/llm/gpt/model/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ def __init__(
self.optim = optim or MegatronOptimizerModule(config=OptimizerConfig(lr=1e-4, use_distributed_optimizer=True))
self.optim.connect(self) # This will bind the `configure_optimizers` method
self.model_transform = model_transform
self._training_loss_reduction = None
self._validation_loss_reduction = None

def configure_model(self) -> None:
if not hasattr(self, "module"):
Expand Down Expand Up @@ -200,11 +202,19 @@ def validation_step(self, batch, batch_idx=None) -> torch.Tensor:

return self.forward_step(batch)

@property
def training_loss_reduction(self) -> MaskedTokenLossReduction:
return MaskedTokenLossReduction()
if not self._training_loss_reduction:
self._training_loss_reduction = MaskedTokenLossReduction()

return self._training_loss_reduction

@property
def validation_loss_reduction(self) -> MaskedTokenLossReduction:
return MaskedTokenLossReduction(validation_step=True)
if not self._validation_loss_reduction:
self._validation_loss_reduction = MaskedTokenLossReduction(validation_step=True)

return self._validation_loss_reduction


def get_batch_on_this_context_parallel_rank(batch):
Expand Down
Loading