-
Notifications
You must be signed in to change notification settings - Fork 37
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
feat(serialization): Serialize and deserialize meta tensors #70
Conversation
lgtm, will extend the test suite to check the new behavior |
This may warrant bumping up to a new tensorizer data version when meta tensors are encountered during serialization, since trying to deserialize a tensor with 0 |
sharing informative blurb from DM with Eta. out of scope for this PR, but should probably document this more formally in the future (e.g. add to the tensorizer readme) Tensorizer has a code version and a data version
|
To add to this quote from me (hiya), this is the current de facto state for compatibility, not de jure; newer versions of tensorizer are not guaranteed to have the same level of backwards compatibility in the serializer or deserializer (though any change that breaks it will probably be a major version bump). This isn't documented because we have never agreed on a rigorous policy for data version compatibility, but what could be documented at the moment is a table of extant tensorizer versions and their possible output data versions + possible input data versions. |
# Conflicts: # CHANGELOG.md # tensorizer/_version.py # tensorizer/serialization.py
This prevents files containing meta tensors from being misinterpreted by older versions of tensorizer that do not support them. This adds a feature_flags bitfield to the tensorizer file header that currently records whether a file is encrypted or not, as the previous way of recording encryption wasn't compatible with new data versions that may only be required part-way through serialization.
Previously, only the lazy_load setting was varied correctly. This also tests encryption with meta tensors when possible.
@wbrown Merged in the latest changes from In data version 4, the previously-unused "file hash" field in the tensorizer file header is now a "feature flags" field, because the old way of indicating encryption metadata wasn't compatible with newer data versions that aren't known up-front, at the beginning of serialization. I also fixed some broken tests and fixed a bug that was preventing meta tensor deserialization from working correctly in |
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.
Great job. 👍
Serialization and Deserialization of Meta Tensors
This change allows serialization of tensors on the
meta
device. A brief explanation of meta tensors from the documentation fortorch.Tensor.is_meta
is:As such, when serialized, they have a
data_length
of 0 and no presence in the file beyond a tensor header, but they are recorded with a realshape
. When deserialized, they are yielded as zero-filled tensors of thatshape
on the requested device.When verifying a deserialized meta tensor with
verify_hash=True
(orTensorDeserializer.verify_module()
), only the header hashes are checked, as there is no tensor data included in the original CRC32 to compare against. Verifying that a zero-filled tensor is still zero-filled can be achieved manually withnot torch.any(tensor)
, which returnsTrue
for tensors of all zeroes andFalse
if any elements are non-zero, and is more efficient than computing a CRC32.There is room to adjust the implementation to provide an option to deserialize meta tensors back onto the meta device if desired instead of always zero-filling them. Yielding meta tensors would allow more flexibility for the end user.