-
Notifications
You must be signed in to change notification settings - Fork 7.2k
[tests] refactor pipeline-level quantization tests #14435
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
base: main
Are you sure you want to change the base?
Changes from all commits
b695feb
bb35ec9
d4a1ad6
5e149c4
24183ab
d5b6437
0bd18df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -302,9 +302,19 @@ def maybe_update_state_dict(self, state_dict: dict[str, Any]) -> dict[str, Any]: | |
| return state_dict | ||
|
|
||
| merged_state_dict = {**self._pending_flattened_state_dict, **state_dict} | ||
| # Tensors at the model root (e.g. Wan's `scale_shift_table`) have no module prefix and are never | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We support safetensors for TorchAO checkpoints. To do that we flatten the tensor subclasses (each quantized weight becomes qdata/scale/… entries plus metadata). On load, this is tackled using the It was surfaced when adding the test around handling sharded checkpoints. |
||
| # flattened tensor-subclass parts; torchao's unflatten helper cannot parse their names, so route | ||
| # them (and their metadata entries) around the reconstruction. | ||
| root_tensors = {k: v for k, v in merged_state_dict.items() if "." not in k} | ||
| merged_state_dict = {k: v for k, v in merged_state_dict.items() if "." in k} | ||
| metadata = self._metadata | ||
| tensor_names = json.loads(metadata["tensor_names"]) | ||
| if any("." not in name for name in tensor_names): | ||
| metadata = {**metadata, "tensor_names": json.dumps([name for name in tensor_names if "." in name])} | ||
| reconstructed_state_dict, self._pending_flattened_state_dict = unflatten_tensor_state_dict( | ||
| merged_state_dict, self._metadata | ||
| merged_state_dict, metadata | ||
| ) | ||
| reconstructed_state_dict.update(root_tensors) | ||
|
|
||
| return reconstructed_state_dict | ||
|
|
||
|
|
||
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.
These changes are for fixing the loading of sharded checkpoints in BnB (8bit).
An 8-bit bnb weight is stored as two state-dict entries that must be materialized together: the int8 weight and its SCB scale statistics. We loaded sharded checkpoints shard-by-shard, and the quantizer looked SCB up in the current shard's dict only, raising Missing quantization component 'SCB' if it wasn't there.
With the default 10GB shard size, we never hit this problem.