Efficient Ways for Saving and Loading weights
See original GitHub issueI’m sorry if it’s not the right place as I could not find the discussions or forum page.
I was wondering what are some of the most efficient ways to save and load models (also verify it’s properly loaded into GPU)?
1, In the docs, its given as save_the_model using Tensorflow 2. I also understand that the weights of haiku network are stored in a dictionary, as an example
{'linear': {'b': ndarray(..., shape=(300,), dtype=float32),
'w': ndarray(..., shape=(28, 300), dtype=float32)},
'linear_1': {'b': ndarray(..., shape=(100,), dtype=float32),
'w': ndarray(..., shape=(1000, 100), dtype=float32)}}
Does haiku have some inbuilt function to save and load models? It becomes crucial in transfer learning tasks. Thanks in advance,
Issue Analytics
- State:
- Created 2 years ago
- Comments:6
Top Results From Across the Web
Save and load models | TensorFlow Core
Manually save weights ... To save weights manually, use tf.keras.Model.save_weights . By default, tf.keras —and the Model.save_weights method in ...
Read more >How to Save and Load Your Keras Deep Learning Model
The model and weight data is loaded from the saved files, and a new model is created. It is important to compile the...
Read more >Everything You Need To Know About Saving Weights In ...
We either save the learnt weights or the entire model so that we could ... will now learn 2 of the widely known...
Read more >Save and load models in Tensorflow - GeeksforGeeks
Now you can simply save the weights of all the layers using the save_weights() method. It saves the weights of the layers contained...
Read more >Saving and loading models in TensorFlow - KDnuggets
Saving your models to maximize reusability is key for efficient ... Now to save the weights only using the simple way, you just...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi @VIGNESHinZONE , in general we recommend keeping a copy of your Python code which defines your model, and saving weights after training to disk. This provides the most flexibility. You can save weights produced by Haiku using pickle (https://colab.research.google.com/gist/tomhennigan/77a7e4ea04d716e9650bc54acf26f468/saving-and-loading-parameters-using-pickle.ipynb).
The integration with TensorFlow is an example of how to save the implementation of your model (e.g. the operations required to execute your neural network) as a TensorFlow graph, which is a suitable long term serialisation format for ML models. In general the best way to save the implementation of your model is to keep a copy of your Python code. In some situations (e.g. production serving) it is useful to have an intermediate format (like TF graphs) instead.
Haiku itself doesn’t do anything special to support pmap/vmap. The key idea with Haiku is that once you’ve
hk.transform
ed your function it is a “pure function” and you can use this directly withjax.pmap
etc.For an example of data parallel training with pmap see our resnet/imagenet example https://github.com/deepmind/dm-haiku/blob/master/examples/imagenet/train.py. In there the
train_step
function is parallel mapped across all available GPUs. You might observe that in this code we use Haiku to define aforward
function with our neural net, and the rest is pure JAX with some other libraries in our ecosystem (e.g. optax for optimization).As a meta point, its probably worth opening new issues for different questions to help other users who are searching.