deepspeedai / deepspeedai/DeepSpeed
reclaiming memory for inference
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 43.1k
- Forks
- 5k
- Avg merge
- 4d 15h
- Merged PRs (30d)
- 112
Description
While https://github.com/microsoft/DeepSpeed/pull/896 solves the leak problem, ideally we should also have a new method to free all optimizer/scheduler related parts to pave wave for inference. In some environments like google colab general RAM is very scarce so every bit counts.
Here is one way to approach this:
engine, optimizer, scheduler = deepspeed.initialize(...)
# do the training and
# then before inference do:
engine.free_optimizer_and_scheduler()
optimizer = None
scheduler = None
# it's then user's responsibility to make sure they have no remaining references to optimizer/scheduler objects for them to be freed.
with a new deepspeed method:
def free_optimizer_and_scheduler(self):
self.lr_scheduler.optimizer = None
self.optimizer.optimizer = None
self.lr_scheduler = None
self.optimizer = None
That way after training is done a lion part of the general RAM used by deepspeed is reclaimed. There are probably other bits to manually clean to reclaim even more.
Let me know if it sounds good to you and I will make another PR with this feature. We can in the future extend it if need be to support other things to benefit inference.
Thank you.
@jeffra, @RezaYazdaniAminabadi
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 at the deepspeed.initialize entry point and trace the engine's optimizer and scheduler references. Define the cleanup scope needed after training, including the references shown in the issue, and verify that inference can proceed after they are released. The issue does not name specific files or tests, so those must be identified before implementation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- machine-learning
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100