Skip to content

Commit dccce56

Browse files
aigaolcliu-zichen
authored andcommitted
per-token loss calculation
Adjust loss logging based on per-token loss calculation.
1 parent b3c0c11 commit dccce56

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

mcore_adapter/src/mcore_adapter/trainer/trainer.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,12 @@ def _maybe_log_save_evaluate(
927927
# reset tr_loss to zero
928928
tr_loss -= tr_loss
929929

930-
logs["loss"] = round(tr_loss_scalar / (self.state.global_step - self._globalstep_last_logged), 4)
930+
# logs["loss"] = round(tr_loss_scalar / (self.state.global_step - self._globalstep_last_logged), 4)
931+
if self.args.calculate_per_token_loss:
932+
logs["loss"] = round(tr_loss_scalar, 4)
933+
else:
934+
logs["loss"] = round(tr_loss_scalar / (self.state.global_step - self._globalstep_last_logged), 4)
935+
931936
if grad_norm is not None:
932937
logs["grad_norm"] = grad_norm.detach().item() if isinstance(grad_norm, torch.Tensor) else grad_norm
933938
logs["learning_rate"] = self._get_learning_rate()

0 commit comments

Comments
 (0)