llmcompressor.transformers.compression.sparsity_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:
-
model(Module) –model to check
-
sparsity_structure(str) –sparsity structure to check against
-
sparsity_threshold(float) –threshold for sparsity
Returns:
-
tuple[list[str], list[str]]–tuple of target and ignore layers
Source code in src/llmcompressor/transformers/compression/sparsity_helpers.py
infer_sparsity_structure_from_model
Determines the sparsity structure, if any exists, given the model
Parameters:
-
model(Module) –model to check for sparsity structure
Returns:
-
str | None–sparsity structure as a string or None
Source code in src/llmcompressor/transformers/compression/sparsity_helpers.py
infer_sparsity_structure_from_modifiers
Determines the sparsity structure, if any exists, given the list of modifiers.
Parameters:
-
modifiers(list[Modifier]) –List of modifier instances.
Returns:
-
str | None–sparsity structure as a string or None.
Source code in src/llmcompressor/transformers/compression/sparsity_helpers.py
is_sparse_compression_target
is_sparse_compression_target(
module: Module,
sparsity_threshold: float,
sparsity_structure: str,
) -> bool
Parameters:
-
module(Module) –module to check
-
sparsity_threshold(float) –threshold for sparsity
-
sparsity_structure(str) –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 src/llmcompressor/transformers/compression/sparsity_helpers.py
tensor_follows_mask_structure
Parameters:
-
tensor(Tensor) –tensor to check
-
mask(str, 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