deepspeedai / deepspeedai/DeepSpeed
[performance] fusing zero.Init and pretrained weights loading
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 43.1k
- Forks
- 5k
- Avg merge
- 4d 15h
- Merged PRs (30d)
- 112
Description
I'm thinking there should be some kind of fused zero.Init and pretrained weights model loading function.
Currently with zero.Init we:
- partition the model and scatter the weights and then for each layer:
- gather the weights of one layer
- load weights of that layer
- scatter the weights of that layer
So gather+scatter happens 3 times, rather than 1.
this feels wasteful and probably does add quite an overhead for large models.
So perhaps there should be a way to hook torch.load into zero.Init. I haven't thought it through, but wanted to start the discussion.
edit: pt-1.9.0/1.9.1 now supports postponed module init where no storage is materialized until it's needed:
https://pytorch.org/tutorials/prototype/skip_param_init.html#implementation-details
So if this is used the solution can be made much simpler by not needing zero.Init (which forces the first wasteful scatter+gather) and perform the first scattering during load_state_dict.
checkpoint loading: need to investigate this one too in the same context of allocating and scattering weights only once (probably need a separate issue to track this)
Here is the corresponding issue on the HF side: https://github.com/huggingface/transformers/issues/12273
Thank you.
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 reading the zero.Init flow alongside torch.load and load_state_dict, then trace the current gather, weight loading, and scatter sequence described in the issue. Compare the proposed path with PyTorch's postponed module initialization. Done means the design and implementation avoid redundant weight movement during pretrained loading, with checkpoint loading considered separately as noted.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, pytorch
- Domain
- distributed-systems, machine-learning, performance
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100