Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions modelopt/onnx/quantization/quantize.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,16 @@ def _preprocess_onnx(
if simplify:
logger.info("Attempting to simplify model")
try:
import onnxsim
import onnxslim
except ModuleNotFoundError as e:
logger.warning(
"onnxsim is not installed. Please install it with 'pip install onnxsim'."
"onnxslim is not installed. Please install it with 'pip install onnxslim'."
)
raise e

try:
model_simp, check = onnxsim.simplify(onnx_model)
if check:
model_simp = onnxslim.slim(onnx_model)
if model_simp:
onnx_model = model_simp
onnx_path = os.path.join(output_dir, f"{model_name}_simp.onnx")
save_onnx(onnx_model, onnx_path, use_external_data_format)
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"onnxscript", # For test_onnx_dynamo_export unit test
"onnxsim ; python_version < '3.12' and platform_machine != 'aarch64'",
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove onnxsim installation if it's no longer being used, thanks.

Copy link
Author

Choose a reason for hiding this comment

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

done

"polygraphy>=0.49.22",
"onnxslim",
],
"hf": [
"accelerate>=1.0.0",
Expand Down
6 changes: 3 additions & 3 deletions tests/gpu/onnx/test_simplify.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ def test_onnx_simplification(tmp_path):
graph = gs.import_onnx(onnx.load(simplified_onnx_path))
identity_nodes = [n for n in graph.nodes if n.op == "Identity"]
assert not identity_nodes, "Simplified ONNX model contains Identity nodes but it shouldn't."
assert len(graph.nodes) == 3, (
f"Number of nodes doesn't match the expected: {len(graph.nodes)} vs 3."
assert len(graph.nodes) == 2, (
f"Number of nodes doesn't match the expected: {len(graph.nodes)} vs 2."
)
assert all(n.op in ["Conv", "BatchNormalization", "Relu"] for n in graph.nodes), (
assert all(n.op in ["Conv", "Relu"] for n in graph.nodes), (
"Graph contains more ops than expected."
)

Expand Down