Skip to content

Conversation

@GregoryComer
Copy link
Member

Summary

Implement the deserialize function in the Python FlatTensorSerializer class. This allows for loading flatbuffer data from a Python environment.

Test plan

I've added an additional test in extension/flat_tensor/test/test_serialize.py to cover the deserialize path.

@pytorch-bot
Copy link

pytorch-bot bot commented Jun 18, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/11779

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 7a33ea8 with merge base 5960a4b (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 18, 2025

self.assertEqual(segments[2].offset + segments[2].size, len(segment_data))

def test_round_trip(self) -> None:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to reviewers: I considered adding a deserialize test in the same vein as the serialize test, but it's a bit awkward to do, in that we'd need to construct a binary input without using the existing serialization logic, Could also include a pre-serialized artifact, but I think this coverage is sufficient in conjunction with the serialize test. Feel free to let me know if you want to see more coverage.

@GregoryComer GregoryComer added the release notes: none Do not include this in the release notes label Jun 18, 2025
@GregoryComer GregoryComer force-pushed the flat-tensor-deserialize branch from 1422bfe to 7a33ea8 Compare June 18, 2025 05:09
@GregoryComer GregoryComer marked this pull request as ready for review June 18, 2025 06:18
@GregoryComer GregoryComer requested a review from lucylq as a code owner June 18, 2025 06:18
Copy link
Contributor

@lucylq lucylq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you for adding this!

deserialized_payload = serializer.deserialize(Cord(serialized_data))

# Validate the deserialized payload. Since alignment isn't serialized, we need to
# do this somewhat manually.
Copy link
Contributor

@lucylq lucylq Jun 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there's currently a need to serialize the alignment(?)
It might be good to have for deserialization/general error-checking, I guess the trade-off is binary size.

if field.name not in SKIP_FIELDS:
self.assertEqual(
getattr(reference, field.name),
getattr(actual, field.name),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is nice!

@GregoryComer GregoryComer merged commit 528dce7 into pytorch:main Jun 25, 2025
96 checks passed
hinriksnaer pushed a commit to hinriksnaer/executorch that referenced this pull request Jun 26, 2025
### Summary
Implement the deserialize function in the Python FlatTensorSerializer
class. This allows for loading flatbuffer data from a Python
environment.

### Test plan
I've added an additional test in
`extension/flat_tensor/test/test_serialize.py` to cover the deserialize
path.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. release notes: none Do not include this in the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants