sparseml.sparsification package

Submodules

sparseml.sparsification.info module

Functionality related to describing availability and information of sparsification algorithms to models within in the ML frameworks.

The file is executable and will get the sparsification info for a given framework:

Compile the available setup and information for the sparsification of a model in a given framework.

positional arguments:
framework the ML framework or path to a framework file to load the

sparsification info for

optional arguments:
-h, --help

show this help message and exit

--path PATH

A full file path to save the sparsification info to. If not supplied, will print out the sparsification info to the console.

class sparseml.sparsification.info.ModifierInfo(*, name: str, description: str, type_: sparseml.sparsification.info.ModifierType = <ModifierType.misc: 'misc'>, props: List[sparseml.sparsification.info.ModifierPropInfo] = [], warnings: List[str] = None)[source]

Bases: pydantic.main.BaseModel

Class for storing information and associated metadata for a given Modifier. Extends pydantics BaseModel class for serialization to and from json in addition to proper type checking on construction.

description: str
name: str
props: List[sparseml.sparsification.info.ModifierPropInfo]
type_: sparseml.sparsification.info.ModifierType
warnings: Optional[List[str]]
class sparseml.sparsification.info.ModifierPropInfo(*, name: str, description: str, type_: str, restrictions: List[Any] = None)[source]

Bases: pydantic.main.BaseModel

Class for storing information and associated metadata for a property on a given Modifier. Extends pydantics BaseModel class for serialization to and from json in addition to proper type checking on construction.

description: str
name: str
restrictions: Optional[List[Any]]
type_: str
class sparseml.sparsification.info.ModifierType(value)[source]

Bases: enum.Enum

Types of modifiers for grouping what functionality a Modifier falls under.

act_sparsity = 'act_sparsity'
general = 'general'
misc = 'misc'
pruning = 'pruning'
quantization = 'quantization'
training = 'training'
class sparseml.sparsification.info.SparsificationInfo(*, modifiers: List[sparseml.sparsification.info.ModifierInfo] = [])[source]

Bases: pydantic.main.BaseModel

Class for storing the information for sparsifying in a given framework. Extends pydantics BaseModel class for serialization to and from json in addition to proper type checking on construction.

modifiers: List[sparseml.sparsification.info.ModifierInfo]
type_modifiers(type_: sparseml.sparsification.info.ModifierType)List[sparseml.sparsification.info.ModifierInfo][source]

Get the contained Modifiers for a specific ModifierType. :param type_: The ModifierType to filter the returned list of Modifiers by. :type type_: ModifierType :return: The filtered list of Modifiers that match the given type_. :rtype: List[ModifierInfo]

sparseml.sparsification.info.load_sparsification_info(load: str)sparseml.sparsification.info.SparsificationInfo[source]

Load the sparsification info from a file or raw json. If load exists as a path, will read from the file and use that. Otherwise will try to parse the input as a raw json str.

Parameters

load (str) – Either a file path to a json file or a raw json string.

Returns

The loaded sparsification info.

Return type

SparsificationInfo

sparseml.sparsification.info.save_sparsification_info(framework: Any, path: Optional[str] = None)[source]

Save the sparsification info for a given framework. If path is provided, will save to a json file at that path. If path is not provided, will print out the info.

Parameters
  • framework (Any) – The item to detect the ML framework for. See detect_framework() for more information.

  • path (Optional[str]) – The path, if any, to save the info to in json format. If not provided will print out the info.

sparseml.sparsification.info.sparsification_info(framework: Any)sparseml.sparsification.info.SparsificationInfo[source]

Get the available setup for sparsifying model in the given framework.

Parameters

framework (Any) – The item to detect the ML framework for. See detect_framework() for more information.

Returns

The sparsification info for the given framework

Return type

SparsificationInfo

Module contents

Functionality related to applying, describing, and supporting sparsification algorithms to models within in ML frameworks.