Converts torch models into PyTrees for Equinox
Project description
statedict2pytree
Important
This package is still in its infancy and hihgly experimental! The code works, but it's far from perfect. With more and more iterations, it will eventually become stable and well tested. PRs and other contributions are highly welcome! :)
Info
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.
(Theoretically, you can rearrange the model in any way you like - e.g. last layer as the first layer - as long as the shapes match!)
Shape Matching? What's that?
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)
Get Started
Installation
Run
pip install statedict2pytree
Docs
Documentation will appear as soon as I have all the necessary features implemented. Until then, check out the "main.py" file for a better example.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for statedict2pytree-0.5.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a9f17be4727420f70514a7823d5c79cd5e52587c908efce19e48d33c95d2ac3 |
|
MD5 | 665c5b31c241f3dbc168c431972d8021 |
|
BLAKE2b-256 | 8aeb99f95bbd022a9c847553ee71a471e08ba062be51435fd65a8ad859466e64 |