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

Skip onnx.check_model if model is too large #1515

Merged
merged 3 commits into from
Apr 18, 2023
Merged
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
9 changes: 8 additions & 1 deletion src/sparseml/onnx/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,14 @@ def validate_onnx_file(path: str):
"""
try:
onnx_model = check_load_model(path)
onnx.checker.check_model(onnx_model)

if onnx_model.ByteSize() < onnx.checker.MAXIMUM_PROTOBUF:
Copy link
Contributor

Choose a reason for hiding this comment

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

Good idea with this check. But checking >2Gb models is supported after they had been saved:image

The crux is, you should call the checker:

  • not on the variable that holds a model in the memory
  • ...but on the path (string) to the model on disk (assuming that the external data file is in the same folder side-by-side with the model)

I will approve this PR, but planning to audit the onnx pathways later and see whether we can easily account for the large models as well.

Copy link
Contributor

@dbogunowicz dbogunowicz Apr 11, 2023

Choose a reason for hiding this comment

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

Wait, actually this pathway theoretically should work for both small and large onnx files - validate_path takes a path to the model as the input, this, in theory, should not fail...

onnx.checker.check_model(onnx_model)
else:
_LOGGER.warning(
"onnx check_model skipped as model exceeds maximum protobuf size of 2GB"
)

if not onnx_model.opset_import:
raise ValueError("could not parse opset_import")
except Exception as err:
Expand Down