Skip to content
This repository was archived by the owner on Jun 3, 2025. It is now read-only.

Commit a574de1

Browse files
authored
Add:Support for ONNX versions 1.8.*, 1.9.* upto 1.10.1 (#365)
* Replaced usage of onnx.helpers.make_model(model.graph) to deepcopy(model) in [file](https://github.com/neuralmagic/sparseml/blob/main/src/sparseml/onnx/utils/helpers.py) because opset and ir_versions were lost in the process initially which broke Tests when using onnx versions>=1.8.0 * Added explicit IR_VERSION=6 in usages of onnx.helpers.make_model(...) in [file](https://github.com/neuralmagic/sparseml/blob/main/tests/sparseml/onnx/optim/quantization/helpers.py) * Updated setup.py to install latest onnx version(at the time of this PR) when installing using pip -e ... Tested on `Python 3.6.9`, and Linux/Debian system, Tests ran:`make test TARGETS=onnx`
1 parent 2a19442 commit a574de1

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"numpy>=1.0.0",
3939
"matplotlib>=3.0.0",
4040
"merge-args>=0.1.0",
41-
"onnx>=1.5.0,<1.8.0",
41+
"onnx>=1.5.0,<=1.10.1",
4242
"onnxruntime>=1.0.0",
4343
"pandas>=0.25.0",
4444
"packaging>=20.0",

src/sparseml/onnx/utils/helpers.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@
1818

1919
import logging
2020
from collections import OrderedDict
21+
from copy import deepcopy
2122
from functools import reduce
2223
from typing import Any, Dict, List, NamedTuple, Tuple, Union
2324

2425
import numpy
2526
import onnx
2627
import onnxruntime
2728
from onnx import ModelProto, NodeProto, TensorProto, numpy_helper
28-
from onnx.helper import get_attribute_value, make_empty_tensor_value_info, make_model
29+
from onnx.helper import get_attribute_value, make_empty_tensor_value_info
2930

3031
from sparseml.utils import clean_path
3132

@@ -240,7 +241,7 @@ def extract_nodes_shapes_ort(model: ModelProto) -> Dict[str, List[List[int]]]:
240241
:param model: an ONNX model
241242
:return: a list of NodeArg with their shape exposed
242243
"""
243-
model_copy = make_model(model.graph)
244+
model_copy = deepcopy(model)
244245

245246
for node in model_copy.graph.node:
246247
intermediate_layer_value_info = make_empty_tensor_value_info(
@@ -277,7 +278,7 @@ def extract_nodes_shapes_shape_inference(
277278
:param model: an ONNX model
278279
:return: a list of NodeProto with their shape exposed
279280
"""
280-
model_copy = make_model(model.graph)
281+
model_copy = deepcopy(model)
281282

282283
for node in model_copy.graph.node:
283284
model_copy.graph.output.extend(

tests/sparseml/onnx/optim/quantization/helpers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def onnx_conv_net() -> ModelProto:
135135
],
136136
)
137137
opset_id = onnx.helper.make_opsetid("", 11)
138-
model = onnx.helper.make_model(graph, opset_imports=[opset_id])
138+
model = onnx.helper.make_model(graph, opset_imports=[opset_id], ir_version=6)
139139
return model
140140

141141

@@ -174,5 +174,5 @@ def onnx_linear_net() -> ModelProto:
174174
[matmul1_weight, matmul2_weight],
175175
)
176176
opset_id = onnx.helper.make_opsetid("", 11)
177-
model = onnx.helper.make_model(graph, opset_imports=[opset_id])
177+
model = onnx.helper.make_model(graph, opset_imports=[opset_id], ir_version=6)
178178
return model

0 commit comments

Comments
 (0)