Skip to content

[BUG] monitor loss seems not being correctly computed. #3769

Closed

Description

@whr94621

Describe the bug

The loss values saved in https://github.com/microsoft/DeepSpeed/blob/v0.9.4/deepspeed/runtime/engine.py#L1843 are already divided by gradient_accumulation_steps in this line https://github.com/microsoft/DeepSpeed/blob/v0.9.4/deepspeed/runtime/engine.py#L1835.

So currently the monitored loss is actually mini-batch loss divided by gradient_accumulation_steps, which will vary as the gradient_accumulation_steps changed in different settings. I don't know if it is the expecting behavior and in my opinion gradient_accumulation_steps should not change the training loss curve if global_batch_size is kept unchanged? (for example, micro_batch_size = 8, grad_acc_steps = 8, dp_size=8 should have the similar curve as micro_batch_size = 4, grad_acc_steps = 16, dp_size=8)

To Reproduce
Training with different grad_acc_steps while keeping global_batch_size unchanged.

Sorry but currently I do not have a quick script to reproduce this issue

Expected behavior
A clear and concise description of what you expected to happen.

ds_report output
Please run ds_report to give us details about your setup.

Screenshots
If applicable, add screenshots to help explain your problem.

System info (please complete the following information):

  • OS: [e.g. Ubuntu 18.04]
  • GPU count and types [e.g. two machines with x8 A100s each]
  • Interconnects (if applicable) [e.g., two machines connected with 100 Gbps IB]
  • Python version
  • Any other relevant info about your setup

Launcher context
Are you launching your experiment with the deepspeed launcher, MPI, or something else?

Docker context
Are you using a specific docker image that you can share?

Additional context
Add any other context about the problem here.

Activity

  1. added
    bug
    on Jun 19, 2023
  2. chhensel commented on Jun 22, 2023

    @chhensel

    Adding on to this (as it's related to the same commit), we are seeing that the loss is no longer correctly monitored when no gradient accumulation is set, but it's reported as 0 consistently.

    Looking at this logic: https://github.com/microsoft/DeepSpeed/blob/master/deepspeed/runtime/engine.py#L1836-L1850
    this seems only natural, because every step is at a gradient accumulation boundary and self.losses will be cleared every step.

    I may be mistaken, but this seems to be just one special case of a more general problem: one element from every interval between gradient accumulations is dropped as the current step's loss at an accumulation boundary is not part of self.losses at the time of reporting and will not be recorded to self.losses here either.

    All of the reported issues seem related to this commit: 4d269c6

  3. tginart commented on Jun 22, 2023

    @tginart

    I am also experiencing this issue. Is there any patch?

  4. whr94621 commented on Jun 25, 2023

    @whr94621
    Author

    I am also experiencing this issue. Is there any patch?

    Currently, I just manually collect the losses from rank0 and write the correct loss event again with a different name. This is just what DeepSpeed to in DeepSpeedEngine.

    losses = []
    
    if model.is_gradient_accumulation_boundary():
        train_loss_this_step = sum(losses) / len(losses)
    
        # 1. Logging
        if model.monitor.enabled:
            if model.global_rank == 0:
                global_samples = model.global_samples
                global_steps = model.global_steps + 1
                summary_events = [(
                    f"Train/Samples/real_training_loss",
                    train_loss_this_step, global_samples
                ), ]
    
                model.monitor.write_events(summary_events)
    
                log_dist(f"GlobalSteps: {global_steps} Loss: {train_loss_this_step:.3f}", ranks=[0])
    
        losses = []
  5. self-assigned this
    on Jul 7, 2023
  6. linked a pull request that will close this issueMonitored Loss Calculations #4030on Jul 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugtraining

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions