Can I save/restore part of the state? #3263
-
Hi, For models like MAE or any GAN-like models, parts of the model are only used for training but not during inferring. I wonder if I can save/restore only part of the state using the checkpoint manager. E.g. my MAE trainer model comprises several smaller mae_trainer = MAE(Encoder(...), Decoder(..), ...) Later, when I use the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
Hi @davidshen84, It looks like with Orbax you can save and restore PyTrees directly, this is outlined in the following doc. As far as my understanding goes you could use the outlined methods to save the parameters you care about using an instance of The following block of code from the docs seems to provide and example: checkpointer = orbax.checkpoint.PyTreeCheckpointer()
# 'path/to/directory' should already exist, but 'checkpoint_name' folder should
# not.
# The leaves of `my_tree` may be a number of different types.
# See `PyTreeCheckpointHandler` documentation.
checkpointer.save('path/to/directory/checkpoint_name/', my_tree)
# If you want to restore any of the leaves as sharded arrays, you'll need some
# extra arguments. See `PyTreeCheckpointHandler` documentation.
restored = checkpointer.restore('path/to/directory/checkpoint_name/') |
Beta Was this translation helpful? Give feedback.
-
Of course 😊
…On Thu, 10 Aug 2023, 18:18 Peter David Fagan, ***@***.***> wrote:
Hi @davidshen84 <https://github.com/davidshen84>,
If I write a colab would you be able to accept the answer, this will help
me to get the galaxy brain badge on GitHub.
—
Reply to this email directly, view it on GitHub
<#3263 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAQBTJU6HZIPVDX4KOBAD3XUSKMTANCNFSM6AAAAAA3GSQEQU>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
Hi @peterdavidfagan ,
No worries. This document helped me a lot. I got some of my code snippet working.