huggingface / transformers

🤗 Transformers: State-of-the-art Machine Learning for Pytorch, TensorFlow, and JAX.
https://huggingface.co/transformers
Apache License 2.0
135.65k stars 27.16k forks source link

oom when using adafactor optimizer in deepspeed #33290

Open zhangvia opened 2 months ago

zhangvia commented 2 months ago

System Info

- `transformers` version: 4.44.2
- Platform: Linux-5.15.0-105-generic-x86_64-with-glibc2.31
- Python version: 3.10.0
- Huggingface_hub version: 0.23.4
- Safetensors version: 0.4.2
- Accelerate version: 0.33.0
- Accelerate config:    not found
- PyTorch version (GPU?): 2.3.0+cu118 (True)
- Tensorflow version (GPU?): not installed (NA)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using distributed or parallel set-up in script?: <fill in>
- Using GPU in script?: <fill in>
- GPU type: NVIDIA A800 80GB PCIe

Who can help?

No response

Information

Tasks

Reproduction

i'm running train_xl.sh in this repo. and i change the 8bit adam optimizer to adafactor optimizer using transformers.optimization.Adafactor. i'm using two 40GB a100, deepspeed stage 2, batchsize=1,VTON-HD dataset.

the adafactor optimizer should use less gpu memory, because of less optimizer states than 8bit adam, but it get oom in this line

and oom happens after 10 steps, i don't know what happen in 10th step, i call the accelerate.backward() andoptimizer.step() every step.

and in 10th step, the memory usage increased from 29GB to 39GB when using 8bit adam optimizer, and get oom when using adafactor optimizer

Expected behavior

could anybody explain this phenomenon

LysandreJik commented 2 months ago

cc @SunMarc and @muellerzr

ArthurZucker commented 1 month ago

Hey! This seems like a usage issue! (10 steps just means it normally OOMED) Recommending you this: https://pytorch.org/blog/understanding-gpu-memory-1/ 🤗

hritikranjan1 commented 1 month ago

@ArthurZucker I would like to take this issue up.

Aryan8912 commented 3 weeks ago

.take