neuralmagic / sparsezoo

Neural network model repository for highly sparse and sparse-quantized models with matching sparsification recipes
Apache License 2.0
371 stars 25 forks source link

model.deployment to target compressed deployment directory #373

Closed bfineran closed 1 year ago

bfineran commented 1 year ago

to land with https://github.com/neuralmagic/deepsparse/pull/1318

updates Model to target the compressed deployment directory tarball instead of the loose directory includes a helper function for downloading/unzipping the tarball

simple test:

from sparsezoo import Model

model = Model("zoo:nlg/text_generation/mpt-7b/pytorch/huggingface/mpt_chat/base-none")

model.deployment_directory_path

This PR adds a AliasedSelectDirectory class that can be used to download a different file, but point to the actual expected directory.

Now, the deployment folder is always downloaded as a tar ball and extracted instead of downloading all files.

Test:

# local_test.py
from sparsezoo import Model

stub = "zoo:resnet_v1-50-imagenet-pruned95_quantized"

model = Model(stub)

print(model.deployment.path)

Case 1: When model is not already downloaded:


rahul at office-desktop in ~/projects/sparsezoo (deployment-tar●●) (.venv) 
$ rm -rf ~/.cache/sparsezoo                                                                                                   (deployment-tar|✚3…3)

rahul at office-desktop in ~/projects/sparsezoo (deployment-tar●●) (.venv) 
$ python local_test.py                                                                                                        (deployment-tar|✚3…3)
Downloading (…)eployment/model.onnx: 100%|█████████████████████████████████████████████████████████████████████| 30.3M/30.3M [00:02<00:00, 12.5MB/s]
Downloading (…)quantized/model.onnx: 100%|█████████████████████████████████████████████████████████████████████| 30.3M/30.3M [00:02<00:00, 12.3MB/s]
/home/rahul/.cache/sparsezoo/neuralmagic/resnet_v1-50-imagenet-pruned95_quantized/deployment

rahul at office-desktop in ~/projects/sparsezoo (deployment-tar●●) (.venv) 
$ tree /home/rahul/.cache/sparsezoo/neuralmagic/resnet_v1-50-imagenet-pruned95_quantized                                      (deployment-tar|✚3…3)
/home/rahul/.cache/sparsezoo/neuralmagic/resnet_v1-50-imagenet-pruned95_quantized
├── deployment
│   └── model.onnx
└── model.onnx

Case 2: When the files are already downloaded

rahul at office-desktop in ~/projects/sparsezoo (deployment-tar●●) (.venv) 
$ tree /home/rahul/.cache/sparsezoo/neuralmagic/resnet_v1-50-imagenet-pruned95_quantized                                      (deployment-tar|✚3…3)
/home/rahul/.cache/sparsezoo/neuralmagic/resnet_v1-50-imagenet-pruned95_quantized
├── deployment
│   └── model.onnx
└── model.onnx

1 directory, 2 files

rahul at office-desktop in ~/projects/sparsezoo (deployment-tar●●) (.venv) 
$ python local_test.py                                                                                                        (deployment-tar|✚3…3)
/home/rahul/.cache/sparsezoo/neuralmagic/resnet_v1-50-imagenet-pruned95_quantized/deployment

rahul at office-desktop in ~/projects/sparsezoo (deployment-tar●●) (.venv) 
$ tree /home/rahul/.cache/sparsezoo/neuralmagic/resnet_v1-50-imagenet-pruned95_quantized                                      (deployment-tar|✚3…3)
/home/rahul/.cache/sparsezoo/neuralmagic/resnet_v1-50-imagenet-pruned95_quantized
├── deployment
│   └── model.onnx
└── model.onnx

1 directory, 2 files
Satrat commented 1 year ago

Looks like this is causing a failing unit test:

ERROR tests/sparsezoo/analyze/test_model_analysis_creation.py - NotADirectoryError: [Errno 20] Not a directory: 
'/home/runner/.cache/sparsezoo/neuralmagic/resnet_v1-50-imagenet-pruned95_quantized/deployment.tar.gz/model.onnx'