sparsezoo.requests package

Submodules

sparsezoo.requests.authentication module

Requests for authenticating with the sparsezoo cloud

sparsezoo.requests.authentication.get_auth_header(authentication_type: str = 'public', user_id: Optional[str] = None, app_id: Optional[str] = None, force_token_refresh: bool = False)Dict[source]

Obtain an authentication header token from either credentials file or from APIs if token is over 1 day old. Location of credentials file can be changed by setting the environment variable NM_SPARSE_ZOO_CREDENTIALS.

Currently only ‘public’ authentication type is supported.

Parameters
  • authentication_type – authentication type for generating token

  • user_id – user id if auth type requires user_id

  • app_id – app id if auth type requires app_id

  • force_token_refresh – forces a new token to be generated

Returns

An authentication header with key ‘nm-token-header’ containing the header token

sparsezoo.requests.base module

Code related to base functionality for making requests

class sparsezoo.requests.base.ModelArgs(domain: Optional[str] = None, sub_domain: Optional[str] = None, architecture: Optional[Union[str, List[str]]] = None, sub_architecture: Optional[Union[str, List[str]]] = None, framework: Optional[Union[str, List[str]]] = None, repo: Optional[Union[str, List[str]]] = None, dataset: Optional[Union[str, List[str]]] = None, training_scheme: Optional[Union[str, List[str]]] = None, sparse_name: Optional[Union[str, List[str]]] = None, sparse_category: Optional[Union[str, List[str]]] = None, sparse_target: Optional[Union[str, List[str]]] = None, release_version: Optional[Union[str, Any]] = None, **kwargs)[source]

Bases: object

Arguments for making requests into 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

property architecture

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

Type

return

property architecture_id

Unique id for the model architecture containing both the architecture and sub_architecture

Type

return

property dataset

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

Type

return

property domain

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

Type

return

property framework

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

Type

return

property model_url_args

arguments for searching in the sparsezoo

Type

return

property model_url_root

root path for where the model is located in the sparsezoo

Type

return

property release_version

The sparsezoo release version for the model

Type

return

property repo

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

Type

return

property 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)

Type

return

property sparse_id

Unique id for how the model was sparse containing the sparse_name, sparse_category, sparse_target

Type

return

property sparse_name

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

Type

return

property sparse_target

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

Type

return

property stub

full path for where the model is located in the sparsezoo

Type

return

property sub_architecture

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

Type

return

property sub_domain

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

Type

return

property training_id

Unique id for how the model was trained containing both the dataset and training_scheme

Type

return

property training_scheme

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

Type

return

class sparsezoo.requests.base.RecipeArgs(domain: Optional[str] = None, sub_domain: Optional[str] = None, architecture: Optional[Union[str, List[str]]] = None, sub_architecture: Optional[Union[str, List[str]]] = None, framework: Optional[Union[str, List[str]]] = None, repo: Optional[Union[str, List[str]]] = None, dataset: Optional[Union[str, List[str]]] = None, training_scheme: Optional[Union[str, List[str]]] = None, sparse_name: Optional[Union[str, List[str]]] = None, sparse_category: Optional[Union[str, List[str]]] = None, sparse_target: Optional[Union[str, List[str]]] = None, release_version: Optional[Union[str, Any]] = None, recipe_type: Optional[str] = None, **kwargs)[source]

Bases: sparsezoo.requests.base.ModelArgs

Arguments for making recipe requests into 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

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

property model_url_args

arguments for searching in the sparsezoo

Type

return

property recipe_type

The recipe type; e.g. original, transfer_learn

Type

return

sparsezoo.requests.base.parse_zoo_stub(stub: str, valid_params: Optional[List[str]] = None)Tuple[str, Dict[str, str]][source]
Parameters
  • stub – A SparseZoo model stub. i.e. ‘model/stub/path’, ‘zoo:model/stub/path’, ‘zoo:model/stub/path?param1=value1&param2=value2’

  • valid_params – list of expected parameter names to be encoded in the stub. Will raise a warning if any unexpected param names are given. Leave as None to not raise any warnings. Default is None

Returns

the parsed base stub and a dictionary of parameter names and their values

sparsezoo.requests.download module

Code related to wrapping around API calls under api.neuralmagic.com/[object]/download

sparsezoo.requests.download.download_get_request(base_url: str, args: Union[sparsezoo.requests.base.ModelArgs, str], sub_path: Optional[str] = None, force_token_refresh: bool = False)Dict[source]

Get a downloadable object from the sparsezoo for any objects matching the args

The path called has structure:

[base_url]/download/[args.stub]/{sub_path}

Parameters
  • base_url – the base url

  • args – the model args describing what should be downloaded for

  • sub_path – the sub path from the model path if any e.g. file_name for models api or recipe_type for the recipes api

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

Returns

the json response as a dict

sparsezoo.requests.download.download_model_get_request(args: Union[sparsezoo.requests.base.ModelArgs, str], file_name: Optional[str] = None, force_token_refresh: bool = False)Dict[source]

Get a downloadable model from the sparsezoo for any objects matching the args

Parameters
  • args – the model args describing what should be downloaded for

  • file_name – the name of the file, if any, to get download info for

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

Returns

the json response as a dict

sparsezoo.requests.download.download_recipe_get_request(args: Union[sparsezoo.requests.base.ModelArgs, str], recipe_type: Optional[str] = None, force_token_refresh: bool = False)[source]

Get a downloadable recipe from the sparsezoo for any objects matching the args

Parameters
  • args – the model args describing what should be downloaded for

  • recipe_type – the recipe_type to get download info for if not original

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

Returns

the json response as a dict

sparsezoo.requests.get module

Code related to wrapping around API calls under api.neuralmagic.com/[object]/get

sparsezoo.requests.get.get_model_get_request(args: Union[sparsezoo.requests.base.ModelArgs, str], file_name: Optional[str] = None, force_token_refresh: bool = False)Dict[source]

Get a model from the sparsezoo for any objects matching the args

Parameters
  • args – the model args describing what should be retrieved for

  • file_name – the name of the file, if any, to get model info for

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

Returns

the json response as a dict

sparsezoo.requests.get.get_recipe_get_request(args: Union[sparsezoo.requests.base.ModelArgs, str], recipe_type: Optional[str] = None, force_token_refresh: bool = False)[source]

Get a recipe from the sparsezoo for any objects matching the args

Parameters
  • args – the model args describing what should be retrieved for

  • recipe_type – the recipe_type to get recipe info for if not original

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

Returns

the json response as a dict

sparsezoo.requests.get.get_request(base_url: str, args: Union[sparsezoo.requests.base.ModelArgs, str], sub_path: Optional[str] = None, force_token_refresh: bool = False)Dict[source]

Get an object from the sparsezoo for any objects matching the args.

The path called has structure:

[base_url]/get/[args.stub]/{sub_path}

Parameters
  • base_url – the base url of the request

  • args – the args describing what should be retrieved

  • file_name – the sub path from the model path if any e.g. file_name for models api or recipe_type for the recipes api

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

Returns

the json response as a dict

sparsezoo.requests.search module

Code related to wrapping around API calls under api.neuralmagic.com/objects/search

sparsezoo.requests.search.search_get_request(base_url: str, args: sparsezoo.requests.base.ModelArgs, page: int = 1, page_length: int = 20, force_token_refresh: bool = False)Dict[source]

Search the sparsezoo for any objects matching the args

Parameters
  • base_url – the base url

  • args – the model args describing what should be searched for

  • page – the page of values to get

  • page_length – the page length of values to get

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

Returns

the json response as a dict

sparsezoo.requests.search.search_model_get_request(args: sparsezoo.requests.base.ModelArgs, page: int = 1, page_length: int = 20, force_token_refresh: bool = False)Dict[source]

Search the sparsezoo for any models matching the args

Parameters
  • args – the model args describing what should be searched for

  • page – the page of values to get

  • page_length – the page length of values to get

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

Returns

the json response as a dict

sparsezoo.requests.search.search_recipe_get_request(args: sparsezoo.requests.base.RecipeArgs, page: int = 1, page_length: int = 20, force_token_refresh: bool = False)Dict[source]

Search the sparsezoo for any models matching the args

Parameters
  • args – the model args describing what should be searched for

  • page – the page of values to get

  • page_length – the page length of values to get

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

Returns

the json response as a dict

Module contents

Classes for making requests with the sparsezoo