Skip to content
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

Safe serialization #116

Merged
merged 13 commits into from
Mar 13, 2024
Merged

Safe serialization #116

merged 13 commits into from
Mar 13, 2024

Conversation

dacorvo
Copy link
Collaborator

@dacorvo dacorvo commented Mar 12, 2024

This extends the QModuleMixin class to support two new serialization mode (in addition to the default Pickle mode):

@dacorvo dacorvo force-pushed the flattened_state_dict branch from 3076298 to 0267158 Compare March 12, 2024 16:47
@dacorvo dacorvo force-pushed the flattened_state_dict branch 2 times, most recently from 81c79a9 to 54b62ab Compare March 12, 2024 16:58
dacorvo added 8 commits March 12, 2024 18:07
The docstring also explains why this method is required.
Now that activations are always quantized per-tensor, the shape of
the input and output scales is always a scalar.
This will help serialization.
We make sure the parameters are serialized as string to be compatible
with the stricter serialization formats.
@dacorvo dacorvo force-pushed the flattened_state_dict branch from 54b62ab to 52a9455 Compare March 12, 2024 17:07
dacorvo added 5 commits March 13, 2024 08:59
This will allow to support other serializers than Pickle.
This also removes the need to force assignment when loading a state_dict.
Flattened tensors meta is serialized using only strings, which are
compatible with Abstract Syntax Trees evluation for converting back
to python generic types.
The only exception is qtype, for which we use a custom helper.
This makes QModuleMixin serialization compatible with the weights_only
parameter of torch.load.
Note that this does NOT make QTensor compatible with safe serialization,
as we don't override the pickle code used when directly saving QTensor
and it uses its own representation of flattened tensors using non-primitive
types.
@dacorvo dacorvo force-pushed the flattened_state_dict branch from 52a9455 to 55e15b0 Compare March 13, 2024 08:10
@dacorvo dacorvo merged commit 661336d into main Mar 13, 2024
3 checks passed
@dacorvo dacorvo deleted the flattened_state_dict branch March 13, 2024 08:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incompatible with safetensors serialization Incompatible with torch.load(...,weights_only=True)
1 participant