sparsezoo.objects package

Submodules

sparsezoo.objects.base module

Base objects for working with the sparsezoo

class sparsezoo.objects.base.BaseObject(created: Optional[str] = None, modified: Optional[str] = None, **kwargs)[source]

Bases: object

A sparse zoo base object

Parameters
  • created – the date created

  • modified – the date modified

property created

the date created

Type

return

dict()Dict[source]
Returns

The object as a dictionary

property modified

the date modifed

Type

return

sparsezoo.objects.data module

Code related to sample data in the sparsezoo

class sparsezoo.objects.data.Data(name: str, model_metadata: sparsezoo.objects.metadata.ModelMetadata, **kwargs)[source]

Bases: sparsezoo.objects.file.File

Sample data for a given model

Parameters
  • name – The name/type of sample data

  • model_metadata – Metadata for the model the data belongs to

dataset()sparsezoo.utils.data.Dataset[source]

A dataset for interacting with the sample data. If the data is not found on the local disk, will automatically download.

Returns

The created dataset from the sample data files

loader(batch_size: int = 1, iter_steps: int = 0, batch_as_list: bool = True)sparsezoo.utils.data.DataLoader[source]

A dataloader for interfacing with the sample data in a batched format.

Parameters
  • batch_size – the size of the batches to create the loader for

  • iter_steps – the number of steps (batches) to create. Set to -1 for infinite, 0 for running through the loaded data once, or a positive integer for the desired number of steps

  • batch_as_list – True to return multiple inputs/outputs/etc within the dataset as lists, False for an ordereddict

Returns

The created dataloader from the sample data files

property name

The name/type of sample data

Type

return

sample_batch(batch_index: int = 0, batch_size: int = 1, batch_as_list: bool = True)Union[List[numpy.ndarray], Dict[str, numpy.ndarray]][source]

Get a sample batch of data from the data loader

Parameters
  • batch_index – the index of the batch to get

  • batch_size – the size of the batches to create the loader for

  • batch_as_list – True to return multiple inputs/outputs/etc within the dataset as lists, False for an ordereddict

Returns

The sample batch for use with the model

sparsezoo.objects.downloadable module

Code related to a downloadable interface

class sparsezoo.objects.downloadable.Downloadable(folder_name: str, override_parent_path: Optional[str] = None, **kwargs)[source]

Bases: object

Downloadable interface with a default folder and file name

Parameters
  • folder_name – Name of the folder to save the downloads under

  • override_parent_path – Path to override the default save path for where to save the folder and downloads at

property dir_path

The local path to download files into. Appends the folder_name to one of the following in order of resolution: [override_parent_path, SPARSEZOO_MODELS_PATH env variable, ~/.cache/sparszoo]

Type

return

download(overwrite: bool = False, refresh_token: bool = False, show_progress: bool = True)[source]
property folder_name

Name of the folder to save the downloads under

Type

return

property override_parent_path

Path to override the default save path for where to save the folder and downloads at

Type

return

sparsezoo.objects.file module

Code related to files as stored for the sparsezoo as well a interacting with them such as downloading

class sparsezoo.objects.file.File(model_metadata: Union[Dict, sparsezoo.objects.metadata.ModelMetadata], file_id: str, display_name: str, file_type: str, operator_version: Optional[str], release_version: Union[Dict, sparsezoo.objects.release_version.ReleaseVersion], checkpoint: bool, md5: str, file_size: int, downloads: int, url: Optional[str] = None, child_folder_name: Optional[str] = None, override_folder_name: Optional[str] = None, override_parent_path: Optional[str] = None, **kwargs)[source]

Bases: sparsezoo.objects.base.BaseObject, sparsezoo.objects.downloadable.Downloadable

A model repo file.

Parameters
  • model_metadata – The metadata of the model the file belongs to

  • file_id – Id of the file as stored in the cloud

  • display_name – The file name and extension

  • file_type – The type of file the object represents

  • operator_version – Version of the file such as onnx OPSET for onnx files

  • release_version – The Release Version of the file, as a Dict or ReleaseVersion

  • checkpoint – True if the model is a checkpoint file (for use with transfer learning flows), False otherwise

  • md5 – The md5 hash for the file as stored in the cloud

  • file_size – The size of the file as stored in the cloud

  • downloads – The amount of times a download has been requested for this file

  • url – The signed url to retrieve the file

  • child_folder_name – A child folder, if any, to store this file under locally

  • override_folder_name – Override for the name of the folder to save this file under

  • override_parent_path – Path to override the default save path for where to save the parent folder for this file under

check_download(overwrite: bool = False, refresh_token: bool = False, show_progress: bool = True)[source]

Check if the file has been downloaded, if not then call download()

Parameters
  • overwrite – True to overwrite any previous file, False otherwise

  • refresh_token – True to refresh the auth token, False otherwise

  • show_progress – True to print tqdm progress, False otherwise

property checkpoint

True if the model is a checkpoint file (for use with transfer learning flows), False otherwise

Type

return

property display_name

The file name and extension

Type

return

download(overwrite: bool = False, refresh_token: bool = False, show_progress: bool = True)[source]

Downloads a sparsezoo file.

Parameters
  • overwrite – True to overwrite any previous file, False otherwise

  • refresh_token – True to refresh the auth token, False otherwise

  • show_progress – True to print tqdm progress, False otherwise

property downloaded

True if the file has already been downloaded, False otherwise

Type

return

downloaded_path()str[source]
Returns

The local path to the downloaded file. Returns the same value as path, but if the file hasn’t been downloaded then it will automatically download

property downloads

The amount of times a download has been requested for this file

Type

return

property file_id

Id of the file as stored in the cloud

Type

return

property file_size

The size of the file as stored in the cloud

Type

return

property file_type

The type of file the object represents

Type

return

property file_type_card

True if the file type is a card, False otherwise

Type

return

property file_type_data

True if the file type is sample data, False otherwise

Type

return

property file_type_data_inputs

True if the file type is the input sample data, False otherwise

Type

return

property file_type_data_labels

True if the file type is the labels sample data, False otherwise

Type

return

property file_type_data_originals

True if the file type is the original sample data, False otherwise

Type

return

property file_type_data_outputs

True if the file type is the output sample data, False otherwise

Type

return

property file_type_framework

True if the file type is a framework file, False otherwise

Type

return

property file_type_onnx

True if the file type is onnx, False otherwise

Type

return

property file_type_onnx_gz

True if the file type is a gzipped onnx, False otherwise

Type

return

property file_type_recipe

True if the file type is a recipe, False otherwise

Type

return

property md5

The md5 hash for the file as stored in the cloud

Type

return

property model_metadata

The metadata of the model the file belongs to

Type

return

property operator_version

Version of the file such as onnx OPSET for onnx files

Type

return

property path

The path for where this file is (or can be) downloaded to

Type

return

property release_version

the file’s release version

Type

return

property url

The signed url to retrieve the file.

Type

return

class sparsezoo.objects.file.FileTypes(value)[source]

Bases: enum.Enum

Types of files available in the sparsezoo

CARD = 'card'
DATA_INPUTS = 'inputs'
DATA_LABELS = 'labels'
DATA_ORIGINALS = 'originals'
DATA_OUTPUTS = 'outputs'
FRAMEWORK = 'framework'
ONNX = 'onnx'
ONNX_GZ = 'onnx_gz'
RECIPE = 'recipe'

sparsezoo.objects.metadata module

Code related to metadata for models as stored in the sparsezoo

class sparsezoo.objects.metadata.ModelMetadata(domain: str, sub_domain: str, architecture: str, sub_architecture: Optional[str], framework: str, repo: str, dataset: str, training_scheme: Optional[str], sparse_name: str, sparse_category: str, sparse_target: Optional[str], release_version: sparsezoo.objects.release_version.ReleaseVersion, model_id: str, base_model: str, user_id: str, **kwargs)[source]

Bases: sparsezoo.objects.base.BaseObject, sparsezoo.requests.base.ModelArgs

Metadata to describe a model as stored in the sparsezoo

Parameters
  • domain – The domain of the model the object belongs to; e.g. cv, nlp

  • sub_domain – The sub domain of the model the object belongs to; e.g. classification, segmentation

  • architecture – The architecture of the model the object belongs to; e.g. resnet_v1, mobilenet_v1

  • sub_architecture – The sub architecture (scaling factor) of the model the object belongs to; e.g. 50, 101, 152

  • framework – The framework the model the object belongs to was trained on; e.g. pytorch, tensorflow

  • repo – The source repo for the model the object belongs to; e.g. sparseml, torchvision

  • dataset – The dataset the model the object belongs to was trained on; e.g. imagenet, cifar10

  • training_scheme – The training scheme used on the model the object belongs to if any; e.g. augmented

  • sparse_name – The name describing the sparsification of the model the object belongs to, e.g. base, pruned, pruned_quant

  • sparse_category – The degree of sparsification of the model the object belongs to; e.g. none, conservative (~100% baseline metric), moderate (>=99% baseline metric), aggressive (<99% baseline metric)

  • sparse_target – The deployment target of sparsification of the model the object belongs to; e.g. edge, deepsparse, deepsparse_throughput, gpu

  • release_version – The sparsezoo release version for the model

  • model_id – The id for the model as stored in the cloud

  • base_model – The id of the base model as stored in the cloud

  • user_id – The id of the user who uploaded the model as stored in the cloud

property base_model

The id of the base model as stored in the cloud

Type

return

property model_id

The id for the model as stored in the cloud

Type

return

property user_id

The id of the user who uploaded the model as stored in the cloud

Type

return

sparsezoo.objects.model module

Code related to a model from the sparsezoo

class sparsezoo.objects.model.Model(display_name: str, display_description: str, files: Optional[List[Dict[str, Any]]] = None, recipes: Optional[List[Dict[str, Any]]] = None, results: Optional[List[Dict[str, Any]]] = None, tags: Optional[List[Dict[str, Any]]] = None, user: Optional[Dict[str, Any]] = None, release_version: Optional[Dict[str, Any]] = None, override_folder_name: Optional[str] = None, override_parent_path: Optional[str] = None, **kwargs)[source]

Bases: sparsezoo.objects.downloadable.Downloadable, sparsezoo.objects.metadata.ModelMetadata

A model repo model

Parameters
  • display_name – the display name for the model

  • display_description – the description for the model

  • files – a list of model repo files for this model

  • recipes – a list of model repo recipes for this model

  • results – a list of model repo results for this model

  • tags – a list of model repo tags for this model

  • user – the model repo user who uploaded this model

  • release_version – a model repo release version this model was released with

  • override_folder_name – Override for the name of the folder to save this file under

  • override_parent_path – Path to override the default save path for where to save the parent folder for this file under

property card_file

The markdown card representing info about the model

Type

return

property data

A dictionary containing all of the Data objects for this model

Type

return

property data_inputs

sample numpy data for inputs into the model

Type

return

property data_labels

sample numpy data for labels for a given input

Type

return

data_loader(batch_size: int = 1, iter_steps: int = 0, batch_as_list: bool = True)sparsezoo.utils.data.DataLoader[source]

Create a data loader containing all of the available data for this model

Parameters
  • batch_size – the size of batches to create for the iterator

  • iter_steps – the number of steps (batches) to create. Set to -1 for infinite, 0 for running through the loaded data once, or a positive integer for the desired number of steps

  • batch_as_list – True to create the items from each dataset as a list, False for an ordereddict

Returns

The created data loader

property data_originals

sample numpy data as originals before any pre processing is applied to the data to create the inputs for the model

Type

return

property data_outputs

sample numpy data recorded as outputs from the model for a given input

Type

return

property display_description

the description for the model

Type

return

property display_name

the display name for the model

Type

return

download(overwrite: bool = False, refresh_token: bool = False, show_progress: bool = True)[source]

Downloads a model repo file.

Parameters
  • overwrite – True to overwrite the file if it exists, False otherwise

  • refresh_token – refresh the auth token

  • show_progress – True to use tqdm for progress, False to not show

download_framework_files(overwrite: bool = False, refresh_token: bool = False, show_progress: bool = True, extensions: Optional[List[str]] = None)List[str][source]

Downloads the framework file(s) for this model.

Parameters
  • overwrite – True to overwrite the file if it exists, False otherwise

  • refresh_token – refresh the auth token

  • show_progress – True to use tqdm for progress, False to not show

  • extensions – List of file extensions to filter for. ex [‘.pth’, ‘.ptc’]. If None or empty list, all framework files are downloaded. Default is None

Returns

List of paths to the downloaded files. Empty list if no files are found or matched

static download_model(domain: str, sub_domain: str, architecture: str, sub_architecture: Optional[str], framework: str, repo: str, dataset: str, training_scheme: Optional[str], sparse_name: str, sparse_category: str, sparse_target: Optional[str], release_version: Optional[str] = None, override_folder_name: Optional[str] = None, override_parent_path: Optional[str] = None, force_token_refresh: bool = False, overwrite: bool = False)sparsezoo.objects.model.Model[source]

Downloads a model from model repo

Parameters
  • domain – The domain of the model the object belongs to; e.g. cv, nlp

  • sub_domain – The sub domain of the model the object belongs to; e.g. classification, segmentation

  • architecture – The architecture of the model the object belongs to; e.g. resnet_v1, mobilenet_v1

  • sub_architecture – The sub architecture (scaling factor) of the model the object belongs to; e.g. 50, 101, 152

  • framework – The framework the model the object belongs to was trained on; e.g. pytorch, tensorflow

  • repo – The source repo for the model the object belongs to; e.g. sparseml, torchvision

  • dataset – The dataset the model the object belongs to was trained on; e.g. imagenet, cifar10

  • training_scheme – The training scheme used on the model the object belongs to if any; e.g. augmented

  • sparse_name – The name describing the sparsification of the model the object belongs to, e.g. base, pruned, pruned_quant

  • sparse_category – The degree of sparsification of the model the object belongs to; e.g. none, conservative (~100% baseline metric), moderate (>=99% baseline metric), aggressive (<99% baseline metric)

  • sparse_target – The deployment target of sparsification of the model the object belongs to; e.g. edge, deepsparse, deepsparse_throughput, gpu

  • release_version – The sparsezoo release version for the model

  • override_folder_name – Override for the name of the folder to save this file under

  • override_parent_path – Path to override the default save path for where to save the parent folder for this file under

  • force_token_refresh – True to refresh the auth token, False otherwise

  • overwrite – True to overwrite the file if it exists, False otherwise

Returns

The requested Model instance

static download_model_from_stub(stub: Union[str, sparsezoo.requests.base.ModelArgs], override_folder_name: Optional[str] = None, override_parent_path: Optional[str] = None, force_token_refresh: bool = False, overwrite: bool = False)sparsezoo.objects.model.Model[source]
Parameters
  • stub – the SparseZoo stub path to the model, can be a string path or ModelArgs object

  • override_folder_name – Override for the name of the folder to save this file under

  • override_parent_path – Path to override the default save path for where to save the parent folder for this file under

  • force_token_refresh – True to refresh the auth token, False otherwise

  • overwrite – True to overwrite the file if it exists, False otherwise

Returns

The requested Model instance

property framework_files

list of Files that are of type framework

Type

return

property is_base

True if the model is a base model. Otherwise return False

Type

return

static load_base_model_from_recipe(recipe: sparsezoo.objects.recipe.Recipe, override_folder_name: Optional[str] = None, override_parent_path: Optional[str] = None, force_token_refresh: bool = False)Optional[sparsezoo.objects.model.Model][source]

Loads the base model associated with a recipe if any exists

Parameters
  • recipe – the Recipe associated with the model

  • override_folder_name – Override for the name of the folder to save this file under

  • override_parent_path – Path to override the default save path for where to save the parent folder for this file under

  • force_token_refresh – True to refresh the auth token, False otherwise

Returns

The requested Model instance

static load_model(domain: str, sub_domain: str, architecture: str, sub_architecture: Optional[str], framework: str, repo: str, dataset: str, training_scheme: Optional[str], sparse_name: str, sparse_category: str, sparse_target: Optional[str], release_version: Optional[str] = None, override_folder_name: Optional[str] = None, override_parent_path: Optional[str] = None, force_token_refresh: bool = False)sparsezoo.objects.model.Model[source]

Obtains a Model from the model repo

Parameters
  • domain – The domain of the model the object belongs to; e.g. cv, nlp

  • sub_domain – The sub domain of the model the object belongs to; e.g. classification, segmentation

  • architecture – The architecture of the model the object belongs to; e.g. resnet_v1, mobilenet_v1

  • sub_architecture – The sub architecture (scaling factor) of the model the object belongs to; e.g. 50, 101, 152

  • framework – The framework the model the object belongs to was trained on; e.g. pytorch, tensorflow

  • repo – The source repo for the model the object belongs to; e.g. sparseml, torchvision

  • dataset – The dataset the model the object belongs to was trained on; e.g. imagenet, cifar10

  • training_scheme – The training scheme used on the model the object belongs to if any; e.g. augmented

  • sparse_name – The name describing the sparsification of the model the object belongs to, e.g. base, pruned, pruned_quant

  • sparse_category – The degree of sparsification of the model the object belongs to; e.g. none, conservative (~100% baseline metric), moderate (>=99% baseline metric), aggressive (<99% baseline metric)

  • sparse_target – The deployment target of sparsification of the model the object belongs to; e.g. edge, deepsparse, deepsparse_throughput, gpu

  • release_version – The sparsezoo release version for the model

  • override_folder_name – Override for the name of the folder to save this file under

  • override_parent_path – Path to override the default save path for where to save the parent folder for this file under

  • force_token_refresh – True to refresh the auth token, False otherwise

Returns

The requested Model instance

static load_model_from_recipe(recipe: sparsezoo.objects.recipe.Recipe, override_folder_name: Optional[str] = None, override_parent_path: Optional[str] = None, force_token_refresh: bool = False)sparsezoo.objects.model.Model[source]

Loads the model associated with a recipe

Parameters
  • recipe – the Recipe associated with the model

  • override_folder_name – Override for the name of the folder to save this file under

  • override_parent_path – Path to override the default save path for where to save the parent folder for this file under

  • force_token_refresh – True to refresh the auth token, False otherwise

Returns

The requested Model instance

static load_model_from_stub(stub: Union[str, sparsezoo.requests.base.ModelArgs], override_folder_name: Optional[str] = None, override_parent_path: Optional[str] = None, force_token_refresh: bool = False)sparsezoo.objects.model.Model[source]
Parameters
  • stub – the SparseZoo stub path to the model, can be a string path or ModelArgs object

  • override_folder_name – Override for the name of the folder to save this file under

  • override_parent_path – Path to override the default save path for where to save the parent folder for this file under

  • force_token_refresh – True to refresh the auth token, False otherwise

Returns

The requested Model instance

property onnx_file

The latest converted onnx file for the model

Type

return

property onnx_file_gz

The latest converted gziped onnx file for the model

Type

return

property onnx_files

list of Files that are of type onnx

Type

return

property original_recipe

the original recipe used to create the model

Type

return

property recipes

list of recipes for the model

Type

return

property release_version

a model repo release version this model was released with

Type

return

property results

a list of model repo results for this model

Type

return

sample_batch(batch_index: int = 0, batch_size: int = 1, batch_as_list: bool = True)Union[List[numpy.ndarray], Dict[str, numpy.ndarray]][source]

Get a sample batch of data from the data loader

Parameters
  • batch_index – the index of the batch to get

  • batch_size – the size of the batches to create the loader for

  • batch_as_list – True to return multiple inputs/outputs/etc within the dataset as lists, False for an ordereddict

Returns

The sample batch for use with the model

static search_models(domain: str, sub_domain: str, architecture: Optional[str] = None, sub_architecture: Optional[str] = None, framework: Optional[str] = None, repo: Optional[str] = None, dataset: Optional[str] = None, training_scheme: Optional[str] = None, sparse_name: Optional[str] = None, sparse_category: Optional[str] = None, sparse_target: Optional[str] = None, release_version: Optional[str] = None, page: int = 1, page_length: int = 20, override_folder_name: Optional[str] = None, override_parent_path: Optional[str] = None, force_token_refresh: bool = False)List[sparsezoo.objects.model.Model][source]

Obtains a list of Models matching the search parameters

Parameters
  • domain – The domain of the model the object belongs to; e.g. cv, nlp

  • sub_domain – The sub domain of the model the object belongs to; e.g. classification, segmentation

  • architecture – The architecture of the model the object belongs to; e.g. resnet_v1, mobilenet_v1

  • sub_architecture – The sub architecture (scaling factor) of the model the object belongs to; e.g. 50, 101, 152

  • framework – The framework the model the object belongs to was trained on; e.g. pytorch, tensorflow

  • repo – The source repo for the model the object belongs to; e.g. sparseml, torchvision

  • dataset – The dataset the model the object belongs to was trained on; e.g. imagenet, cifar10

  • training_scheme – The training scheme used on the model the object belongs to if any; e.g. augmented

  • sparse_name – The name describing the sparsification of the model the object belongs to, e.g. base, pruned, pruned_quant

  • sparse_category – The degree of sparsification of the model the object belongs to; e.g. none, conservative (~100% baseline metric), moderate (>=99% baseline metric), aggressive (<99% baseline metric)

  • sparse_target – The deployment target of sparsification of the model the object belongs to; e.g. edge, deepsparse, deepsparse_throughput, gpu

  • release_version – The sparsezoo release version for the model

  • page – the page of values to get

  • page_length – the page length of values to get

  • override_folder_name – Override for the name of the folder to save this file under

  • override_parent_path – Path to override the default save path for where to save the parent folder for this file under

  • force_token_refresh – True to refresh the auth token, False otherwise

Returns

The requested Model instance

search_similar_models(match_domain: bool = True, match_sub_domain: bool = True, match_architecture: bool = True, match_sub_architecture: bool = True, match_framework: bool = True, match_repo: bool = True, match_dataset: bool = True, match_training_scheme: bool = False, match_sparse_name: bool = False, match_sparse_category: bool = False, match_sparse_target: bool = False)List[sparsezoo.objects.model.Model][source]

Search for similar models to this model

Parameters
  • match_domain – True to match similar models to the current domain of the model the object belongs to; e.g. cv, nlp

  • match_sub_domain – True to match similar models to the current sub domain of the model the object belongs to; e.g. classification, segmentation

  • match_architecture – True to match similar models to the current architecture of the model the object belongs to; e.g. resnet_v1, mobilenet_v1

  • match_sub_architecture – True to match similar models to the current sub architecture (scaling factor) of the model the object belongs to; e.g. 50, 101, 152

  • match_framework – True to match similar models to the current framework the model the object belongs to was trained on; e.g. pytorch, tensorflow

  • match_repo – True to match similar models to the current source repo for the model the object belongs to; e.g. sparseml, torchvision

  • match_dataset – True to match similar models to the current dataset the model the object belongs to was trained on; e.g. imagenet, cifar10

  • match_training_scheme – True to match similar models to the current training scheme used on the model the object belongs to if any; e.g. augmented

  • match_sparse_name – True to match similar models to the current name describing the sparsification of the model the object belongs to, e.g. base, pruned, pruned_quant

  • match_sparse_category – True to match similar models to the current degree of sparsification of the model the object belongs to; e.g. none, conservative (~100% baseline metric), moderate (>=99% baseline metric), aggressive (<99% baseline metric)

  • match_sparse_target – True to match similar models to the current deployment target of sparsification of the model the object belongs to; e.g. edge, deepsparse, deepsparse_throughput, gpu

Returns

a list of models matching the given model, if any

search_sparse_models(match_framework: bool = True, match_repo: bool = True, match_dataset: bool = True, match_training_scheme: bool = True)List[sparsezoo.objects.model.Model][source]

Search for different available sparse versions based off of the current model

Parameters
  • model – The model object, a SparseZoo model stub path, or a ModelArgs object representing the base model to search different sparsifications of

  • match_framework – True to match similar models to the current framework the model the object belongs to was trained on; e.g. pytorch, tensorflow

  • match_repo – True to match similar models to the current source repo for the model the object belongs to; e.g. sparseml, torchvision

  • match_dataset – True to match similar models to the current dataset the model the object belongs to was trained on; e.g. imagenet, cifar10

  • match_training_scheme – True to match similar models to the current training scheme used on the model the object belongs to if any; e.g. augmented

Returns

the list of matching sparse models, if any

property tags

a list of model repo tags for this model

Type

return

property transfer_learning_recipe

the recipe to use for transfer learning from the model

Type

return

property user

the model repo user who uploaded this model

Type

return

sparsezoo.objects.recipe module

Code related to a model repo recipe file

class sparsezoo.objects.recipe.Recipe(model_metadata: sparsezoo.objects.metadata.ModelMetadata, recipe_id: str, recipe_type: str, display_description: str, base_stub: Optional[str], **kwargs)[source]

Bases: sparsezoo.objects.file.File

A model repo recipe.

Parameters
  • model_metadata – the metadata for the model the file is for

  • recipe_id – the recipe id

  • recipe_type – the type of recipe

  • display_description – the display description for the recipe

  • base_stub – the stub for the base model of this recipe, if any

property base_stub

the stub for the base model of this recipe, if any

Type

return

property display_description

the display description for the recipe

Type

return

property display_name

the display name for the recipe

Type

return

download_base_framework_files(override_folder_name: Optional[str] = None, override_parent_path: Optional[str] = None, force_token_refresh: bool = False, overwrite: bool = False, extensions: Optional[List[str]] = None)List[str][source]
Parameters
  • stub – a string model stub that points to a SparseZoo model. recipe_type may be added as a stub parameter or path of path. i.e. “model/stub/path”, “zoo:model/stub/path”, “zoo:model/stub/path?recipe_type=transfer”, “zoo:model/stub/path/transfer”

  • recipe_type – the recipe_type to download if not original

  • override_folder_name – Override for the name of the folder to save this file under

  • override_parent_path – Path to override the default save path for where to save the parent folder for this file under

  • force_token_refresh – True to refresh the auth token, False otherwise

  • overwrite – True to overwrite the file if it exists, False otherwise

  • extensions – List of file extensions to filter for. ex [‘.pth’, ‘.ptc’]. If None or empty list, all framework files are downloaded. Default is None

Returns

file path to the downloaded framework checkpoint files for the base weights of this recipe

static download_recipe(domain: str, sub_domain: str, architecture: str, sub_architecture: Optional[str], framework: str, repo: str, dataset: str, training_scheme: Optional[str], sparse_name: str, sparse_category: str, sparse_target: Optional[str], recipe_type: Optional[str] = None, release_version: Optional[str] = None, override_folder_name: Optional[str] = None, override_parent_path: Optional[str] = None, force_token_refresh: bool = False)sparsezoo.objects.recipe.Recipe[source]

Downloads a Recipe from the model repo

Parameters
  • domain – The domain of the model the object belongs to; e.g. cv, nlp

  • sub_domain – The sub domain of the model the object belongs to; e.g. classification, segmentation

  • architecture – The architecture of the model the object belongs to; e.g. resnet_v1, mobilenet_v1

  • sub_architecture – The sub architecture (scaling factor) of the model the object belongs to; e.g. 50, 101, 152

  • framework – The framework the model the object belongs to was trained on; e.g. pytorch, tensorflow

  • repo – The source repo for the model the object belongs to; e.g. sparseml, torchvision

  • dataset – The dataset the model the object belongs to was trained on; e.g. imagenet, cifar10

  • training_scheme – The training scheme used on the model the object belongs to if any; e.g. augmented

  • sparse_name – The name describing the sparsification of the model the object belongs to, e.g. base, pruned, pruned_quant

  • sparse_category – The degree of sparsification of the model the object belongs to; e.g. none, conservative (~100% baseline metric), moderate (>=99% baseline metric), aggressive (<99% baseline metric)

  • sparse_target – The deployment target of sparsification of the model the object belongs to; e.g. edge, deepsparse, deepsparse_throughput, gpu

  • recipe_type – The recipe type; e.g. original, transfer_learn

  • release_version – The sparsezoo release version for the model

  • override_folder_name – Override for the name of the folder to save this file under

  • override_parent_path – Path to override the default save path for where to save the parent folder for this file under

  • force_token_refresh – True to refresh the auth token, False otherwise

Returns

The requested Recipe instance

static download_recipe_from_stub(stub: Union[str, sparsezoo.requests.base.ModelArgs], recipe_type: Optional[str] = None, override_folder_name: Optional[str] = None, override_parent_path: Optional[str] = None, force_token_refresh: bool = False, overwrite: bool = False)sparsezoo.objects.recipe.Recipe[source]

Downloads a recipe from stub. If the stub is a string, it may contain the recipe type as a stub parameter or part of the stub. i.e.

  • “model/stub/path”

  • “zoo:model/stub/path”,

  • “zoo:model/stub/path?recipe_type=original”,

  • “zoo:model/stub/path/transfer_learn”

Parameters
  • stub – the SparseZoo stub path to the recipe, can be a string path or ModelArgs object

  • recipe_type – the recipe_type to download if not original

  • override_folder_name – Override for the name of the folder to save this file under

  • override_parent_path – Path to override the default save path for where to save the parent folder for this file under

  • force_token_refresh – True to refresh the auth token, False otherwise

  • overwrite – True to overwrite the file if it exists, False otherwise

Returns

The requested Recipe instance

load_base_model(override_folder_name: Optional[str] = None, override_parent_path: Optional[str] = None)Optional[Model][source]
Returns

the base model associated with the recipe

load_model(override_folder_name: Optional[str] = None, override_parent_path: Optional[str] = None)Model[source]
Returns

the model associated with the recipe

static load_recipe(domain: str, sub_domain: str, architecture: str, sub_architecture: Optional[str], framework: str, repo: str, dataset: str, training_scheme: Optional[str], sparse_name: str, sparse_category: str, sparse_target: Optional[str], recipe_type: Optional[str] = None, release_version: Optional[str] = None, override_folder_name: Optional[str] = None, override_parent_path: Optional[str] = None, force_token_refresh: bool = False)sparsezoo.objects.recipe.Recipe[source]

Obtains a Recipe from the model repo

Parameters
  • domain – The domain of the model the object belongs to; e.g. cv, nlp

  • sub_domain – The sub domain of the model the object belongs to; e.g. classification, segmentation

  • architecture – The architecture of the model the object belongs to; e.g. resnet_v1, mobilenet_v1

  • sub_architecture – The sub architecture (scaling factor) of the model the object belongs to; e.g. 50, 101, 152

  • framework – The framework the model the object belongs to was trained on; e.g. pytorch, tensorflow

  • repo – The source repo for the model the object belongs to; e.g. sparseml, torchvision

  • dataset – The dataset the model the object belongs to was trained on; e.g. imagenet, cifar10

  • training_scheme – The training scheme used on the model the object belongs to if any; e.g. augmented

  • sparse_name – The name describing the sparsification of the model the object belongs to, e.g. base, pruned, pruned_quant

  • sparse_category – The degree of sparsification of the model the object belongs to; e.g. none, conservative (~100% baseline metric), moderate (>=99% baseline metric), aggressive (<99% baseline metric)

  • sparse_target – The deployment target of sparsification of the model the object belongs to; e.g. edge, deepsparse, deepsparse_throughput, gpu

  • recipe_type – The recipe type; e.g. original, transfer_learn

  • release_version – The sparsezoo release version for the model

  • override_folder_name – Override for the name of the folder to save this file under

  • override_parent_path – Path to override the default save path for where to save the parent folder for this file under

  • force_token_refresh – True to refresh the auth token, False otherwise

Returns

The requested Recipe instance

static load_recipe_from_stub(stub: Union[str, sparsezoo.requests.base.ModelArgs], recipe_type: Optional[str] = None, override_folder_name: Optional[str] = None, override_parent_path: Optional[str] = None, force_token_refresh: bool = False)sparsezoo.objects.recipe.Recipe[source]

Loads a recipe from stub. If the stub is a string, it may contain the recipe type as a stub parameter. i.e.

  • “model/stub/path”

  • “zoo:model/stub/path”,

  • “zoo:model/stub/path?recipe_type=original”,

  • “zoo:model/stub/path/transfer_learn”

Parameters
  • stub – the SparseZoo stub path to the recipe, can be a string path or ModelArgs object

  • recipe_type – the recipe type to obtain if not original

  • override_folder_name – Override for the name of the folder to save this file under

  • override_parent_path – Path to override the default save path for where to save the parent folder for this file under

  • force_token_refresh – True to refresh the auth token, False otherwise

Returns

The requested Recipe instance

property recipe_id

the recipe id

Type

return

property recipe_type

the type of recipe

Type

return

property recipe_type_original

True if this is the original recipe that created the model, False otherwise

Type

return

property recipe_type_transfer_learn

True if this is a recipe for transfer learning from the created model, False otherwise

Type

return

static search_recipes(domain: str, sub_domain: str, architecture: Optional[str] = None, sub_architecture: Optional[str] = None, framework: Optional[str] = None, repo: Optional[str] = None, dataset: Optional[str] = None, training_scheme: Optional[str] = None, sparse_name: Optional[str] = None, sparse_category: Optional[str] = None, sparse_target: Optional[str] = None, release_version: Optional[str] = None, recipe_type: Optional[str] = None, page: int = 1, page_length: int = 20, override_folder_name: Optional[str] = None, override_parent_path: Optional[str] = None, force_token_refresh: bool = False)List[sparsezoo.objects.recipe.Recipe][source]

Obtains a list of Recipes matching the model search parameters

Parameters
  • domain – The domain of the model the object belongs to; e.g. cv, nlp

  • sub_domain – The sub domain of the model the object belongs to; e.g. classification, segmentation

  • architecture – The architecture of the model the object belongs to; e.g. resnet_v1, mobilenet_v1

  • sub_architecture – The sub architecture (scaling factor) of the model the object belongs to; e.g. 50, 101, 152

  • framework – The framework the model the object belongs to was trained on; e.g. pytorch, tensorflow

  • repo – The source repo for the model the object belongs to; e.g. sparseml, torchvision

  • dataset – The dataset the model the object belongs to was trained on; e.g. imagenet, cifar10

  • training_scheme – The training scheme used on the model the object belongs to if any; e.g. augmented

  • sparse_name – The name describing the sparsification of the model the object belongs to, e.g. base, pruned, pruned_quant

  • sparse_category – The degree of sparsification of the model the object belongs to; e.g. none, conservative (~100% baseline metric), moderate (>=99% baseline metric), aggressive (<99% baseline metric)

  • sparse_target – The deployment target of sparsification of the model the object belongs to; e.g. edge, deepsparse, deepsparse_throughput, gpu

  • release_version – The sparsezoo release version for the model

  • recipe_type – The recipe type; e.g. original, transfer_learn

  • page – the page of values to get

  • page_length – the page length of values to get

  • override_folder_name – Override for the name of the folder to save this file under

  • override_parent_path – Path to override the default save path for where to save the parent folder for this file under

  • force_token_refresh – True to refresh the auth token, False otherwise

Returns

A list of Recipe objects for models that match the given search parameters

static search_sparse_recipes(model: Union[Model, str, sparsezoo.requests.base.ModelArgs], recipe_type: Optional[str] = None, match_framework: bool = True, match_repo: bool = True, match_dataset: bool = True, match_training_scheme: bool = True)List[Recipe][source]

Search for recipes of the given model

Parameters
  • model – The model object, a SparseZoo stub model path, or a ModelArgs object representing the base model to search for recipes

  • match_framework – True to match similar models to the current framework the model the object belongs to was trained on; e.g. pytorch, tensorflow

  • match_repo – True to match similar models to the current source repo for the model the object belongs to; e.g. sparseml, torchvision

  • match_dataset – True to match similar models to the current dataset the model the object belongs to was trained on; e.g. imagenet, cifar10

  • match_training_scheme – True to match similar models to the current training scheme used on the model the object belongs to if any; e.g. augmented

Returns

the list of matching recipes, if any

property stub

full path for where the recipe is located in the sparsezoo

Type

return

class sparsezoo.objects.recipe.RecipeTypes(value)[source]

Bases: enum.Enum

Types of recipes available in the sparsezoo

ORIGINAL = 'original'
SPARSE = 'sparse'
TRANSFER = 'transfer'
TRANSFER_LEARN = 'transfer_learn'

sparsezoo.objects.release_version module

Code related to a model repo release version

class sparsezoo.objects.release_version.ReleaseVersion(release_version_id: str, major_version: str, minor_version: str, patch_version: str, published: bool, **kwargs)[source]

Bases: sparsezoo.objects.base.BaseObject

A model repo semantic release version. Will represent a version in the format

MAJOR.MINOR.PATCH

Parameters
  • release_version_id – the release version id

  • major_version – the major version of the release

  • minor_version – the minor version of the release

  • patch_version – the patch version of the release

  • published – whether the release has been officially published

property major_version

the major version of the release

Type

return

property minor_version

the minor version of the release

Type

return

property patch_version

the patchversion of the release

Type

return

property published

whether the release has been officially published

Type

return

property release_version_id

the release version id

Type

return

sparsezoo.objects.result module

Code related to a model repo results

class sparsezoo.objects.result.Result(result_id: str, display_name: str, result_type: str, result_category: str, model_id: str, recorded_value: float, recorded_units: str, recorded_format: str, **kwargs)[source]

Bases: sparsezoo.objects.base.BaseObject

A model repo metric result such as for performance, accuracy, etc

Parameters
  • result_id – the result id

  • display_name – the display name for the result

  • result_type – the result type e.g. benchmark or performance

  • result_category – the result category e.g. cpu or gpu

  • model_id – the model id of the model the result is for

  • recorded_value – the recorded value of the result

  • recorded_units – the units the recorded value was in

  • recorded_format – any information of recorded format

property display_name

the display name for the result

Type

return

property model_id

the model id of the model the result is for

Type

return

property recorded_format

any information of recorded format

Type

return

property recorded_units

the units the recorded value was in

Type

return

property recorded_value

the recorded value of the result

Type

return

property result_category

the result category e.g. cpu or gpu

Type

return

property result_id

the result id

Type

return

property result_type

the result type e.g. benchmark or performance

Type

return

sparsezoo.objects.tag module

Code related to model repo tags

class sparsezoo.objects.tag.Tag(tag_id: str, display_name: str, model_id: str, recipe_id: str, name: str, **kwargs)[source]

Bases: sparsezoo.objects.base.BaseObject

A tag for a Model or Recipe

Parameters
  • tag_id – the tag id

  • display_name – the display name for tag

  • model_id – the model id if the tag is associated with a Model

  • recipe_id – the recipe id if tag is associated with a Recipe

  • name – the name for the tag

property display_name

the display name for tag

Type

return

property model_id

the model id of the model the tag is associated with

Type

return

property name

the name for the tag

Type

return

property recipe_id

the recipe id if tag is associated with a Recipe

Type

return

property tag_id

the tag id

Type

return

sparsezoo.objects.user module

Code related to a model repo user

class sparsezoo.objects.user.User(email: str, name: str, user_id: str, trusted: bool, **kwargs)[source]

Bases: sparsezoo.objects.base.BaseObject

A model repo user

Parameters
  • email – contact email

  • name – name of user

  • user_id – user id

  • trusted – Whether the user is a trusted source

property email

contact email

Type

return

property name

name of user

Type

return

property trusted

Whether the user is a trusted source

Type

return

property user_id

user id

Type

return

Module contents

Object classes related to the sparsezoo