Skip to content

Fixed reporting of single value of loss and ppl across devices. #496

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

quic-meetkuma
Copy link
Contributor

  • Fixed reporting of single value of loss and ppl across devices.
  • Minor refactoring changes and variable name changes to make it consistent.


if local_rank == 0:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

local_rank will be None in non ddp case. Hence, it will not update the tensorboard in non DDP case. Defining following method in helper.py and calling it over here will help:
def is_rank_zero():
return int(os.getenv("LOCAL_RANK", 0)) == 0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, will update!

# Update the learning rate as needed
lr_scheduler.step()

if train_config.run_validation:
if train_config.enable_ddp:
dist.barrier()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving line #368 and #369 won't be any help. We can keep these here only.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is code refactoring. Moved inside evaluation function.

eval_epoch_loss = (
0.0 if eval_loss == 0.0 else eval_loss / (step + 1 - num_dummy_samples / train_config.val_batch_size)
)
eval_loss = 0.0 if eval_loss == 0.0 else eval_loss / (step + 1 - num_dummy_samples / train_config.val_batch_size)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are using the variable name train_epoch_loss for the average train loss of the epoch, it will be good to keep the name eval_epoch_loss for the average evaluation loss of the epoch to maintain uniformity.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check the other variables being returned from this function. Made the names consistent.

@quic-meetkuma quic-meetkuma marked this pull request as ready for review July 8, 2025 05:31
dist.all_reduce(eval_loss, op=dist.ReduceOp.SUM)
eval_loss /= get_num_ddp_devices()
dist.all_reduce(eval_metric, op=dist.ReduceOp.SUM)
eval_metric /= get_num_ddp_devices()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will it not make each json files have same data for train_epoch_loss, train_epoch_metric and val_epoch_loss and val_epoch_metric?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

train_epoch_loss and train_epoch_metric are all_reduced after they are populated at L357.

For this eval_loss and eval_metric, you are right. I will move this all reduce after L386.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants