This repository was archived by the owner on Jun 3, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
ModelAnalysis.create(...)
#281
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
79d9185
Moved: analysis namespace to analyze
rahul-tuli 09ee921
Remove: code used for local debugging
rahul-tuli d1bb60e
Propagate: changes to tests
rahul-tuli be00b52
Add missed file
rahul-tuli 2b9842e
Add: `flake8: noqa` to files that violate F811 as these errors are no…
rahul-tuli 823e4ce
Conform Analyze CLI with PRD (#280)
rahul-tuli 6567cc7
Add a `.create(...)` function for `ModelAnalysis`
rahul-tuli d6b810d
Style
rahul-tuli 04dc5b5
Remove unintended typo
rahul-tuli 229500d
fix yaml tests
rahul-tuli fee3753
Merge remote-tracking branch 'origin/main' into analyze-compare-funct…
rahul-tuli d57817e
Resolve: merge conflicts
rahul-tuli 41ebf7c
Rework: ModelAnalysis.create(...) if else ladder to load onnx file ir…
rahul-tuli 44d440f
Merge branch 'main' into analyze-compare-functionality
rahul-tuli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# 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. | ||
|
||
from pathlib import Path | ||
|
||
import onnx | ||
import pytest | ||
|
||
from sparsezoo import Model | ||
from sparsezoo.analyze import ModelAnalysis | ||
|
||
|
||
def onnx_stub(): | ||
return ( | ||
"zoo:cv/classification/resnet_v1-50/pytorch/sparseml/" | ||
"imagenet/pruned95_quant-none" | ||
) | ||
|
||
|
||
def onnx_deployment_dir(): | ||
return Model(onnx_stub()).deployment.path | ||
|
||
|
||
def onnx_local_path(): | ||
return str(Path(onnx_deployment_dir()) / "model.onnx") | ||
|
||
|
||
def onnx_model(): | ||
return onnx.load(onnx_local_path()) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"file_path, should_error", | ||
[ | ||
(onnx_stub(), False), | ||
(onnx_deployment_dir(), False), | ||
(onnx_local_path(), False), | ||
(onnx_model(), False), | ||
(1, True), | ||
], | ||
) | ||
def test_create(file_path, should_error): | ||
if should_error: | ||
with pytest.raises(ValueError, match="Invalid"): | ||
ModelAnalysis.create(file_path) | ||
else: | ||
analysis = ModelAnalysis.create(file_path) | ||
assert isinstance(analysis, ModelAnalysis) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"model_path", | ||
[ | ||
onnx_local_path(), | ||
], | ||
) | ||
def test_yaml_serialization(model_path, tmp_path): | ||
analysis = ModelAnalysis.create(file_path=model_path) | ||
|
||
yaml_file = str(tmp_path / "quantized-resnet.yaml") | ||
analysis.yaml(file_path=yaml_file) | ||
|
||
analysis_from_yaml = ModelAnalysis.create(file_path=yaml_file) | ||
|
||
assert analysis.yaml() == analysis_from_yaml.yaml() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.