llmcompressor.transformers.compression.helpers
函数
-
infer_sparse_targets_and_ignores–推断模型中用于稀疏压缩的目标和忽略层
-
infer_sparsity_structure_from_model–根据模型确定稀疏结构(如果存在)。
-
infer_sparsity_structure_from_modifiers–根据修饰符列表确定稀疏结构(如果存在)。
-
is_sparse_compression_target–:param module: 要检查的模块
-
tensor_follows_mask_structure–:param tensor: 要检查的张量
infer_sparse_targets_and_ignores
infer_sparse_targets_and_ignores(
model: Module,
sparsity_structure: str,
sparsity_threshold: float,
) -> tuple[list[str], list[str]]
推断模型中用于稀疏压缩的目标层和忽略层
参数
-
(modelModule) –要检查的模型
-
(sparsity_structurestr) –要对照检查的稀疏结构
-
(sparsity_thresholdfloat) –稀疏性的阈值
返回
-
tuple[list[str], list[str]]–目标层和忽略层的元组
Source code in llmcompressor/transformers/compression/helpers.py
infer_sparsity_structure_from_model
根据模型确定稀疏结构(如果存在)。
参数
-
(modelModule) –要检查稀疏结构的模型
返回
-
str | None–稀疏结构(字符串或 None)
Source code in llmcompressor/transformers/compression/helpers.py
infer_sparsity_structure_from_modifiers
根据修饰符列表确定稀疏结构(如果存在)。
参数
-
(修饰符list[Modifier]) –修饰符实例列表。
返回
-
str | None–稀疏结构(字符串或 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
参数
-
(moduleModule) –要检查的模块
-
(sparsity_thresholdfloat) –稀疏性的阈值
-
(sparsity_structurestr) –要对照检查的稀疏结构
返回
-
bool–该模块是否是稀疏压缩的目标,即如果它是稀疏的并且遵循稀疏结构,则为 True,否则为 False
Source code in llmcompressor/transformers/compression/helpers.py
tensor_follows_mask_structure
参数
-
(tensorTensor) –要检查的张量
-
(maskstr, default:'2:4') –要检查的掩码结构,格式为“n:m”,也接受“unstructured”作为有效掩码结构
返回
-
bool–张量是否遵循掩码结构,True 则遵循,False 则不遵循。注意,某些权重可能碰巧为零,因此我们检查每个大小为 m 的块中至少有 n 个零