deepspeedai / deepspeedai/DeepSpeed

Deepspeed Zero3 resume training with Huggingface Trainer Failed

Open
#7,436 0 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

Hello,

When I try to resume training for a huggingface PEFT model, with the deepspeed launcher and the same number of gpus (8 gpus on the same node), I got lora size mismatch:

lora_weight = lora_B.weight @ lora_A.weight

  File "lib/python3.10/site-packages/torch/nn/modules/module.py", line 1561, in _call_impl
RuntimeError: size mismatch, got input (18944), mat (18944x8), vec (0)

Here's how I launch the training script

deepspeed src/train.py \
    ...
    --deepspeed_config zero3.json

Here's what's in the train.py:

training_args = TrainingArguments(
        output_dir=output_dir,
        overwrite_output_dir=True,
        per_device_train_batch_size=args.batch_size,
        per_device_eval_batch_size=args.batch_size,
        dataloader_num_workers=1,
        num_train_epochs=3,

        gradient_accumulation_steps=16,
        save_total_limit=10,
        learning_rate=2e-4,
        weight_decay=0.,
        warmup_ratio=0.03,
        lr_scheduler_type="cosine",
        save_strategy="best",
        metric_for_best_model = "loss",
        # logging_steps=4,
        logging_steps=16,
        do_eval=True,
        eval_strategy='steps',
        eval_steps=1000,
        bf16=True,
        tf32=False,
        gradient_checkpointing=True,
        gradient_checkpointing_kwargs={"use_reentrant": False},
        report_to=args.report_to,
        remove_unused_columns=False,
        deepspeed=args.deepspeed_config
    )

model and dataloader initialization etc, no deepspeed engine was called here...

    logging.info("Building trainer...")
    trainer = MultimodalLlamaTrainer(model=model_stack['model'],
                                     tokenizer=model_stack['tokenizer'],
                                     group_by_modality_length=True,
                                     args=training_args,
                                     **data_module)
    
    logging.info("Starting training...")
    if list(pathlib.Path(training_args.output_dir).glob("checkpoint-*")):
        trainer.train(resume_from_checkpoint=True)
    else:
        trainer.train()

Here's what's in my checkpoint dir:
Image

When I use the script to train from scratch, it works perfectly. When I try to resume training, the model loaded successfully, but eventually got lora size mismatch. I can confirm that I did not change any configurations. How could I fix this?

Thanks a lot!

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 resume_from_checkpoint path in train.py and the referenced zero3.json configuration. Reproduce the failure using the provided DeepSpeed command and checkpoint setup, then compare resume behavior with training from scratch. Done means resuming the same PEFT training run completes without the reported LoRA size mismatch.

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.