deepspeedai / deepspeedai/DeepSpeed

Backward time grows linearly to the number of to zero3_consolidated_16bit_state_dict called

Open
#5,332 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug training
Dominant language
Python
Stars
43.1k
Forks
5k
Avg merge
4d 15h
Merged PRs (30d)
112

Description

I'm training a model with ema states which means module state dict needs to be gathered after each step. When zero stage 3 is enabled model_engine.backward become slower as step grows.
image
Training loop

train_steps = 0
for _ in epoch:
    for x, y in dataset:
        ts = time()
        model_engine.backward(loss / grac_acc)
        running_loss.append(loss.detach().item() * args.grad_acc_steps)
        backward_seconds += time() - ts
        # ...
        if train_steps % grac_acc == 0:
            model_engine.step()

            if model_engine.zero_optimization_stage() == 3:
                sd = model_engine._zero3_consolidated_16bit_state_dict()
            elif is_global_rank_0():
                sd = model_engine.module_state_dict()

            if is_global_rank_0():
                update_ema(ema, sd)

            tb_writer.add_scalar(
                'Train/Backward time ms',
                backward_seconds * 1000,
                train_steps,
            )
            backward_seconds = 0
            train_steps += 1

if model_engine._zero3_consolidated_16bit_state_dict is disabled, backward time is not growing and everything works fine.

ds version is 0.12.6 Tried on 8 * a800 & 8 * 3090

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at model_engine._zero3_consolidated_16bit_state_dict and reproduce the supplied training loop with ZeRO stage 3, recording backward time as train_steps increases. Compare runs with state-dict consolidation enabled and disabled; done means backward time no longer grows linearly with the number of calls.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
distributed-systems, machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.