sparsezoo-nightly


Namesparsezoo-nightly JSON
Version 1.8.0.20240325 PyPI version JSON
download
home_pagehttps://github.com/neuralmagic/sparsezoo
SummaryNeural network model repository for highly sparse and sparse-quantized models with matching sparsification recipes
upload_time2024-03-25 16:24:33
maintainerNone
docs_urlNone
authorNeuralmagic, Inc.
requires_python>=3.8.0
licenseApache
keywords inference machine learning neural network deep learning model models computer vision nlp pretrained transfer learning sparsity pruning quantization sparse models resnet mobilenet yolov3
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <!--
Copyright (c) 2021 - present / Neuralmagic, Inc. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<h1><img alt="tool icon" src="https://raw.githubusercontent.com/neuralmagic/sparsezoo/main/docs/source/icon-sparsezoo.png" />&nbsp;&nbsp;SparseZoo</h1>

<h3>Neural network model repository for highly sparse and sparse-quantized models with matching sparsification recipes</h3>

<p>
    <a href="https://docs.neuralmagic.com/sparsezoo">
        <img alt="Documentation" src="https://img.shields.io/badge/documentation-darkred?&style=for-the-badge&logo=read-the-docs" height=25>
    </a>
    <a href="https://join.slack.com/t/discuss-neuralmagic/shared_invite/zt-q1a1cnvo-YBoICSIw3L1dmQpjBeDurQ/">
        <img src="https://img.shields.io/badge/slack-purple?style=for-the-badge&logo=slack" height=25>
    </a>
    <a href="https://github.com/neuralmagic/sparsezoo/issues">
        <img src="https://img.shields.io/badge/support%20forums-navy?style=for-the-badge&logo=github" height=25>
    </a>
    <a href="https://github.com/neuralmagic/sparsezoo/actions/workflows/test-check.yaml">
        <img alt="Main" src="https://img.shields.io/github/workflow/status/neuralmagic/sparsezoo/Test%20Checks/main?label=build&style=for-the-badge" height=25>
    </a>
    <a href="https://github.com/neuralmagic/sparsezoo/releases">
        <img alt="GitHub release" src="https://img.shields.io/github/release/neuralmagic/sparsezoo.svg?style=for-the-badge" height=25>
    </a>
    <a href="https://github.com/neuralmagic/sparsezoo/blob/main/LICENSE">
        <img alt="GitHub" src="https://img.shields.io/github/license/neuralmagic/sparsezoo.svg?color=lightgray&style=for-the-badge" height=25>
    </a>
    <a href="https://github.com/neuralmagic/sparsezoo/blob/main/CODE_OF_CONDUCT.md">
        <img alt="Contributor Covenant" src="https://img.shields.io/badge/Contributor%20Covenant-v2.1%20adopted-ff69b4.svg?color=yellow&style=for-the-badge" height=25>
    </a>
    <a href="https://www.youtube.com/channel/UCo8dO_WMGYbWCRnj_Dxr4EA">
        <img src="https://img.shields.io/badge/-YouTube-red?&style=for-the-badge&logo=youtube&logoColor=white" height=25>
    </a>
     <a href="https://medium.com/limitlessai">
        <img src="https://img.shields.io/badge/medium-%2312100E.svg?&style=for-the-badge&logo=medium&logoColor=white" height=25>
    </a>
    <a href="https://twitter.com/neuralmagic">
        <img src="https://img.shields.io/twitter/follow/neuralmagic?color=darkgreen&label=Follow&style=social" height=25>
    </a>
</p>

## Overview

[SparseZoo is a constantly-growing repository](https://sparsezoo.neuralmagic.com) of sparsified (pruned and pruned-quantized) models with matching sparsification recipes for neural networks. 
It simplifies and accelerates your time-to-value in building performant deep learning models with a collection of inference-optimized models and recipes to prototype from. 
Read [more about sparsification](https://docs.neuralmagic.com/user-guides/sparsification).

Available via API and hosted in the cloud, the SparseZoo contains both baseline and models sparsified to different degrees of inference performance vs. baseline loss recovery. 
Recipe-driven approaches built around sparsification algorithms allow you to use the models as given, transfer-learn from the models onto private datasets, or transfer the recipes to your architectures.

The [GitHub repository](https://github.com/neuralmagic/sparsezoo) contains the Python API code to handle the connection and authentication to the cloud.

<img alt="SparseZoo Flow" src="https://docs.neuralmagic.com/docs/source/infographics/sparsezoo.png" width="960px" />


## 🚨 New SparseZoo Models 🚨
### 🎃 October 2023 🎃
**Generative AI**
- Sparse MPT Models - [21 variants](https://sparsezoo.neuralmagic.com/?architectures=mpt&ungrouped=true)
    - âš¡ Highlighted Model âš¡ :  [mpt-7b-gsm8k_mpt_pretrain-pruned80_quantized](https://sparsezoo.neuralmagic.com/models/mpt-7b-gsm8k_mpt_pretrain-pruned80_quantized?hardware=deepsparse-c6i.12xlarge&comparison=mpt-7b-gsm8k_mpt_pretrain-base)
- Sparse OPT Models - [12 variants](https://sparsezoo.neuralmagic.com/?architectures=opt&ungrouped=true)
    - âš¡ Highlighted Model âš¡ :  [opt-6.7b-opt_pretrain-pruned50_quantW8A8](https://sparsezoo.neuralmagic.com/models/opt-6.7b-opt_pretrain-pruned50_quantW8A8?hardware=deepsparse-c6i.12xlarge&comparison=opt-6.7b-opt_pretrain-base)
- Sparse Codegen (mono,multi) Models - [10 variants](https://sparsezoo.neuralmagic.com/?ungrouped=true&architectures=codegen_mono%2Ccodegen_multi)
    - âš¡ Highlighted Model âš¡ :  [codegen_multi-350m-bigquery_thepile-pruned50_quantized](https://sparsezoo.neuralmagic.com/models/codegen_multi-350m-bigquery_thepile-pruned50_quantized?hardware=deepsparse-c6i.12xlarge&comparison=codegen_multi-350m-bigquery_thepile-base) 
 

## Highlights

- [Model Stub Architecture Overview](https://docs.neuralmagic.com/sparsezoo/source/models.html)
- [Available Model Recipes](https://docs.neuralmagic.com/sparsezoo/source/recipes.html)
- [sparsezoo.neuralmagic.com](https://sparsezoo.neuralmagic.com)

## Installation

This repository is tested on Python 3.8-3.11, and Linux/Debian systems.
It is recommended to install in a [virtual environment](https://docs.python.org/3/library/venv.html) to keep your system in order.

Install with pip using:

```bash
pip install sparsezoo
```

## Quick Tour

The SparseZoo Python API enables you to search and download sparsified models. Code examples are given below.
We encourage users to load SparseZoo models by copying a stub directly from a [model page]((https://sparsezoo.neuralmagic.com/)).

### Introduction to Model Class Object

The `Model` is a fundamental object that serves as a main interface with the SparseZoo library. 
It represents a SparseZoo model, together with all its directories and files.

#### Creating a Model Class Object From SparseZoo Stub
```python
from sparsezoo import Model

stub = "zoo:cv/classification/resnet_v1-50/pytorch/sparseml/imagenet/pruned95_quant-none"

model = Model(stub)
print(str(model))

>> Model(stub=zoo:cv/classification/resnet_v1-50/pytorch/sparseml/imagenet/pruned95_quant-none)
```

#### Creating a Model Class Object From Local Model Directory
```python
from sparsezoo import Model

directory = ".../.cache/sparsezoo/eb977dae-2454-471b-9870-4cf38074acf0"

model = Model(directory)
print(str(model))

>> Model(directory=.../.cache/sparsezoo/eb977dae-2454-471b-9870-4cf38074acf0)
```

#### Manually Specifying the Model Download Path

Unless specified otherwise, the model created from the SparseZoo stub is saved to the local sparsezoo cache directory. 
This can be overridden by passing the optional `download_path` argument to the constructor:

```python
from sparsezoo import Model

stub = "zoo:cv/classification/resnet_v1-50/pytorch/sparseml/imagenet/pruned95_quant-none"
download_directory = "./model_download_directory"

model = Model(stub, download_path = download_directory)
```
#### Downloading the Model Files
Once the model is initialized from a stub, it may be downloaded either by calling the `download()` method or by invoking a `path` property. Both pathways are universal for all the files in SparseZoo. Invoking the `path` property will always trigger file download unless the file has already been downloaded.

```python
# method 1
model.download() 

# method 2 
model_path = model.path
```

#### Inspecting the Contents of the SparseZoo Model

We call the `available_files` method to inspect which files are present in the SparseZoo model. Then, we select a file by calling the appropriate attribute:

```python
model.available_files

>> {'training': Directory(name=training), 
>> 'deployment': Directory(name=deployment), 
>> 'sample_inputs': Directory(name=sample_inputs.tar.gz), 
>> 'sample_outputs': {'framework': Directory(name=sample_outputs.tar.gz)}, 
>> 'sample_labels': Directory(name=sample_labels.tar.gz), 
>> 'model_card': File(name=model.md), 
>> 'recipes': Directory(name=recipe), 
>> 'onnx_model': File(name=model.onnx)}
```
Then, we might take a closer look at the contents of the SparseZoo model:
```python
model_card = model.model_card
print(model_card)

>> File(name=model.md)
```
```python
model_card_path = model.model_card.path
print(model_card_path)

>> .../.cache/sparsezoo/eb977dae-2454-471b-9870-4cf38074acf0/model.md
```


### Model, Directory, and File

In general, every file in the SparseZoo model shares a set of attributes: `name`, `path`, `URL`, and `parent`:
- `name` serves as an identifier of the file/directory
- `path` points to the location of the file/directory 
- `URL` specifies the server address of the file/directory in question
- `parent` points to the location of the parent directory of the file/directory in question

A directory is a unique type of file that contains other files. For that reason, it has an additional `files` attribute.

```python
print(model.onnx_model)

>> File(name=model.onnx)

print(f"File name: {model.onnx_model.name}\n"
      f"File path: {model.onnx_model.path}\n"
      f"File URL: {model.onnx_model.url}\n"
      f"Parent directory: {model.onnx_model.parent_directory}")
      
>> File name: model.onnx
>> File path: .../.cache/sparsezoo/eb977dae-2454-471b-9870-4cf38074acf0/model.onnx
>> File URL: https://models.neuralmagic.com/cv-classification/...
>> Parent directory: .../.cache/sparsezoo/eb977dae-2454-471b-9870-4cf38074acf0
```

```python
print(model.recipes)

>> Directory(name=recipe)

print(f"File name: {model.recipes.name}\n"
      f"Contains: {[file.name for file in model.recipes.files]}\n"
      f"File path: {model.recipes.path}\n"
      f"File URL: {model.recipes.url}\n"
      f"Parent directory: {model.recipes.parent_directory}")
      
>> File name: recipe
>> Contains: ['recipe_original.md', 'recipe_transfer-classification.md']
>> File path: /home/user/.cache/sparsezoo/eb977dae-2454-471b-9870-4cf38074acf0/recipe
>> File URL: None
>> Parent directory: /home/user/.cache/sparsezoo/eb977dae-2454-471b-9870-4cf38074acf0
```

### Selecting Checkpoint-Specific Data

A SparseZoo model may contain several checkpoints. The model may contain a checkpoint that had been saved before the model was quantized - that checkpoint would be used for transfer learning. Another checkpoint might have been saved after the quantization step - that one is usually directly used for inference.

The recipes may also vary depending on the use case. We may want to access a recipe that was used to sparsify the dense model (`recipe_original`) or the one that enables us to sparse transfer learn from the already sparsified model (`recipe_transfer`). 

There are two ways to access those specific files.

#### Accessing Recipes (Through Python API)
```python
available_recipes = model.recipes.available
print(available_recipes)

>> ['original', 'transfer-classification']

transfer_recipe = model.recipes["transfer-classification"]
print(transfer_recipe)

>> File(name=recipe_transfer-classification.md)

original_recipe = model.recipes.default # recipe defaults to `original`
original_recipe_path = original_recipe.path # downloads the recipe and returns its path
print(original_recipe_path)

>> .../.cache/sparsezoo/eb977dae-2454-471b-9870-4cf38074acf0/recipe/recipe_original.md
```

#### Accessing Checkpoints (Through Python API)
In general, we are expecting the following checkpoints to be included in the model: 

- `checkpoint_prepruning`
- `checkpoint_postpruning`
- `checkpoint_preqat`
- `checkpoint_postqat` 

The checkpoint that the model defaults to is the `preqat` state (just before the quantization step).

```python
from sparsezoo import Model

stub = "zoo:nlp/question_answering/bert-base/pytorch/huggingface/squad/pruned_quant_3layers-aggressive_84"

model = Model(stub)
available_checkpoints = model.training.available
print(available_checkpoints)

>> ['preqat']

preqat_checkpoint = model.training.default # recipe defaults to `preqat`
preqat_checkpoint_path = preqat_checkpoint.path # downloads the checkpoint and returns its path
print(preqat_checkpoint_path)

>> .../.cache/sparsezoo/0857c6f2-13c1-43c9-8db8-8f89a548dccd/training

[print(file.name) for file in preqat_checkpoint.files]

>> vocab.txt
>> special_tokens_map.json
>> pytorch_model.bin
>> config.json
>> training_args.bin
>> tokenizer_config.json
>> trainer_state.json
>> tokenizer.json
```


#### Accessing Recipes (Through Stub String Arguments)

You can also directly request a specific recipe/checkpoint type by appending the appropriate URL query arguments to the stub:
```python
from sparsezoo import Model

stub = "zoo:cv/classification/resnet_v1-50/pytorch/sparseml/imagenet/pruned95_quant-none?recipe=transfer"

model = Model(stub)

# Inspect which files are present.
# Note that the available recipes are restricted
# according to the specified URL query arguments
print(model.recipes.available)

>> ['transfer-classification']

transfer_recipe = model.recipes.default # Now the recipes default to the one selected by the stub string arguments
print(transfer_recipe)

>> File(name=recipe_transfer-classification.md)
```

### Accessing Sample Data

The user may easily request a sample batch of data that represents the inputs and outputs of the model.

```python
sample_data = model.sample_batch(batch_size = 10)

print(sample_data['sample_inputs'][0].shape)
>> (10, 3, 224, 224) # (batch_size, num_channels, image_dim, image_dim)

print(sample_data['sample_outputs'][0].shape)
>> (10, 1000) # (batch_size, num_classes)
```

### Model Search
The function `search_models` enables the user to quickly filter the contents of SparseZoo repository to find the stubs of interest:

```python
from sparsezoo import search_models

args = {
    "domain": "cv",
    "sub_domain": "segmentation",
    "architecture": "yolact",
}

models = search_models(**args)
[print(model) for model in models]

>> Model(stub=zoo:cv/segmentation/yolact-darknet53/pytorch/dbolya/coco/pruned82_quant-none)
>> Model(stub=zoo:cv/segmentation/yolact-darknet53/pytorch/dbolya/coco/pruned90-none)
>> Model(stub=zoo:cv/segmentation/yolact-darknet53/pytorch/dbolya/coco/base-none)
```

### Environmental Variables

Users can specify the directory where models (temporarily during download) and its required credentials will be saved in your working machine. 
`SPARSEZOO_MODELS_PATH` is the path where the downloaded models will be saved temporarily. Default `~/.cache/sparsezoo/`
`SPARSEZOO_CREDENTIALS_PATH` is the path where `credentials.yaml` will be saved. Default `~/.cache/sparsezoo/`

### Console Scripts

In addition to the Python APIs, a console script entry point is installed with the package `sparsezoo`.
This enables easy interaction straight from your console/terminal.

#### Downloading

Download command help

```shell script
sparsezoo.download -h
```

<br>Download ResNet-50 Model

```shell script
sparsezoo.download zoo:cv/classification/resnet_v1-50/pytorch/sparseml/imagenet/base-none
```

<br>Download pruned and quantized ResNet-50 Model

```shell script
sparsezoo.download zoo:cv/classification/resnet_v1-50/pytorch/sparseml/imagenet/pruned_quant-moderate
```

#### Searching

Search command help

```shell script
sparsezoo search -h
```

<br>Searching for all classification MobileNetV1 models in the computer vision domain

```shell script
sparsezoo search --domain cv --sub-domain classification --architecture mobilenet_v1
```

<br>Searching for all ResNet-50 models

```shell script
sparsezoo search --domain cv --sub-domain classification \
    --architecture resnet_v1 --sub-architecture 50
```

For a more in-depth read, check out [SparseZoo documentation.](https://docs.neuralmagic.com/sparsezoo/)

## Resources

### Learning More

- Documentation: [SparseML,](https://docs.neuralmagic.com/sparseml/) [SparseZoo,](https://docs.neuralmagic.com/sparsezoo/) [Sparsify,](https://docs.neuralmagic.com/sparsify/) [DeepSparse](https://docs.neuralmagic.com/deepsparse/)
- Neural Magic: [Blog,](https://www.neuralmagic.com/blog/) [Resources](https://www.neuralmagic.com/resources/)

### Release History

Official builds are hosted on PyPI

- stable: [sparsezoo](https://pypi.org/project/sparsezoo/)
- nightly (dev): [sparsezoo-nightly](https://pypi.org/project/sparsezoo-nightly/)

Additionally, more information can be found via [GitHub Releases.](https://github.com/neuralmagic/sparsezoo/releases)

### License

The project is licensed under the [Apache License Version 2.0.](https://github.com/neuralmagic/sparsezoo/blob/main/LICENSE)

## Community

### Contribute

We appreciate contributions to the code, examples, integrations, and documentation as well as bug reports and feature requests! [Learn how here.](https://github.com/neuralmagic/sparsezoo/blob/main/CONTRIBUTING.md)

### Join

For user help or questions about SparseZoo, sign up or log in to our [**Neural Magic Community Slack**](https://join.slack.com/t/discuss-neuralmagic/shared_invite/zt-q1a1cnvo-YBoICSIw3L1dmQpjBeDurQ). We are growing the community member by member and happy to see you there. Bugs, feature requests, or additional questions can also be posted to our [GitHub Issue Queue.](https://github.com/neuralmagic/sparsezoo/issues)

You can get the latest news, webinar and event invites, research papers, and other ML Performance tidbits by [subscribing](https://neuralmagic.com/subscribe/) to the Neural Magic community.

For more general questions about Neural Magic, please fill out this [form.](http://neuralmagic.com/contact/)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/neuralmagic/sparsezoo",
    "name": "sparsezoo-nightly",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8.0",
    "maintainer_email": null,
    "keywords": "inference, machine learning, neural network, deep learning model, models, computer vision, nlp, pretrained transfer learning, sparsity, pruning, quantization, sparse models, resnet, mobilenet, yolov3",
    "author": "Neuralmagic, Inc.",
    "author_email": "support@neuralmagic.com",
    "download_url": null,
    "platform": null,
    "description": "<!--\nCopyright (c) 2021 - present / Neuralmagic, Inc. All Rights Reserved.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n   http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing,\nsoftware distributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n-->\n\n<h1><img alt=\"tool icon\" src=\"https://raw.githubusercontent.com/neuralmagic/sparsezoo/main/docs/source/icon-sparsezoo.png\" />&nbsp;&nbsp;SparseZoo</h1>\n\n<h3>Neural network model repository for highly sparse and sparse-quantized models with matching sparsification recipes</h3>\n\n<p>\n    <a href=\"https://docs.neuralmagic.com/sparsezoo\">\n        <img alt=\"Documentation\" src=\"https://img.shields.io/badge/documentation-darkred?&style=for-the-badge&logo=read-the-docs\" height=25>\n    </a>\n    <a href=\"https://join.slack.com/t/discuss-neuralmagic/shared_invite/zt-q1a1cnvo-YBoICSIw3L1dmQpjBeDurQ/\">\n        <img src=\"https://img.shields.io/badge/slack-purple?style=for-the-badge&logo=slack\" height=25>\n    </a>\n    <a href=\"https://github.com/neuralmagic/sparsezoo/issues\">\n        <img src=\"https://img.shields.io/badge/support%20forums-navy?style=for-the-badge&logo=github\" height=25>\n    </a>\n    <a href=\"https://github.com/neuralmagic/sparsezoo/actions/workflows/test-check.yaml\">\n        <img alt=\"Main\" src=\"https://img.shields.io/github/workflow/status/neuralmagic/sparsezoo/Test%20Checks/main?label=build&style=for-the-badge\" height=25>\n    </a>\n    <a href=\"https://github.com/neuralmagic/sparsezoo/releases\">\n        <img alt=\"GitHub release\" src=\"https://img.shields.io/github/release/neuralmagic/sparsezoo.svg?style=for-the-badge\" height=25>\n    </a>\n    <a href=\"https://github.com/neuralmagic/sparsezoo/blob/main/LICENSE\">\n        <img alt=\"GitHub\" src=\"https://img.shields.io/github/license/neuralmagic/sparsezoo.svg?color=lightgray&style=for-the-badge\" height=25>\n    </a>\n    <a href=\"https://github.com/neuralmagic/sparsezoo/blob/main/CODE_OF_CONDUCT.md\">\n        <img alt=\"Contributor Covenant\" src=\"https://img.shields.io/badge/Contributor%20Covenant-v2.1%20adopted-ff69b4.svg?color=yellow&style=for-the-badge\" height=25>\n    </a>\n    <a href=\"https://www.youtube.com/channel/UCo8dO_WMGYbWCRnj_Dxr4EA\">\n        <img src=\"https://img.shields.io/badge/-YouTube-red?&style=for-the-badge&logo=youtube&logoColor=white\" height=25>\n    </a>\n     <a href=\"https://medium.com/limitlessai\">\n        <img src=\"https://img.shields.io/badge/medium-%2312100E.svg?&style=for-the-badge&logo=medium&logoColor=white\" height=25>\n    </a>\n    <a href=\"https://twitter.com/neuralmagic\">\n        <img src=\"https://img.shields.io/twitter/follow/neuralmagic?color=darkgreen&label=Follow&style=social\" height=25>\n    </a>\n</p>\n\n## Overview\n\n[SparseZoo is a constantly-growing repository](https://sparsezoo.neuralmagic.com) of sparsified (pruned and pruned-quantized) models with matching sparsification recipes for neural networks. \nIt simplifies and accelerates your time-to-value in building performant deep learning models with a collection of inference-optimized models and recipes to prototype from. \nRead [more about sparsification](https://docs.neuralmagic.com/user-guides/sparsification).\n\nAvailable via API and hosted in the cloud, the SparseZoo contains both baseline and models sparsified to different degrees of inference performance vs. baseline loss recovery. \nRecipe-driven approaches built around sparsification algorithms allow you to use the models as given, transfer-learn from the models onto private datasets, or transfer the recipes to your architectures.\n\nThe [GitHub repository](https://github.com/neuralmagic/sparsezoo) contains the Python API code to handle the connection and authentication to the cloud.\n\n<img alt=\"SparseZoo Flow\" src=\"https://docs.neuralmagic.com/docs/source/infographics/sparsezoo.png\" width=\"960px\" />\n\n\n## \ud83d\udea8 New SparseZoo Models \ud83d\udea8\n### \ud83c\udf83 October 2023 \ud83c\udf83\n**Generative AI**\n- Sparse MPT Models - [21 variants](https://sparsezoo.neuralmagic.com/?architectures=mpt&ungrouped=true)\n    - \u26a1 Highlighted Model \u26a1 :  [mpt-7b-gsm8k_mpt_pretrain-pruned80_quantized](https://sparsezoo.neuralmagic.com/models/mpt-7b-gsm8k_mpt_pretrain-pruned80_quantized?hardware=deepsparse-c6i.12xlarge&comparison=mpt-7b-gsm8k_mpt_pretrain-base)\n- Sparse OPT Models - [12 variants](https://sparsezoo.neuralmagic.com/?architectures=opt&ungrouped=true)\n    - \u26a1 Highlighted Model \u26a1 :  [opt-6.7b-opt_pretrain-pruned50_quantW8A8](https://sparsezoo.neuralmagic.com/models/opt-6.7b-opt_pretrain-pruned50_quantW8A8?hardware=deepsparse-c6i.12xlarge&comparison=opt-6.7b-opt_pretrain-base)\n- Sparse Codegen (mono,multi) Models - [10 variants](https://sparsezoo.neuralmagic.com/?ungrouped=true&architectures=codegen_mono%2Ccodegen_multi)\n    - \u26a1 Highlighted Model \u26a1 :  [codegen_multi-350m-bigquery_thepile-pruned50_quantized](https://sparsezoo.neuralmagic.com/models/codegen_multi-350m-bigquery_thepile-pruned50_quantized?hardware=deepsparse-c6i.12xlarge&comparison=codegen_multi-350m-bigquery_thepile-base) \n \n\n## Highlights\n\n- [Model Stub Architecture Overview](https://docs.neuralmagic.com/sparsezoo/source/models.html)\n- [Available Model Recipes](https://docs.neuralmagic.com/sparsezoo/source/recipes.html)\n- [sparsezoo.neuralmagic.com](https://sparsezoo.neuralmagic.com)\n\n## Installation\n\nThis repository is tested on Python 3.8-3.11, and Linux/Debian systems.\nIt is recommended to install in a [virtual environment](https://docs.python.org/3/library/venv.html) to keep your system in order.\n\nInstall with pip using:\n\n```bash\npip install sparsezoo\n```\n\n## Quick Tour\n\nThe SparseZoo Python API enables you to search and download sparsified models. Code examples are given below.\nWe encourage users to load SparseZoo models by copying a stub directly from a [model page]((https://sparsezoo.neuralmagic.com/)).\n\n### Introduction to Model Class Object\n\nThe `Model` is a fundamental object that serves as a main interface with the SparseZoo library. \nIt represents a SparseZoo model, together with all its directories and files.\n\n#### Creating a Model Class Object From SparseZoo Stub\n```python\nfrom sparsezoo import Model\n\nstub = \"zoo:cv/classification/resnet_v1-50/pytorch/sparseml/imagenet/pruned95_quant-none\"\n\nmodel = Model(stub)\nprint(str(model))\n\n>> Model(stub=zoo:cv/classification/resnet_v1-50/pytorch/sparseml/imagenet/pruned95_quant-none)\n```\n\n#### Creating a Model Class Object From Local Model Directory\n```python\nfrom sparsezoo import Model\n\ndirectory = \".../.cache/sparsezoo/eb977dae-2454-471b-9870-4cf38074acf0\"\n\nmodel = Model(directory)\nprint(str(model))\n\n>> Model(directory=.../.cache/sparsezoo/eb977dae-2454-471b-9870-4cf38074acf0)\n```\n\n#### Manually Specifying the Model Download Path\n\nUnless specified otherwise, the model created from the SparseZoo stub is saved to the local sparsezoo cache directory. \nThis can be overridden by passing the optional `download_path` argument to the constructor:\n\n```python\nfrom sparsezoo import Model\n\nstub = \"zoo:cv/classification/resnet_v1-50/pytorch/sparseml/imagenet/pruned95_quant-none\"\ndownload_directory = \"./model_download_directory\"\n\nmodel = Model(stub, download_path = download_directory)\n```\n#### Downloading the Model Files\nOnce the model is initialized from a stub, it may be downloaded either by calling the `download()` method or by invoking a `path` property. Both pathways are universal for all the files in SparseZoo. Invoking the `path` property will always trigger file download unless the file has already been downloaded.\n\n```python\n# method 1\nmodel.download() \n\n# method 2 \nmodel_path = model.path\n```\n\n#### Inspecting the Contents of the SparseZoo Model\n\nWe call the `available_files` method to inspect which files are present in the SparseZoo model. Then, we select a file by calling the appropriate attribute:\n\n```python\nmodel.available_files\n\n>> {'training': Directory(name=training), \n>> 'deployment': Directory(name=deployment), \n>> 'sample_inputs': Directory(name=sample_inputs.tar.gz), \n>> 'sample_outputs': {'framework': Directory(name=sample_outputs.tar.gz)}, \n>> 'sample_labels': Directory(name=sample_labels.tar.gz), \n>> 'model_card': File(name=model.md), \n>> 'recipes': Directory(name=recipe), \n>> 'onnx_model': File(name=model.onnx)}\n```\nThen, we might take a closer look at the contents of the SparseZoo model:\n```python\nmodel_card = model.model_card\nprint(model_card)\n\n>> File(name=model.md)\n```\n```python\nmodel_card_path = model.model_card.path\nprint(model_card_path)\n\n>> .../.cache/sparsezoo/eb977dae-2454-471b-9870-4cf38074acf0/model.md\n```\n\n\n### Model, Directory, and File\n\nIn general, every file in the SparseZoo model shares a set of attributes: `name`, `path`, `URL`, and `parent`:\n- `name` serves as an identifier of the file/directory\n- `path` points to the location of the file/directory \n- `URL` specifies the server address of the file/directory in question\n- `parent` points to the location of the parent directory of the file/directory in question\n\nA directory is a unique type of file that contains other files. For that reason, it has an additional `files` attribute.\n\n```python\nprint(model.onnx_model)\n\n>> File(name=model.onnx)\n\nprint(f\"File name: {model.onnx_model.name}\\n\"\n      f\"File path: {model.onnx_model.path}\\n\"\n      f\"File URL: {model.onnx_model.url}\\n\"\n      f\"Parent directory: {model.onnx_model.parent_directory}\")\n      \n>> File name: model.onnx\n>> File path: .../.cache/sparsezoo/eb977dae-2454-471b-9870-4cf38074acf0/model.onnx\n>> File URL: https://models.neuralmagic.com/cv-classification/...\n>> Parent directory: .../.cache/sparsezoo/eb977dae-2454-471b-9870-4cf38074acf0\n```\n\n```python\nprint(model.recipes)\n\n>> Directory(name=recipe)\n\nprint(f\"File name: {model.recipes.name}\\n\"\n      f\"Contains: {[file.name for file in model.recipes.files]}\\n\"\n      f\"File path: {model.recipes.path}\\n\"\n      f\"File URL: {model.recipes.url}\\n\"\n      f\"Parent directory: {model.recipes.parent_directory}\")\n      \n>> File name: recipe\n>> Contains: ['recipe_original.md', 'recipe_transfer-classification.md']\n>> File path: /home/user/.cache/sparsezoo/eb977dae-2454-471b-9870-4cf38074acf0/recipe\n>> File URL: None\n>> Parent directory: /home/user/.cache/sparsezoo/eb977dae-2454-471b-9870-4cf38074acf0\n```\n\n### Selecting Checkpoint-Specific Data\n\nA SparseZoo model may contain several checkpoints. The model may contain a checkpoint that had been saved before the model was quantized - that checkpoint would be used for transfer learning. Another checkpoint might have been saved after the quantization step - that one is usually directly used for inference.\n\nThe recipes may also vary depending on the use case. We may want to access a recipe that was used to sparsify the dense model (`recipe_original`) or the one that enables us to sparse transfer learn from the already sparsified model (`recipe_transfer`). \n\nThere are two ways to access those specific files.\n\n#### Accessing Recipes (Through Python API)\n```python\navailable_recipes = model.recipes.available\nprint(available_recipes)\n\n>> ['original', 'transfer-classification']\n\ntransfer_recipe = model.recipes[\"transfer-classification\"]\nprint(transfer_recipe)\n\n>> File(name=recipe_transfer-classification.md)\n\noriginal_recipe = model.recipes.default # recipe defaults to `original`\noriginal_recipe_path = original_recipe.path # downloads the recipe and returns its path\nprint(original_recipe_path)\n\n>> .../.cache/sparsezoo/eb977dae-2454-471b-9870-4cf38074acf0/recipe/recipe_original.md\n```\n\n#### Accessing Checkpoints (Through Python API)\nIn general, we are expecting the following checkpoints to be included in the model: \n\n- `checkpoint_prepruning`\n- `checkpoint_postpruning`\n- `checkpoint_preqat`\n- `checkpoint_postqat` \n\nThe checkpoint that the model defaults to is the `preqat` state (just before the quantization step).\n\n```python\nfrom sparsezoo import Model\n\nstub = \"zoo:nlp/question_answering/bert-base/pytorch/huggingface/squad/pruned_quant_3layers-aggressive_84\"\n\nmodel = Model(stub)\navailable_checkpoints = model.training.available\nprint(available_checkpoints)\n\n>> ['preqat']\n\npreqat_checkpoint = model.training.default # recipe defaults to `preqat`\npreqat_checkpoint_path = preqat_checkpoint.path # downloads the checkpoint and returns its path\nprint(preqat_checkpoint_path)\n\n>> .../.cache/sparsezoo/0857c6f2-13c1-43c9-8db8-8f89a548dccd/training\n\n[print(file.name) for file in preqat_checkpoint.files]\n\n>> vocab.txt\n>> special_tokens_map.json\n>> pytorch_model.bin\n>> config.json\n>> training_args.bin\n>> tokenizer_config.json\n>> trainer_state.json\n>> tokenizer.json\n```\n\n\n#### Accessing Recipes (Through Stub String Arguments)\n\nYou can also directly request a specific recipe/checkpoint type by appending the appropriate URL query arguments to the stub:\n```python\nfrom sparsezoo import Model\n\nstub = \"zoo:cv/classification/resnet_v1-50/pytorch/sparseml/imagenet/pruned95_quant-none?recipe=transfer\"\n\nmodel = Model(stub)\n\n# Inspect which files are present.\n# Note that the available recipes are restricted\n# according to the specified URL query arguments\nprint(model.recipes.available)\n\n>> ['transfer-classification']\n\ntransfer_recipe = model.recipes.default # Now the recipes default to the one selected by the stub string arguments\nprint(transfer_recipe)\n\n>> File(name=recipe_transfer-classification.md)\n```\n\n### Accessing Sample Data\n\nThe user may easily request a sample batch of data that represents the inputs and outputs of the model.\n\n```python\nsample_data = model.sample_batch(batch_size = 10)\n\nprint(sample_data['sample_inputs'][0].shape)\n>> (10, 3, 224, 224) # (batch_size, num_channels, image_dim, image_dim)\n\nprint(sample_data['sample_outputs'][0].shape)\n>> (10, 1000) # (batch_size, num_classes)\n```\n\n### Model Search\nThe function `search_models` enables the user to quickly filter the contents of SparseZoo repository to find the stubs of interest:\n\n```python\nfrom sparsezoo import search_models\n\nargs = {\n    \"domain\": \"cv\",\n    \"sub_domain\": \"segmentation\",\n    \"architecture\": \"yolact\",\n}\n\nmodels = search_models(**args)\n[print(model) for model in models]\n\n>> Model(stub=zoo:cv/segmentation/yolact-darknet53/pytorch/dbolya/coco/pruned82_quant-none)\n>> Model(stub=zoo:cv/segmentation/yolact-darknet53/pytorch/dbolya/coco/pruned90-none)\n>> Model(stub=zoo:cv/segmentation/yolact-darknet53/pytorch/dbolya/coco/base-none)\n```\n\n### Environmental Variables\n\nUsers can specify the directory where models (temporarily during download) and its required credentials will be saved in your working machine. \n`SPARSEZOO_MODELS_PATH` is the path where the downloaded models will be saved temporarily. Default `~/.cache/sparsezoo/`\n`SPARSEZOO_CREDENTIALS_PATH` is the path where `credentials.yaml` will be saved. Default `~/.cache/sparsezoo/`\n\n### Console Scripts\n\nIn addition to the Python APIs, a console script entry point is installed with the package `sparsezoo`.\nThis enables easy interaction straight from your console/terminal.\n\n#### Downloading\n\nDownload command help\n\n```shell script\nsparsezoo.download -h\n```\n\n<br>Download ResNet-50 Model\n\n```shell script\nsparsezoo.download zoo:cv/classification/resnet_v1-50/pytorch/sparseml/imagenet/base-none\n```\n\n<br>Download pruned and quantized ResNet-50 Model\n\n```shell script\nsparsezoo.download zoo:cv/classification/resnet_v1-50/pytorch/sparseml/imagenet/pruned_quant-moderate\n```\n\n#### Searching\n\nSearch command help\n\n```shell script\nsparsezoo search -h\n```\n\n<br>Searching for all classification MobileNetV1 models in the computer vision domain\n\n```shell script\nsparsezoo search --domain cv --sub-domain classification --architecture mobilenet_v1\n```\n\n<br>Searching for all ResNet-50 models\n\n```shell script\nsparsezoo search --domain cv --sub-domain classification \\\n    --architecture resnet_v1 --sub-architecture 50\n```\n\nFor a more in-depth read, check out [SparseZoo documentation.](https://docs.neuralmagic.com/sparsezoo/)\n\n## Resources\n\n### Learning More\n\n- Documentation: [SparseML,](https://docs.neuralmagic.com/sparseml/) [SparseZoo,](https://docs.neuralmagic.com/sparsezoo/) [Sparsify,](https://docs.neuralmagic.com/sparsify/) [DeepSparse](https://docs.neuralmagic.com/deepsparse/)\n- Neural Magic: [Blog,](https://www.neuralmagic.com/blog/) [Resources](https://www.neuralmagic.com/resources/)\n\n### Release History\n\nOfficial builds are hosted on PyPI\n\n- stable: [sparsezoo](https://pypi.org/project/sparsezoo/)\n- nightly (dev): [sparsezoo-nightly](https://pypi.org/project/sparsezoo-nightly/)\n\nAdditionally, more information can be found via [GitHub Releases.](https://github.com/neuralmagic/sparsezoo/releases)\n\n### License\n\nThe project is licensed under the [Apache License Version 2.0.](https://github.com/neuralmagic/sparsezoo/blob/main/LICENSE)\n\n## Community\n\n### Contribute\n\nWe appreciate contributions to the code, examples, integrations, and documentation as well as bug reports and feature requests! [Learn how here.](https://github.com/neuralmagic/sparsezoo/blob/main/CONTRIBUTING.md)\n\n### Join\n\nFor user help or questions about SparseZoo, sign up or log in to our [**Neural Magic Community Slack**](https://join.slack.com/t/discuss-neuralmagic/shared_invite/zt-q1a1cnvo-YBoICSIw3L1dmQpjBeDurQ). We are growing the community member by member and happy to see you there. Bugs, feature requests, or additional questions can also be posted to our [GitHub Issue Queue.](https://github.com/neuralmagic/sparsezoo/issues)\n\nYou can get the latest news, webinar and event invites, research papers, and other ML Performance tidbits by [subscribing](https://neuralmagic.com/subscribe/) to the Neural Magic community.\n\nFor more general questions about Neural Magic, please fill out this [form.](http://neuralmagic.com/contact/)\n",
    "bugtrack_url": null,
    "license": "Apache",
    "summary": "Neural network model repository for highly sparse and sparse-quantized models with matching sparsification recipes",
    "version": "1.8.0.20240325",
    "project_urls": {
        "Homepage": "https://github.com/neuralmagic/sparsezoo"
    },
    "split_keywords": [
        "inference",
        " machine learning",
        " neural network",
        " deep learning model",
        " models",
        " computer vision",
        " nlp",
        " pretrained transfer learning",
        " sparsity",
        " pruning",
        " quantization",
        " sparse models",
        " resnet",
        " mobilenet",
        " yolov3"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "050b9726d554ee3e87047e17d7fc41b806dcd479c5ba1445098849863f1d2c01",
                "md5": "3d82f8da966ee3a71664b29cbb98594e",
                "sha256": "cdbe9dcc697c29a6ce3c4617e0a5c274f035f2fc608a52ba4974959dc78019c5"
            },
            "downloads": -1,
            "filename": "sparsezoo_nightly-1.8.0.20240325-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3d82f8da966ee3a71664b29cbb98594e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8.0",
            "size": 178209,
            "upload_time": "2024-03-25T16:24:33",
            "upload_time_iso_8601": "2024-03-25T16:24:33.306121Z",
            "url": "https://files.pythonhosted.org/packages/05/0b/9726d554ee3e87047e17d7fc41b806dcd479c5ba1445098849863f1d2c01/sparsezoo_nightly-1.8.0.20240325-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-25 16:24:33",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "neuralmagic",
    "github_project": "sparsezoo",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "sparsezoo-nightly"
}
        
Elapsed time: 0.23059s