Lightning-AI / Lightning-AI/pytorch-lightning

configure_model with deepspeed_stage3 goes wrong

Open
#19,259 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

3rd party bug docs ver: 2.1.x
Dominant language
Python
Stars
31.4k
Forks
3.8k
Avg merge
6d 7h
Merged PRs (30d)
6

Description

### Bug description

I tried to train huggingface transformers model with deepspeed_stage3,
but when I load model with checkpoint like the code below, error occurs.

I think checkpoint and model template are totally fine, because it worked okay if I configure model in __init__.
(And it might goes wrong only with multi-GPU env?)

### What version are you seeing the problem on?

v2.1

### How to reproduce the bug

```python
def configure_model(self):
self.model = SOME_MODEL.from_pretrained(some_path, config=some_config)
```

### Error messages and logs

```
RuntimeError: Error(s) in loading state_dict for GPTJForCausalLM:
size mismatch for transformer.wte.weight: copying a param with shape torch.Size([32768, 3072]) from checkpoint, the shape in current model is torch.Size([0]).
size mismatch for transformer.h.0.ln_1.weight: copying a param with shape torch.Size([3072]) from checkpoint, the shape in current model is torch.Size([0]).
...
```

### Environment

Current environment

```
#- Lightning Component (e.g. Trainer, LightningModule, LightningApp, LightningWork, LightningFlow):
#- PyTorch Lightning Version (e.g., 1.5.0):
#- Lightning App Version (e.g., 0.5.2):
#- PyTorch Version (e.g., 2.0):
#- Python version (e.g., 3.9):
#- OS (e.g., Linux):
#- CUDA/cuDNN version:
#- GPU models and configuration:
#- How you installed Lightning(`conda`, `pip`, source):
#- Running environment of LightningApp (e.g. local, cloud):
```

### More info

_No response_

cc @borda

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 configure_model path and the SOME_MODEL.from_pretrained call, then reproduce the checkpoint load with deepspeed_stage3 in a multi-GPU environment and compare it with configuration in __init__. Done means the checkpoint loads without zero-sized parameter mismatches; the issue names no repository files or tests to run.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.