Skip to content

Conversation

@liangel-02
Copy link
Contributor

Summary

Updating unflatten_tensor_state_dict and flatten_tensor_state_dict to only modify tensor subclasses. Also changing naming format so that we can directly assign module parameters.

Testing
python test/prototype/safetensors/test_safetensors_support.py

@pytorch-bot
Copy link

pytorch-bot bot commented Nov 3, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/ao/3282

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

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

✅ No Failures

As of commit fd731af with merge base 9266734 (image):
💚 Looks good so far! There are no failures yet. 💚

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

@meta-cla meta-cla 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 Nov 3, 2025
@liangel-02 liangel-02 requested a review from jerryzh168 November 3, 2025 18:39
@liangel-02 liangel-02 marked this pull request as ready for review November 3, 2025 18:39
@liangel-02 liangel-02 added the topic: improvement Use this tag if this PR is an improvement (doesn't fit into any of the other categories) label Nov 3, 2025
@liangel-02 liangel-02 force-pushed the update_metadata_structure branch 3 times, most recently from 83fdbdc to bd6bbac Compare November 3, 2025 21:03
Copy link
Contributor

@jerryzh168 jerryzh168 left a comment

Choose a reason for hiding this comment

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

maybe add a test for the format as well? it's a bit surprising to see that format changes like this doesn't require any changes to the test

@liangel-02 liangel-02 force-pushed the update_metadata_structure branch 3 times, most recently from 1539983 to 22d8c3a Compare November 3, 2025 23:21
@liangel-02 liangel-02 force-pushed the update_metadata_structure branch 2 times, most recently from 1c695a1 to cb2b13e Compare November 4, 2025 00:04
result = {}

for tensor_name in tensor_names:
prefix = f"{tensor_name.rsplit('.', 1)[0]}._{tensor_name.rsplit('.', 1)[1]}_"
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: split the tensor_name separate beforehand?

module_fqn, weight_name = tensor_name.rsplit(".", 1)
...

Copy link
Contributor

@jerryzh168 jerryzh168 left a comment

Choose a reason for hiding this comment

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

looks good, although I think ideally this should be 2 PRs, future PRs should only contain a single change for easy review and clear purpose

@liangel-02 liangel-02 force-pushed the update_metadata_structure branch from cb2b13e to fd731af Compare November 4, 2025 00:56
@jerryzh168 jerryzh168 merged commit ba3ac9f into main Nov 4, 2025
18 checks passed
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. topic: improvement Use this tag if this PR is an improvement (doesn't fit into any of the other categories)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants