-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move StateDict to Haliax, clean it up a lot. #90
Open
dlwh
wants to merge
18
commits into
main
Choose a base branch
from
state_dict_in_haliax
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 13 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
0609b32
wip
dlwh 80890e8
wip state_dict serialization for haliax
dlwh d361bf7
wip
dlwh 0420a1a
add flatten_linear_layers to Linear. probably gonna move it out though
dlwh 9e4e857
this is much cleaner
dlwh f1d0c0f
tests
dlwh 68dfb87
remove old bad jax config bug
dlwh 02fc32e
oops
dlwh 54c4bfc
ok, the new stacked seems to basically work
dlwh c7a61dc
add an explicit to_torch_compatible dict
dlwh 382e405
make a public model for state
dlwh 9061cfb
wip
dlwh b64a374
Merge remote-tracking branch 'origin/main' into state_dict_in_haliax
dlwh 1799fe8
Merge remote-tracking branch 'origin/main' into state_dict_in_haliax
dlwh 4a0c35b
add docs, clean up tests some
dlwh 0ee7136
fix deprecations
dlwh c6bc2de
Merge remote-tracking branch 'origin/main' into state_dict_in_haliax
dlwh c877679
remove update_state_dict
dlwh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Serialization | ||
|
||
Haliax supports serialization of modules (including any [equinox.Module][]) to and from PyTorch-compatible | ||
state dicts using the [safetensors](https://github.com/huggingface/safetensors) library. For details on | ||
how state dicts work in PyTorch, see the [PyTorch documentation](https://pytorch.org/docs/stable/notes/serialization.html). | ||
|
||
A state dict is a Python dictionary that maps string keys to tensors. It is used to store the parameters | ||
of a model (though typically not the model's structure or hyperparameters). The keys are typically the names of the | ||
model's parameters, arranged as `.`-separated paths. For example, a model with a `conv1` layer might have a | ||
state dict with keys like `conv1.weight` and `conv1.bias`. Sequences of modules (e.g., for lists of layers) are | ||
serialize with keys like `layer.0.weight`, `layer.1.weight`, etc. | ||
|
||
|
||
## Saving a state dict | ||
|
||
To serialize a module to a Pytorch-compatible state dict, use the [haliax.state_dict.to_torch_compatible_state_dict][] | ||
function. This function takes a module and returns a state dict. To save the state dict to a file, use the | ||
[haliax.state_dict.save_state_dict][] function, which writes the state dict to a file in safetensor format. | ||
`to_torch_compatible_state_dict` flattens [haliax.nn.Linear] module Input and Output axis specs to a format that | ||
is compatible with PyTorch Linear modules (though `out_first=True` is necessary to match PyTorch's default). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(The main "draft-y" part of this PR is just the docs.