Skip to content

llmcompressor.modifiers.interface

ModifierInterface

Bases: ABC

Defines the contract that all modifiers must implement

Source code in src/llmcompressor/modifiers/interface.py
class ModifierInterface(ABC):
    """
    Defines the contract that all modifiers must implement
    """

    @property
    @abstractmethod
    def initialized(self) -> bool:
        """
        :return: True if the modifier has been initialized
        """
        raise NotImplementedError()

    @property
    @abstractmethod
    def finalized(self) -> bool:
        """
        :return: True if the modifier has been finalized
        """
        raise NotImplementedError()

    @abstractmethod
    def initialize(self, state: State, **kwargs):
        """
        Initialize the modifier

        :param state: The current state of the model
        :param kwargs: Additional keyword arguments
            for modifier initialization
        """
        raise NotImplementedError()

    @abstractmethod
    def finalize(self, state: State, **kwargs):
        """
        Finalize the modifier

        :param state: The current state of the model
        :param kwargs: Additional keyword arguments for
            modifier finalization
        """
        raise NotImplementedError()

    @abstractmethod
    def update_event(self, state: State, event: Event, **kwargs):
        """
        Update the modifier based on the event

        :param state: The current state of the model
        :param event: The event to update the modifier with
        :param kwargs: Additional keyword arguments for
            modifier update
        """
        raise NotImplementedError()

finalized abstractmethod property

Returns:

Type Description
bool

True if the modifier has been finalized

initialized abstractmethod property

Returns:

Type Description
bool

True if the modifier has been initialized

finalize(state, **kwargs) abstractmethod

Finalize the modifier

Parameters:

Name Type Description Default
state State

The current state of the model

required
kwargs

Additional keyword arguments for modifier finalization

{}
Source code in src/llmcompressor/modifiers/interface.py
@abstractmethod
def finalize(self, state: State, **kwargs):
    """
    Finalize the modifier

    :param state: The current state of the model
    :param kwargs: Additional keyword arguments for
        modifier finalization
    """
    raise NotImplementedError()

initialize(state, **kwargs) abstractmethod

Initialize the modifier

Parameters:

Name Type Description Default
state State

The current state of the model

required
kwargs

Additional keyword arguments for modifier initialization

{}
Source code in src/llmcompressor/modifiers/interface.py
@abstractmethod
def initialize(self, state: State, **kwargs):
    """
    Initialize the modifier

    :param state: The current state of the model
    :param kwargs: Additional keyword arguments
        for modifier initialization
    """
    raise NotImplementedError()

update_event(state, event, **kwargs) abstractmethod

Update the modifier based on the event

Parameters:

Name Type Description Default
state State

The current state of the model

required
event Event

The event to update the modifier with

required
kwargs

Additional keyword arguments for modifier update

{}
Source code in src/llmcompressor/modifiers/interface.py
@abstractmethod
def update_event(self, state: State, event: Event, **kwargs):
    """
    Update the modifier based on the event

    :param state: The current state of the model
    :param event: The event to update the modifier with
    :param kwargs: Additional keyword arguments for
        modifier update
    """
    raise NotImplementedError()