huggingface / huggingface/accelerate

[feature request] A more flexible `free_memory` function

Open
#925 0 comments 0 reactions 0 assignees View on GitHub
enhancement feature request
Dominant language
Python
Stars
9.9k
Forks
1.5k
Avg merge
5d 2h
Merged PRs (30d)
27

Description

After looking at the existing issues and PRs, I'm opening this feature request since I couldn't find my use case.
https://github.com/huggingface/accelerate/blob/7889ba6b6dd094e72fa222194146a40426fb3d5a/src/accelerate/accelerator.py#L1788-L1799
1. In my case, I'm using a custom cache system instead of regular dataloaders and I need to load and unload the same objects multiple times in the `Accelerator` for each iteration to free up memory. For now, I need to access the different internal objects of the `Accelerator` class individually. This could happen in different non-standard training loop (e.g. reloading a model and corresponding optimizers, ...).
2. It only needs a quick modification of the `free_memory` function. I'm not sure how you would implement that to be coherent with the whole library though.
3. This feature could be used as followed:
```python
# load cache
# prepare it with the Accelerator
for iteration in range(nb_iterations):
# take random batch from cache
# Forward pass
if iteration % reload_frequency == 0:
# unload the cache from the Accelerator to free up memory
# load new cache
# prepare it with the Accelerator
```

Thank you for this library by the way. It makes things much easier for everyone!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.