feat: enable save/load after recovery without additional steps#619
feat: enable save/load after recovery without additional steps#619psyberck wants to merge 9 commits into
Conversation
Not up to standards ⛔🔴 Issues
|
| Category | Results |
|---|---|
| Security | 3 high |
🟢 Metrics 12 complexity · 0 duplication
Metric Results Complexity 12 Duplication 0
TIP This summary will be updated as you push new changes. Give us feedback
|
Hi @psyberck! Thank you for your contribution! I've run the tests. Please take a look before we jump into any review :) |
|
Hey @sdiazlor , can you help kindly re-run the tests? There seems some network failures during the tests: |
|
Sure thing! I ran them again :) |
|
This PR has been inactive for 10 days and is now marked as stale. |
simlang
left a comment
There was a problem hiding this comment.
Thanks for looking at this! I left a view requests :)
|
Hi @psyberck! When you have time, could you take a look at the comments? :) |
|
This PR has been inactive for 10 days and is now marked as stale. |
8975c49 to
81ca7d0
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 81ca7d0. Configure here.
|
This PR has been inactive for 10 days and is now marked as stale. |
|
Closing this PR due to inactivity. Please reopen it or create a new PR if this is still relevant. |
|
Hi @psyberck, sorry for the delay, would it be possible to review the conflicts :) |
…: get_save_before_smash_dir
…'s weights for "save_before_apply" algos
81ca7d0 to
aec268e
Compare
|
This PR has been inactive for 10 days and is now marked as stale. It will be closed in 7 days if there is no further activity. |
|
Could the errors be fixed? :) |
|
|
||
|
|
||
| class PERPRecoverer(PrunaAlgorithmBase): | ||
| class PERPRecoverer(PrunaAlgorithmBase, metaclass=ABCMeta): |
There was a problem hiding this comment.
we don't use this anywhere else in pruna, to keep it consistent we can remove this
|
|
||
| super().__init__() # self.adapters need to be set before calling get_hyperparameters | ||
|
|
||
| @property |
There was a problem hiding this comment.
please also revert this, to keep it consistent with the rest of the code
|
|
||
| def post_apply_hook(self, model: Any, smash_config: SmashConfig): | ||
| """ | ||
| Override to run side effects after the algorithm has been applied. |
There was a problem hiding this comment.
can you please change the docstring to what the override does specifically here?
| ori_save_fns = smash_config.save_fns[:] | ||
| smash_config.save_fns = [fn for fn in smash_config.save_fns if fn != SAVE_FUNCTIONS.save_before_apply.name] | ||
| # Re-save with recovered weights | ||
| shutil.rmtree(model_path, ignore_errors=True) |
There was a problem hiding this comment.
i'm not super comfortable with ignoring errors. Is there a particular reason why you went for this - otherwise i would prefer to at least log something if something went wrong
| smash_config.save_fns = [fn for fn in smash_config.save_fns if fn != SAVE_FUNCTIONS.save_before_apply.name] | ||
| # Re-save with recovered weights | ||
| shutil.rmtree(model_path, ignore_errors=True) | ||
| save_pruna_model(model, model_path, smash_config) |
There was a problem hiding this comment.
do you think it's possible to first save the new pruna model before removing the old one? if something goes wrong in the save here at least we didn't lose the original model
so i guess the order would be:
save new model
remove old model
move new model to the location of the old one
| from pruna.algorithms.base.pruna_base import PrunaAlgorithmBase | ||
| from pruna.algorithms.global_utils.recovery.perp_recoverer import PERPRecoverer | ||
|
|
||
| class FakeRecoverer(PERPRecoverer): |
There was a problem hiding this comment.
i like the idea. but i would feel safer, if we actually use the smash-workflow instead of re-implementing the workflow in the test.
you could use monkeypatching to make these overrides and then add an algorithm which uses saving before apply to test things and finally call smash with this algorithm + monkeypatched PERPRecoverer

Description
Extend save and load to also allow saving and loading after recovery without additional steps.
Related Issue
Fixes #603
Type of Change
Testing
uv run pytest -m "cpu and not slow")For full setup and testing instructions, see the Contributing Guide.
Checklist
Thanks for contributing to Pruna! We're excited to review your work.
New to contributing? Check out our Contributing Guide for everything you need to get started.
First Prune (1-year OSS anniversary)
First Prune marks one year of Pruna’s open-source work. During the initiative window, qualifying merged contributions count toward First Prune. You can earn credits for our performance models via our API.
If you’d like your contribution to count toward First Prune, here’s how it works: