llmcompressor.transformers.compression.helpers
Functions:
-
infer_sparse_targets_and_ignores–Infers the target and ignore layers in the given model
-
infer_sparsity_structure_from_model–Determines the sparsity structure, if any exists, given the model
-
infer_sparsity_structure_from_modifiers–Determines the sparsity structure, if any exists, given the list of modifiers.
-
is_sparse_compression_target–:param module: module to check
-
tensor_follows_mask_structure–:param tensor: tensor to check
infer_sparse_targets_and_ignores
infer_sparse_targets_and_ignores(
model: Module,
sparsity_structure: str,
sparsity_threshold: float,
) -> Tuple[List[str], List[str]]
Infers the target and ignore layers in the given model to be used for sparsity compression
Parameters:
-
(modelModule) –model to check
-
(sparsity_structurestr) –sparsity structure to check against
-
(sparsity_thresholdfloat) –threshold for sparsity
Returns:
-
Tuple[List[str], List[str]]–tuple of target and ignore layers
Source code in llmcompressor/transformers/compression/helpers.py
infer_sparsity_structure_from_model
Determines the sparsity structure, if any exists, given the model
Parameters:
-
(modelModule) –model to check for sparsity structure
Returns:
-
Optional[str]–sparsity structure as a string or None
Source code in llmcompressor/transformers/compression/helpers.py
infer_sparsity_structure_from_modifiers
Determines the sparsity structure, if any exists, given the list of modifiers.
Parameters:
-
(modifiersList[Modifier]) –List of modifier instances.
Returns:
-
Optional[str]–sparsity structure as a string or None.
Source code in llmcompressor/transformers/compression/helpers.py
is_sparse_compression_target
is_sparse_compression_target(
module: Module,
sparsity_threshold: float,
sparsity_structure: str,
) -> bool
Parameters:
-
(moduleModule) –module to check
-
(sparsity_thresholdfloat) –threshold for sparsity
-
(sparsity_structurestr) –sparsity structure to check against
Returns:
-
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
Parameters:
-
(tensorTensor) –tensor to check
-
(maskstr, default:'2:4') –mask structure to check for, in the format "n:m", also accepts "unstructured" as a valid mask structure
Returns:
-
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