Skip to content

llmcompressor.pytorch.utils.sparsification_info.module_sparsification_info

Classes:

ModuleSparsificationInfo

Bases: SparsificationInfo

Pydantic model for storing sparsification information of a torch module.

Methods:

  • from_module

    Factory method to create a ModuleSparsificationInfo object from a torch module.

  • loggable_items

    A generator that yields the loggable items of

from_module classmethod

from_module(module: Module) -> ModuleSparsificationInfo

Factory method to create a ModuleSparsificationInfo object from a torch module.

Parameters:

  • module

    (Module) –

    the module to create the ModuleSparsificationInfo object from

Returns:

Source code in llmcompressor/pytorch/utils/sparsification_info/module_sparsification_info.py
@classmethod
def from_module(cls, module: torch.nn.Module) -> "ModuleSparsificationInfo":
    """
    Factory method to create a ModuleSparsificationInfo object from a torch module.

    :param module: the module to create the ModuleSparsificationInfo object from
    :return: the ModuleSparsificationInfo object created from the module
    """
    if not isinstance(module, torch.nn.Module):
        raise ValueError(
            "Module must be a torch.nn.Module, not {}".format(type(module))
        )

    return cls(
        summary_info=SparsificationSummaries.from_module(module),
        pruning_info=SparsificationPruning.from_module(module),
        quantization_info=SparsificationQuantization.from_module(module),
    )

loggable_items

loggable_items(
    **kwargs,
) -> Generator[Tuple[str, Any], None, None]

A generator that yields the loggable items of the ModuleSparsificationInfo object.

Parameters:

  • kwargs

    additional kwargs to pass to the loggable items

Returns:

  • Generator[Tuple[str, Any], None, None]
    • the name of the loggable item - the value of the loggable item
Source code in llmcompressor/pytorch/utils/sparsification_info/module_sparsification_info.py
def loggable_items(self, **kwargs) -> Generator[Tuple[str, Any], None, None]:
    """
    A generator that yields the loggable items of
    the ModuleSparsificationInfo object.

    :param kwargs: additional kwargs to pass to the loggable items
    :return a generator that yields a tuple of:
        - the name of the loggable item
        - the value of the loggable item
    """
    for info in [self.summary_info, self.pruning_info, self.quantization_info]:
        yield from info.loggable_items(**kwargs)