mode — Model Optimizer 0.27.1 (original) (raw)

Sparsity mode descriptor.

Classes

ExportSparseModeDescriptor Class to describe the "export_sparse" mode.
SparseGPTModeDescriptor Class to define and describe sparsification based on SparseGPT.
SparseMagnitudeModeDescriptor Class to define and describe magnitude-based sparsification.

Functions

convert_sparse_model Function for converting a model to a sparsity meta-model.
export_sparse Export a sparse model to a regular model.
restore_export_sparse Restore & export a sparse model to a regular model.
restore_sparse_model Function for restoring a previously convert model to a sparsity meta-model.
update_sparse_metadata Update subnet config to current subnet config of model.

class ExportSparseModeDescriptor

Bases: _ModeDescriptor

Class to describe the "export_sparse" mode.

The properties of this mode can be inspected via the source code.

property config_class_: type[ModeloptBaseConfig]_

Specifies the config class for the mode.

property convert_: Callable[[Module, ModeloptBaseConfig], tuple[Module, dict[str, Any]]]_

The mode’s entrypoint for converting a model.

property is_export_mode_: bool_

Specifies if this mode is an export mode.

property name_: str_

Returns the value (str representation) of the mode.

property restore_: Callable[[Module, ModeloptBaseConfig, dict[str, Any]], Module]_

The mode’s entrypoint for restoring a model.

class SparseGPTModeDescriptor

Bases: SparseMagnitudeModeDescriptor

Class to define and describe sparsification based on SparseGPT.

property config_class_: type[ModeloptBaseConfig]_

Specifies the config class for the mode.

property name_: str_

Returns the name of the mode.

property search_algorithm_: type[BaseSearcher]_

Specifies the search algorithm for the mode.

class SparseMagnitudeModeDescriptor

Bases: _ModeDescriptor

Class to define and describe magnitude-based sparsification.

property config_class_: type[ModeloptBaseConfig]_

Specifies the config class for the mode.

property convert_: Callable[[Module, ModeloptBaseConfig], tuple[Module, dict[str, Any]]]_

The mode’s entrypoint for converting a model.

property export_mode_: str | None_

The mode that corresponds to the export mode of this mode.

property name_: str_

Returns the name of the mode.

property next_modes_: set[str] | None_

Specifies the next modes for the mode.

property restore_: Callable[[Module, ModeloptBaseConfig, dict[str, Any]], Module]_

The mode’s entrypoint for restoring a model.

property search_algorithm_: type[BaseSearcher]_

Specifies the search algorithm for the mode.

property update_for_new_mode_: Callable[[Module, ModeloptBaseConfig, dict[str, Any]], None]_

The mode’s entrypoint for updating the models metadata.

property update_for_save_: Callable[[Module, ModeloptBaseConfig, dict[str, Any]], None]_

The mode’s entrypoint for updating the models metadata.

convert_sparse_model(model, config)

Function for converting a model to a sparsity meta-model.

Parameters:

Return type:

_tuple_[Module, _dict_[str, _Any_]]

export_sparse(model, config)

Export a sparse model to a regular model.

Parameters:

Return type:

_tuple_[Module, _dict_[str, _Any_]]

restore_export_sparse(model, config, metadata)

Restore & export a sparse model to a regular model.

Parameters:

Return type:

Module

restore_sparse_model(model, config, metadata)

Function for restoring a previously convert model to a sparsity meta-model.

Parameters:

Return type:

Module

update_sparse_metadata(model, config, metadata)

Update subnet config to current subnet config of model.

Parameters:

Return type:

None