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

Update: ModelAnalysis.from_onnx(...) to work with ModelProto #253

Merged
merged 1 commit into from
Jan 30, 2023

Conversation

rahul-tuli
Copy link
Member

Before this PR, sparezoo.analysis.ModelAnalysis.from_onnx(...) method
worked only with filepaths to onnx files, this can be inconvenient especially
if we need to analyze an already loaded onnx model.

import onnx
from sparsezoo.analysis import ModelAnalysis
onnx_model = onnx.load("./model.onnx")
ModelAnalysis.from_onnx(onnx_model)

Results in the following Error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/rahul/projects/sparsezoo/src/sparsezoo/analysis/analysis.py", line 435, in from_onnx
    model_onnx = onnx.load(onnx_file_path)
  File "/home/rahul/virtual_environments/sparsezoo3.9/lib/python3.9/site-packages/onnx/__init__.py", line 120, in load_model
    s = _load_bytes(f)
  File "/home/rahul/virtual_environments/sparsezoo3.9/lib/python3.9/site-packages/onnx/__init__.py", line 34, in _load_bytes
    with open(cast(Text, f), 'rb') as readable:
TypeError: expected str, bytes or os.PathLike object, not ModelProto

After this PR ModelAnalysis will work with both loaded onnx ModelProto and
local filepaths

The same test code(after this PR) now returns a ModelAnalysis object

ModelAnalysis(node_counts={'Conv': 53, 'Gemm': 1, 'BatchNormalization': ...

This will allow easier testing where we will not have to reload onnx files,
and, will be useful for upcoming PerformanceAnalysis api

Note: The changes added should not affect existing flows.

@rahul-tuli rahul-tuli merged commit 9cdc900 into main Jan 30, 2023
@rahul-tuli rahul-tuli deleted the ModelProto-support-ModelAnalysis branch January 30, 2023 18:06
horheynm pushed a commit that referenced this pull request Feb 1, 2023
horheynm pushed a commit that referenced this pull request Feb 1, 2023
search

search, download draft

draft, successful search and download

draft

Update: `ModelAnalysis.from_onnx(...)` to additionally work with loaded `ModelProto` (#253)

refactor

search, download
horheynm added a commit that referenced this pull request Mar 20, 2023
* Dummy graphql requests module

* graphql api request

* return Model instances

* Update NOTICE (#242)

license name change

* bump main to 1.4.0 (#246)

Co-authored-by: dhuang <dhuang@MacBook-Pro.local>

* Pin numpy version to <=1.21.6 (#247)

search

search, download draft

draft, successful search and download

draft

Update: `ModelAnalysis.from_onnx(...)` to additionally work with loaded `ModelProto` (#253)

refactor

search, download

* lint

* pass tests

* init files

* lint

* Add dummy test using test-specific subclass

* tests

* add incremeent_downloads=False

* allow empty arguments

* comments

* refactor from main merge

* comments

* da comments

---------

Co-authored-by: Danny Guinther <dguinther@neuralmagic.com>
Co-authored-by: Jeannie Finks <74554921+jeanniefinks@users.noreply.github.com>
Co-authored-by: dhuangnm <74931910+dhuangnm@users.noreply.github.com>
Co-authored-by: dhuang <dhuang@MacBook-Pro.local>
Co-authored-by: Rahul Tuli <rahul@neuralmagic.com>
horheynm added a commit that referenced this pull request Mar 21, 2023
* Dummy graphql requests module

* graphql api request

* return Model instances

* Update NOTICE (#242)

license name change

* bump main to 1.4.0 (#246)

Co-authored-by: dhuang <dhuang@MacBook-Pro.local>

* Pin numpy version to <=1.21.6 (#247)

search

search, download draft

draft, successful search and download

draft

Update: `ModelAnalysis.from_onnx(...)` to additionally work with loaded `ModelProto` (#253)

refactor

search, download

* lint

* pass tests

* init files

* lint

* Add dummy test using test-specific subclass

* tests

* add incremeent_downloads=False

* allow empty arguments

* comments

* query parser, allow dict as input, add tests for extra functionality

* restore models.utils

* restore models.utils

* comments

* remove redundant code

---------

Co-authored-by: Danny Guinther <dguinther@neuralmagic.com>
Co-authored-by: Jeannie Finks <74554921+jeanniefinks@users.noreply.github.com>
Co-authored-by: dhuangnm <74931910+dhuangnm@users.noreply.github.com>
Co-authored-by: dhuang <dhuang@MacBook-Pro.local>
Co-authored-by: Rahul Tuli <rahul@neuralmagic.com>
horheynm added a commit that referenced this pull request Apr 12, 2023
* Dummy graphql requests module

* graphql api request

* return Model instances

* Update NOTICE (#242)

license name change

* bump main to 1.4.0 (#246)

Co-authored-by: dhuang <dhuang@MacBook-Pro.local>

* Pin numpy version to <=1.21.6 (#247)

search

search, download draft

draft, successful search and download

draft

Update: `ModelAnalysis.from_onnx(...)` to additionally work with loaded `ModelProto` (#253)

refactor

search, download

* lint

* pass tests

* init files

* lint

* Add dummy test using test-specific subclass

* tests

* add incremeent_downloads=False

* allow empty arguments

* comments

* query parser, allow dict as input, add tests for extra functionality

* restore models.utils

* restore models.utils

* v2 stub

* comments

* change stubs to ones on prod

* lint

* Update src/sparsezoo/model/utils.py

Co-authored-by: Danny Guinther <dannyguinther@gmail.com>

* Update src/sparsezoo/model/utils.py

Co-authored-by: Danny Guinther <dannyguinther@gmail.com>

* Update src/sparsezoo/api/utils.py

Co-authored-by: Danny Guinther <dannyguinther@gmail.com>

---------

Co-authored-by: Danny Guinther <dguinther@neuralmagic.com>
Co-authored-by: Jeannie Finks <74554921+jeanniefinks@users.noreply.github.com>
Co-authored-by: dhuangnm <74931910+dhuangnm@users.noreply.github.com>
Co-authored-by: dhuang <dhuang@MacBook-Pro.local>
Co-authored-by: Rahul Tuli <rahul@neuralmagic.com>
Co-authored-by: Danny Guinther <dannyguinther@gmail.com>
horheynm added a commit that referenced this pull request Apr 13, 2023
* Dummy graphql requests module

* graphql api request

* return Model instances

* Update NOTICE (#242)

license name change

* bump main to 1.4.0 (#246)

Co-authored-by: dhuang <dhuang@MacBook-Pro.local>

* Pin numpy version to <=1.21.6 (#247)

search

search, download draft

draft, successful search and download

draft

Update: `ModelAnalysis.from_onnx(...)` to additionally work with loaded `ModelProto` (#253)

refactor

search, download

* lint

* pass tests

* init files

* lint

* Add dummy test using test-specific subclass

* tests

* add incremeent_downloads=False

* allow empty arguments

* comments

* query parser, allow dict as input, add tests for extra functionality

* restore models.utils

* restore models.utils

* v2 stub

* comments

* change stubs to ones on prod

* lint

* Update src/sparsezoo/model/utils.py

Co-authored-by: Danny Guinther <dannyguinther@gmail.com>

* Update src/sparsezoo/model/utils.py

Co-authored-by: Danny Guinther <dannyguinther@gmail.com>

* Update src/sparsezoo/api/utils.py

Co-authored-by: Danny Guinther <dannyguinther@gmail.com>

---------

Co-authored-by: Danny Guinther <dguinther@neuralmagic.com>
Co-authored-by: Jeannie Finks <74554921+jeanniefinks@users.noreply.github.com>
Co-authored-by: dhuangnm <74931910+dhuangnm@users.noreply.github.com>
Co-authored-by: dhuang <dhuang@MacBook-Pro.local>
Co-authored-by: Rahul Tuli <rahul@neuralmagic.com>
Co-authored-by: Danny Guinther <dannyguinther@gmail.com>
horheynm added a commit that referenced this pull request Apr 17, 2023
* fix return type annotation and tests (#282)

Co-authored-by: Danny Guinther <dannyguinther@gmail.com>

* error handling - send message from graphql (#286)

* error handling - send message from graphql

Union to Optional

error message

* error message

* comments

* tests

* tests

* change def name

* error logic

* Stub v2 (#271)

* Dummy graphql requests module

* graphql api request

* return Model instances

* Update NOTICE (#242)

license name change

* bump main to 1.4.0 (#246)

Co-authored-by: dhuang <dhuang@MacBook-Pro.local>

* Pin numpy version to <=1.21.6 (#247)

search

search, download draft

draft, successful search and download

draft

Update: `ModelAnalysis.from_onnx(...)` to additionally work with loaded `ModelProto` (#253)

refactor

search, download

* lint

* pass tests

* init files

* lint

* Add dummy test using test-specific subclass

* tests

* add incremeent_downloads=False

* allow empty arguments

* comments

* query parser, allow dict as input, add tests for extra functionality

* restore models.utils

* restore models.utils

* v2 stub

* comments

* change stubs to ones on prod

* lint

* Update src/sparsezoo/model/utils.py

Co-authored-by: Danny Guinther <dannyguinther@gmail.com>

* Update src/sparsezoo/model/utils.py

Co-authored-by: Danny Guinther <dannyguinther@gmail.com>

* Update src/sparsezoo/api/utils.py

Co-authored-by: Danny Guinther <dannyguinther@gmail.com>

---------

Co-authored-by: Danny Guinther <dguinther@neuralmagic.com>
Co-authored-by: Jeannie Finks <74554921+jeanniefinks@users.noreply.github.com>
Co-authored-by: dhuangnm <74931910+dhuangnm@users.noreply.github.com>
Co-authored-by: dhuang <dhuang@MacBook-Pro.local>
Co-authored-by: Rahul Tuli <rahul@neuralmagic.com>
Co-authored-by: Danny Guinther <dannyguinther@gmail.com>

---------

Co-authored-by: Danny Guinther <dannyguinther@gmail.com>
Co-authored-by: Danny Guinther <dguinther@neuralmagic.com>
Co-authored-by: Jeannie Finks <74554921+jeanniefinks@users.noreply.github.com>
Co-authored-by: dhuangnm <74931910+dhuangnm@users.noreply.github.com>
Co-authored-by: dhuang <dhuang@MacBook-Pro.local>
Co-authored-by: Rahul Tuli <rahul@neuralmagic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants