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

[Fix] Allow for processing `Path` in the sparsezoo analysis #417

Closed dbogunowicz closed 10 months ago

dbogunowicz commented 10 months ago

onnx.load() has very limited support for loading models from the Path objects, especially when loading involves properly searching for external data. This causes the issue: https://app.asana.com/0/1206109050183159/1206486977947981/f - onnx tries to look for external data in the cwd and not in the directory where model.onnx is.

The solution is to refrain from using onnx.load(...) in favor of using our internal helper func load_model. That is slightly enhanced version of the func, that also works with Path objects.

Now:

deepsparse.analyze /home/damian/.cache/sparsezoo/neuralmagic/codellama-7b-evolcodealpaca_codellama_pretrain-pruned60_quantized/deployment

Does not fail on model loading:

2024-02-01 15:51:49 __main__     INFO     Starting Analysis ...
INFO:__main__:Starting Analysis ...
INFO:root:Loading `model.onnx` from deployment directory /home/damian/.cache/sparsezoo/neuralmagic/codellama-7b-evolcodealpaca_codellama_pretrain-pruned60_quantized/deployment
EP Error narrowing_error when using ['CPUExecutionProvider']
Falling back to ['CPUExecutionProvider'] and retrying.
WARNING:sparsezoo.utils.node_inference:Extracting shapes using ONNX Runtime session failed: narrowing_error
WARNING:sparsezoo.utils.node_inference:Falling back to ONNX shape_inference
...

Note: it fails later on, but for that we have a separate ticket