llmcompressor.transformers.compression.helpers
infer_sparse_targets_and_ignores(model, sparsity_structure, sparsity_threshold)
Infers the target and ignore layers in the given model to be used for sparsity compression
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model | Module | model to check | required |
sparsity_structure | str | sparsity structure to check against | required |
sparsity_threshold | float | threshold for sparsity | required |
Returns:
Type | Description |
---|---|
Tuple[List[str], List[str]] | tuple of target and ignore layers |
Source code in llmcompressor/transformers/compression/helpers.py
infer_sparsity_structure_from_model(model)
Determines the sparsity structure, if any exists, given the model
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model | Module | model to check for sparsity structure | required |
Returns:
Type | Description |
---|---|
Optional[str] | sparsity structure as a string or None |
Source code in llmcompressor/transformers/compression/helpers.py
infer_sparsity_structure_from_modifiers(modifiers)
Determines the sparsity structure, if any exists, given the list of modifiers.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
modifiers | List[Modifier] | List of modifier instances. | required |
Returns:
Type | Description |
---|---|
Optional[str] | sparsity structure as a string or None. |
Source code in llmcompressor/transformers/compression/helpers.py
is_sparse_compression_target(module, sparsity_threshold, sparsity_structure)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module | Module | module to check | required |
sparsity_threshold | float | threshold for sparsity | required |
sparsity_structure | str | sparsity structure to check against | required |
Returns:
Type | Description |
---|---|
bool | whether or not the module is a target for sparsity compression, i.e True if it is sparse and follows the sparsity structure, else False |
Source code in llmcompressor/transformers/compression/helpers.py
tensor_follows_mask_structure(tensor, mask='2:4')
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tensor | Tensor | tensor to check | required |
mask | str | mask structure to check for, in the format "n:m", also accepts "unstructured" as a valid mask structure | '2:4' |
Returns:
Type | Description |
---|---|
bool | True if the tensor follows the mask structure, False otherwise. Note, some weights can incidentally be zero, so we check for atleast n zeros in each chunk of size m |