sparseml package

Subpackages

Submodules

sparseml.base module

class sparseml.base. Framework ( value ) [source]

Bases: enum.Enum

Framework types known of/supported within the sparseml/deepsparse ecosystem

deepsparse = 'deepsparse'
keras = 'keras'
onnx = 'onnx'
pytorch = 'pytorch'
tensorflow_v1 = 'tensorflow_v1'
unknown = 'unknown'
sparseml.base. check_version ( package_name : str , min_version : Optional [ str ] = None , max_version : Optional [ str ] = None , raise_on_error : bool = True , alternate_package_names : Optional [ List [ str ] ] = None ) bool [source]
Parameters
  • package_name ( str ) – the name of the package to check the version of

  • min_version ( str ) – The minimum version for the package that it must be greater than or equal to, if unset will require no minimum version

  • max_version ( str ) – The maximum version for the package that it must be less than or equal to, if unset will require no maximum version.

  • raise_on_error ( bool ) – True to raise any issues such as not installed, minimum version, or maximum version as ImportError. False to return the result.

  • alternate_package_names ( Optional [ List [ str ] ] ) – List of alternate names to look for the package under if package_name is not found. Useful for nightly builds.

Returns

If raise_on_error, will return False if the package is not installed or the version is outside the accepted bounds and True if everything is correct.

Return type

bool

sparseml.base. detect_framework ( item : Any ) sparseml.base.Framework [source]

Detect the supported ML framework for a given item. Supported input types are the following: - A Framework enum - A string of any case representing the name of the framework

(deepsparse, onnx, keras, pytorch, tensorflow_v1)

  • A supported file type within the framework such as model files: (onnx, pth, h5, pb)

  • An object from a supported ML framework such as a model instance

If the framework cannot be determined, will return Framework.unknown :param item: The item to detect the ML framework for :type item: Any :return: The detected framework from the given item :rtype: Framework

sparseml.base. execute_in_sparseml_framework ( framework : sparseml.base.Framework , function_name : str , * args , ** kwargs ) Any [source]

Execute a general function that is callable from the root of the frameworks package under SparseML such as sparseml.pytorch. Useful for benchmarking, analyzing, etc. Will pass the args and kwargs to the callable function. :param framework: The ML framework to run the function under in SparseML. :type framework: Framework :param function_name: The name of the function in SparseML that should be run

with the given args and kwargs.

Parameters
  • args – Any positional args to be passed into the function.

  • kwargs – Any key word args to be passed into the function.

Returns

The return value from the executed function.

Return type

Any

sparseml.base. get_version ( package_name : str , raise_on_error : bool , alternate_package_names : Optional [ List [ str ] ] = None ) Optional [ str ] [source]
Parameters
  • package_name ( str ) – The name of the full package, as it would be imported, to get the version for

  • raise_on_error ( bool ) – True to raise an error if package is not installed or couldn’t be imported, False to return None

  • alternate_package_names ( Optional [ List [ str ] ] ) – List of alternate names to look for the package under if package_name is not found. Useful for nightly builds.

Returns

the version of the desired package if detected, otherwise raises an error

Return type

str

sparseml.log module

Root logging file to handle standard logging setups for the package

sparseml.log. get_main_logger ( ) logging.Logger [source]
Returns

a main logger that can be used in external scripts for logging in a standard format that is consistent with other loggers in sparseml

sparseml.log. get_nm_root_logger ( ) logging.Logger [source]
Returns

the logger used for the sparseml root package that all other loggers in that namespace are created from

sparseml.log. set_logging_level ( level : int ) [source]

Set the logging level for the MAIN and NM_ROOT loggers along with all loggers created in the sparseml namespace

Parameters

level – the log level to set; ex: logging.INFO

sparseml.version module

Functionality for storing and setting the version info for SparseML

Module contents

Tooling to help train, test, and optimize models for better performance