sparseml.pytorch package

Subpackages

Submodules

sparseml.pytorch.base module

sparseml.pytorch.base.check_torch_install(min_version: Optional[str] = '1.0.0', max_version: Optional[str] = '1.9.100', raise_on_error: bool = True)bool[source]

Check that the torch package is installed. If raise_on_error, will raise an ImportError if it is not installed or the required version range, if set, is not installed. If not raise_on_error, will return True if installed with required version and False otherwise.

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

  • max_version (str) – The maximum version for torch 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.

Returns

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

Return type

bool

sparseml.pytorch.base.check_torchvision_install(min_version: Optional[str] = None, max_version: Optional[str] = None, raise_on_error: bool = True)bool[source]

Check that the torchvision package is installed. If raise_on_error, will raise an ImportError if it is not installed or the required version range, if set, is not installed. If not raise_on_error, will return True if installed with required version and False otherwise.

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

  • max_version (str) – The maximum version for torchvision 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.

Returns

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

Return type

bool

sparseml.pytorch.base.require_torch(min_version: Optional[str] = '1.0.0', max_version: Optional[str] = '1.9.100')[source]

Decorator function to require use of torch. Will check that torch package is installed and within the bounding ranges of min_version and max_version if they are set before calling the wrapped function. See check_torch_install() for more info.

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

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

sparseml.pytorch.base.require_torchvision(min_version: Optional[str] = None, max_version: Optional[str] = None)[source]

Decorator function to require use of torchvision. Will check that torchvision package is installed and within the bounding ranges of min_version and max_version if they are set before calling the wrapped function. See check_torchvision_install() for more info.

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

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

Module contents

Functionality for working with and sparsifying Models in the PyTorch framework