DeepSpeed icon indicating copy to clipboard operation
DeepSpeed copied to clipboard

[BUG]AttributeError: 'HfDeepSpeedConfig' object has no attribute 'trainer_config_finalize'

Open 2018211801 opened this issue 3 years ago • 15 comments

Describe the bug I check the source code, and find that HfDeepSpeedConfig is inherited by HfTrainerDeepSpeedConfig,the trainer_config_finalize is defined in the subclass HfTrainerDeepSpeedConfig.

Traceback (most recent call last): [10/1911] File "/mnt/data/wxc/workspace/release/qlora_train.py", line 197, in train() File "/mnt/data/wxc/workspace/release/qlora_train.py", line 191, in train trainer.train() File "/home/wxc/miniconda3/envs/llama/lib/python3.9/site-packages/transformers/trainer.py", line 1661, in train return inner_training_loop( File "/home/wxc/miniconda3/envs/llama/lib/python3.9/site-packages/transformers/trainer.py", line 1740, in _inner_training_loop self.optimizer, self.lr_scheduler = deepspeed_init(self, num_training_steps=max_steps) File "/home/wxc/miniconda3/envs/llama/lib/python3.9/site-packages/transformers/deepspeed.py", line 343, in deepspeed_init hf_deepspeed_config.trainer_config_finalize(args, model, num_training_steps) AttributeError: 'HfDeepSpeedConfig' object has no attribute 'trainer_config_finalize'

To Reproduce Steps to reproduce the behavior: 1.CUDA_VISIBLE_DEVICES="0,5" accelerate launch --nnodes=1 --nproc_per_node=2 --master_port='29501' qlora_train.py --learning_rate=2e-5 --per_device_train_batch_size=46 --gradient_accumulation_steps=1 --deepspeed deepspeed_config_s2.json

2. the deepspeed_config_s2.json `{ "fp16": { "enabled": "auto", "loss_scale": 0, "loss_scale_window": 1000, "initial_scale_power": 16, "hysteresis": 2, "min_loss_scale": 1 },

"optimizer": {
    "type": "AdamW",
    "params": {
        "lr": "auto",
        "betas": "auto",
        "eps": "auto",
        "weight_decay": "auto"
    }
},

"scheduler": {
    "type": "WarmupLR",
    "params": {
        "warmup_min_lr": "auto",
        "warmup_max_lr": "auto",
        "warmup_num_steps": "auto"
    }
},

"zero_optimization": {
    "stage": 2,
    "offload_optimizer": {
        "device": "cpu",
        "pin_memory": true
    },
    "allgather_partitions": true,
    "allgather_bucket_size": 2e8,
    "overlap_comm": true,
    "reduce_scatter": true,
    "reduce_bucket_size": 2e8,
    "contiguous_gradients": true
},

"gradient_accumulation_steps": "auto",
"gradient_clipping": "auto",
"steps_per_print": 2000,
"train_batch_size": "auto",
"train_micro_batch_size_per_gpu": "auto",
"wall_clock_breakdown": false

}`

Expected behavior I was able to run successful deepspeed multi-card training before, but after joining QLORA, I encountered this error.

System info (please complete the following information):

Because I ran into a problem before, a pr solved it ,the version I used was "git clone -b olruwase/ds_3678 https://github.com/microsoft/DeepSpeed.git"

Launcher context CUDA_VISIBLE_DEVICES="0,5" accelerate launch --nnodes=1 --nproc_per_node=2 --master_port='29501' qlora_train.py --learning_rate=2e-5 --per_device_train_batch_size=46 --gradient_accumulation_steps=1 --deepspeed deepspeed_config_s2.json

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

Additional context Add any other context about the problem here.

2018211801 avatar Jun 10 '23 06:06 2018211801

I meet this issue,when I try to use QLORA and deepspeed together. Does any one can help?

2018211801 avatar Jun 21 '23 04:06 2018211801

want to know if qlora can be use in deepspeed

Nisoka avatar Jul 07 '23 02:07 Nisoka

Hi @2018211801 - are you saying you tried the olruwase/ds_3678 branch before, it fixed your issue, and you are hitting a new issue? Or it didn't resolve your issue?

And can you confirm that you are seeing this with either 0.10.0 or the latest DeepSpeed if building from source?

loadams avatar Jul 07 '23 21:07 loadams

Facing the same issue.

sawradip avatar Jul 26 '23 11:07 sawradip

same issue

QYHcrossover avatar Jul 28 '23 06:07 QYHcrossover

@sawradip or @QYHcrossover - can you provide a repro case so I can investigate?

loadams avatar Jul 28 '23 14:07 loadams

@2018211801 - from what we tried before, qlora+deepspeed wasn't a supported combination, because qlora couldn't work with multiple GPUs. If qlora have updated their code to work with multi-gpu, we can see. Do you have a smaller repro script than the above one?

loadams avatar Aug 09 '23 17:08 loadams

same issue

MaxMys avatar Aug 14 '23 04:08 MaxMys

@MaxMys - do you have a small repro script that we can reproduce with on our side?

loadams avatar Aug 14 '23 15:08 loadams

Encountered the same issue. In my case initializing accelerate.Accelerator only once (automatically does by the trainer) solves the problem. I think qlora+deepspeed can work with stage2 without offloading.

namespace-Pt avatar Aug 22 '23 16:08 namespace-Pt

@namespace-Pt - yes I believe that is correct. Though do you have a small repro case for the stage3 error?

loadams avatar Sep 01 '23 17:09 loadams

same issue encountered.

chongxiaoc avatar Sep 09 '23 00:09 chongxiaoc

Removing any initialization of accelerate.Accelerator before initializing the HF trainer resolved this issue for me.

For example, if you have used it when loading the model

model = AutoModelForCausalLM.from_pretrained(
    model_name_or_path,
    torch_dtype=torch.fp16,
-    device_map={"": Accelerator().process_index},
)

bofenghuang avatar Oct 07 '23 17:10 bofenghuang

Closing the issue given this doesn't appear to be directly a DeepSpeed bug - if this needs re-opened, please let us know or file a new bug and link this one.

loadams avatar Nov 09 '23 19:11 loadams

if you use deepspeed zero stage 2

device_map = {"": os.environ.get('LOCAL_RANK', '0')}

may be a better way

billvsme avatar Nov 30 '23 13:11 billvsme