Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bugfix] Point OnnxGz files to model.onnx but download and extract model.onnx.tar.gz #357

Merged
merged 11 commits into from
Aug 21, 2023

Conversation

rahul-tuli
Copy link
Member

@rahul-tuli rahul-tuli commented Aug 17, 2023

Big LLMS are generally saved with external data; this external data along with model.onnx live inside model.onnx.tar.gz tarball on sparsezoo; recently we added support to download the tarfile and emulate a normal onnx model file using a wrapper class OnnxGz; when adding this support a bug was introduced where model.onnx was present twice in the model path; leading to errors while creating ort sessions as

TEST PLAN:

  • Manual inspection using attached script
  • Add automated tests to capture conditions where extraction was failing
  • Test with deepsparse main

Test Script:

from sparsezoo import Model
from pathlib import Path


def local_test(stub: str):
    model = Model(stub)
    onnx_model = model.onnx_model
    model_path = onnx_model.path
    onnx_model_path = Path(model_path)
    assert onnx_model_path.exists(), "Path to onnx model does not exist"
    assert (count := str(onnx_model_path).count("model.onnx")) == 1, f"Path to onnx model contains model.onnx {count} times"

    # create an ORT session with the model
    import onnxruntime as ort
    session = ort.InferenceSession(str(onnx_model_path), providers=["CPUExecutionProvider"])
    assert session is not None, "ORT session is None"

if __name__ == '__main__':
    # stub = "zoo:nlg/text_generation/opt-13b/pytorch/huggingface/opt_pretrain/pruned50_quantW8A8-none"
    stub = "zoo:cv/classification/mobilenet_v1-1.0/pytorch/sparseml/imagenet/pruned_quant-moderate"
    local_test(stub=stub)

Before this PR: The onnx_model_path had an extra model.onnx in it's path leading to errors like:
https://github.com/neuralmagic/deepsparse/actions/runs/5869604261/job/15914935604?pr=1150#step:7:138

After this PR the test script runs successfully, and the base test errors on deepsparse side are green


@rahul-tuli rahul-tuli changed the title [Bugfix] Point OnnxGz files to model.onnx but download using model.onnx.tar.gz [Bugfix] Point OnnxGz files to model.onnx but download and extract model.onnx.tar.gz Aug 17, 2023
@rahul-tuli rahul-tuli self-assigned this Aug 17, 2023
@rahul-tuli rahul-tuli added the bug Something isn't working label Aug 17, 2023
Raise FileNotFoundError if model.onnx could not be extracted/found
Unzip ModelGz irrespective of parent dir existence
Fix Typing in a few places
Use generators with all
Do not rely on `super.path` as the `_path` variable is mangled in superclass
Write Invariants and post conditions for OnnxGz
Fix OnnxGz path for cases when Model is created from local files
Move `not isinstance(file, Directory)` check first to avoid calling `.path` on Directory objects unwillingly
Add tests with mobilenet to check Onnxgz extraction using local files and model stub
src/sparsezoo/model/model.py Show resolved Hide resolved
src/sparsezoo/model/model.py Show resolved Hide resolved
src/sparsezoo/model/utils.py Show resolved Hide resolved
src/sparsezoo/objects/directories.py Show resolved Hide resolved
src/sparsezoo/objects/directories.py Show resolved Hide resolved
src/sparsezoo/objects/directory.py Show resolved Hide resolved
src/sparsezoo/objects/directory.py Show resolved Hide resolved
src/sparsezoo/model/model.py Show resolved Hide resolved
src/sparsezoo/model/utils.py Show resolved Hide resolved
Copy link
Contributor

@Satrat Satrat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure the file we want to unzip is model.tar.gz and not model.onnx.tar.gz if the purpose of this PR is to extract the model.data file.

The 2B codegen stub shows model.tar.gz as 6.4GB and model.onnx.tar.gz as only 594KB.

In general, I think it would be a good idea to upload a small model to sparsezoo that has its data stored externally so we can catch the issue in the test suite without having to run giant models

@rahul-tuli
Copy link
Member Author

rahul-tuli commented Aug 18, 2023

I'm pretty sure the file we want to unzip is model.tar.gz and not model.onnx.tar.gz if the purpose of this PR is to extract the model.data file.

The 2B codegen stub shows model.tar.gz as 6.4GB and model.onnx.tar.gz as only 594KB.

In general, I think it would be a good idea to upload a small model to sparsezoo that has its data stored externally so we can catch the issue in the test suite without having to run giant models

making a comment here that the linked model needs to be updated on sparsezoo; and the onnx model model.onnx along with external_data if any should be inside model.onnx.tar.gz

Satrat
Satrat previously approved these changes Aug 18, 2023
Copy link
Contributor

@dsikka dsikka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two comments. otherwise LGTM

src/sparsezoo/objects/directories.py Outdated Show resolved Hide resolved
src/sparsezoo/objects/directories.py Show resolved Hide resolved
src/sparsezoo/model/utils.py Show resolved Hide resolved
src/sparsezoo/objects/directories.py Outdated Show resolved Hide resolved
src/sparsezoo/objects/directory.py Show resolved Hide resolved
- Update info log -> debug
- Update assumption in docstring
@bfineran bfineran merged commit 1943c1a into main Aug 21, 2023
4 checks passed
@bfineran bfineran deleted the bugfix-model.onnx.tar.gz branch August 21, 2023 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants