module.save_pretrained() and load_from_pretrained() implementations for xpm torch models
#110
Answered
by
VictorMorand
VictorMorand
asked this question in
Q&A
|
I have a use case where I woud like to save a torch module (which also dereives from xpm It would look like this: c_model = ModelConfig(...)
model = c_model.instance() #get the instance of the class, automatically done if in an xpm task
model.train(...)
model.save_pretrained(path)
...
#further loading
model = load_from_pretrained(path)
there is a hacky way by doing the following keys = self.C().__xpm__.__dict__['values'].keys()
config = {key: getattr(self, key) for key in keys}What would be the best way of implementing this ? if possible without having to keep track of the config and the instance separately, which I find heavy |
Answered by
VictorMorand
May 16, 2025
Replies: 1 comment 4 replies
|
The best way is to keep the configuration and save it, i.e. from experimaestro import load, save
c_model = Model()
model = c_model.instance()
save(c_model, "/my/directory")
# Load (as instance)
model = load("/my/directory", as_instance=True)Note that usually this is done within an experimental plan (so no instance there), so what is your use case? |
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
One solution can be found in #111.