Lightning-AI / Lightning-AI/pytorch-lightning
--hf_deepspeed_save flag to use Hugging Face Deepspeed logic and no configure_optimizers if optimizer/scheduler defined
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 31.4k
- Forks
- 3.8k
- Avg merge
- 6d 7h
- Merged PRs (30d)
- 6
Description
### Description & Motivation
I have been a long time lightning user, but the Deepspeed integration has made it unusable, and as deepspeed is used for all model training this is a big problem.
I propose just porting over the HF Trainer deepspeed saving logic: https://github.com/huggingface/transformers/blob/main/src/transformers/trainer.py#L2352 for checkpoints as I have found the lightning logic doesn't work.
The HF Trainer logic is more battle tested and works for each stage with various model sizes. When I use lightning quite often it doesn't work making the whole training run useless. HF Trainer also always saves a pytorch_model.bin with the checkpoint and then global_step folder with the deepspeed optimizer states. This makes a lot more sense—so you do'nt have to faff about converting optimizer states if you want to use the pytorch model which is often 10% of the size anyway, so negligible to save each time.
I would also like to be able to define the optimizer and scheduler in the DS config without breaking the lightning logic, there should be a default to invalidate configure_optimizers if these are defined in the config. Most people training models like to use their own DS config with optimizer and scheduler defined and don't want to have to faff about with configure_optimizers when it can be handled by deepspeed
### Pitch
_No response_
### Alternatives
_No response_
### Additional context
_No response_
cc @borda @awaelchli
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by comparing the Hugging Face Trainer checkpoint logic at the linked trainer.py location with Lightning's existing DeepSpeed integration. Define how the --hf_deepspeed_save behavior should write pytorch_model.bin and global_step optimizer state, and how DeepSpeed-configured optimizer and scheduler settings interact with configure_optimizers; done means both flows work without breaking existing Lightning behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, pytorch
- Domain
- distributed-systems, machine-learning
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100