For examples for statedict2pytree
, check out my other repository jaxonmodels.
Docs can be found here.
statedict2pytree
is a powerful tool for converting PyTorch state dictionaries to JAX pytrees, specifically for Equinox
pip install statedict2pytree
The goal of this package is to simplify the conversion from PyTorch models into JAX PyTrees (which can be used e.g. in Equinox). The way this works is by putting both models side my side and aligning the weights in the right order. Then, all statedict2pytree is doing, is iterating over both lists and matching the weight matrices.
Usually, if you declared the fields in the same order as in the PyTorch model, you don't have to rearrange anything -- but the option is there if you need it.
Currently, there is no sophisticated shape matching in place. Two matrices are considered "matching" if the product of their shape match. For example:
(8, 1, 1) and (8, ) match, because (8 _ 1 _ 1 = 8)
Some of the docstrings and the docs have been written with the help of Claude.