deepspeedai / deepspeedai/DeepSpeed

[BUG] model.load_checkpoint out of memory

Open
#3,938 7 comments 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

System Info
accelerate 0.20.3
python 3.10
numpy 1.24.3
torch 2.0.1
accelerate config:
compute_environment: LOCAL_MACHINE
deepspeed_config:
  deepspeed_multinode_launcher: standard
  gradient_accumulation_steps: 1
  gradient_clipping: 1.0
  offload_optimizer_device: none
  offload_param_device: none
  zero3_init_flag: true
  zero3_save_16bit_model: true
  zero_stage: 3
distributed_type: DEEPSPEED
downcast_bf16: 'no'
dynamo_config: {}
fsdp_config: {}
main_training_function: main
megatron_lm_config: {}
mixed_precision: bf16
num_machines: 1
num_processes: 8
tpu_env: []
tpu_use_cluster: false
tpu_use_sudo: false
use_cpu: false
Information
  • The official example scripts
  • My own modified scripts
Tasks
  • One of the scripts in the examples/ folder of Accelerate or an officially supported no_trainer script in the examples folder of the transformers repo (such as run_no_trainer_glue.py)
  • My own task or dataset (give details below)
Reproduction

I pretrain a 27B model from scratch with deepspeed stage 3 (no cpu offload) in 8*80G A100, batch size of each gpu is 2. And I use 'accelerator.save_state()' to save the optimizer/lr scheduler. The saved files are as follows:
image

When I want to resume from above saved checkpoint, I use the following code:
model, train_dataloader, optimizer, lr_scheduler = accelerator.prepare(
model, train_dataloader, optimizer, lr_scheduler
)
accelerator.load_state('/pretrained_model/xxx')
But I got the error of CUDA out of memory. Can you help me? Thanks a lot.

Expected behavior

I expected it cannot caused the cuda out of memory.

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 with the accelerator.prepare and accelerator.load_state calls in the reproduction, then inspect how the saved optimizer and scheduler checkpoint is restored under DeepSpeed ZeRO stage 3. Reproduce with the stated 27B model and 8×80G A100 configuration; done means resuming the checkpoint without a CUDA out-of-memory error.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
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.