Lightning-AI / Lightning-AI/pytorch-lightning

--hf_deepspeed_save flag to use Hugging Face Deepspeed logic and no configure_optimizers if optimizer/scheduler defined

Open
#17,673 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

feature strategy: deepspeed
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

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.