-
Notifications
You must be signed in to change notification settings - Fork 2
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
Support for targets
and ignore
in Sparsity Compressors
#182
base: main
Are you sure you want to change the base?
Conversation
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.
I'm not sure how/if this is related to #822 (it's listed as a dependency)
- Doesn't this list of targets need to be accounted for during decompression?
- Don't these changes throw away any weights which are not targeted for sparse compression?
src/compressed_tensors/compressors/model_compressors/model_compressor.py
Outdated
Show resolved
Hide resolved
src/compressed_tensors/compressors/model_compressors/model_compressor.py
Outdated
Show resolved
Hide resolved
src/compressed_tensors/compressors/model_compressors/model_compressor.py
Outdated
Show resolved
Hide resolved
400c6c3
to
e5bfd8a
Compare
Point 1: Decompression takes care of that using COMPRESSION_PARAM_NAMES It is listed as a dependency for #822 because without this we cannot enable sparse compression + quantization compression. These changes are needed for #822 to work fine. |
…ly.py Signed-off-by: Rahul Tuli <[email protected]>
Add: tests for get_nested_weight_mappings Signed-off-by: Rahul Tuli <[email protected]>
Signed-off-by: Rahul Tuli <[email protected]>
1a7cdba
to
a528334
Compare
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.
LGTM!
@@ -97,8 +107,10 @@ def decompress( | |||
:param device: device to load decompressed weights onto | |||
:return: iterator for generating decompressed weights | |||
""" | |||
weight_mappings = get_nested_weight_mappings( | |||
path_to_model_or_tensors, self.COMPRESSION_PARAM_NAMES | |||
weight_mappings, other_params = get_nested_weight_mappings( |
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.
nit: use a more descriptive variable name for other_params
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.
Done!
model_path: str, params_to_nest: List[str] | ||
) -> Dict[str, Dict[str, str]]: | ||
model_path: str, params_to_nest: List[str], return_other_params: bool = False | ||
) -> Union[NestedWeightMappingType, Tuple[NestedWeightMappingType, WeightMappingType]]: |
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.
Can you also update this docstring to indicate what the output is expected to look like when return_other_params is True?
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.
Updated!
nested_weight_mappings[dense_param][param_name] = weight_mappings[key] | ||
nested_weight_mappings[dense_param][param_name] = file_location | ||
matched = True | ||
if not matched: |
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.
In what cases would we not have a match? Why do we need the other_params dictionary if the output from decompress is used to replace weights?
compressed-tensors/src/compressed_tensors/compressors/model_compressors/model_compressor.py
Line 306 in 525ef3a
self._replace_weights(dense_gen, model) |
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.
decompress has to return uncompressed_params from the safetensors file as well, because those also must be populated in the original potentially empty model. think of cases where we also have quantization in the mix, things like weight_scale must also be populated
We do not have a match for all the uncompressed_params, again things like scales
return name.endswith(".weight") | ||
|
||
return ( | ||
name.endswith(".weight") and name[: -(len(".weight"))] in expanded_targets |
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.
len(".weight") can be hardcoded to the actual length. Should also add that it comes from len(".weight")
This PR introduces support for using
targets
andignore
in sparsity compressors. It has been tested against thellm-compressor
repository at commita47137d8
(onmain
).Changes Made
BaseSparsity.compress(...)
methods to accept a newcompression_targets
argument.ModelCompressor
to directly populate thecompression_targets
argument.Verification
The functionality was verified using the following script:
Verification Script
The script passes successfully without any assertions.
Script Output