-
Notifications
You must be signed in to change notification settings - Fork 383
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests about saving/loading with accelerate
When using AccelerateMixin, the net cannot be pickled. This is caused by accelerate replacing forward methods by wrapped methods: https://github.com/huggingface/accelerate/blob/6d038e19a168f5a270bb4c535023255a0160fc10/src/accelerate/accelerator.py#L747-L753 Pickle does not know how to restore those methods and thus fails. In this PR, we're adding unit tests to check this and documentation indicating this missing feature (and pointing users towards using net.save_params instead). It is not impossible to make pickling work. We could save a copy of the original methods before they're replaced (or dig out the original function from __closure__.cell_contents) and after training restore the methods. It's however not that trivial, since preparing happens during initialize, which can be called outside of fit. Therefore, a simple context manager is not enough. Also, we do want to have acceleration during inference, so methods such as predict need to prepare and restore again. We could also try to mess with __reduce__ but that seems to be equally brittle. So maybe we just need to live with pickle not working with accelerate.
- Loading branch information
1 parent
862f205
commit d576840
Showing
3 changed files
with
65 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters