Skip to content

[ONNX] Add external_data_dir backend parameter #3443

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

Open
wants to merge 13 commits into
base: develop
Choose a base branch
from

Conversation

andrey-churkin
Copy link
Contributor

@andrey-churkin andrey-churkin commented Apr 18, 2025

Changes

  • Added the BackendParameters.EXTERNAL_DATA_DIR parameter for the ONNX backend. This parameter specifies the absolute path to the directory where the model’s external data files are stored. All external data files must be located in the same directory. It should be used when the model is loaded without external data using onnx.load("model.onnx", load_external_data=False), and the external data files are not in the current working directory of the process. This parameter can be omitted if the external data files are located in the current working directory of the process.

  • Added check_model_protobuf_size() and check_external_data_location() validation checks. After this PR, calling nncf.quantize() on an ONNX model with a protobuf size exceeding 2GB will raise an nncf.ValidationError. The check_external_data_location() method ensures that the external data files can be successfully located.

Reason for changes

Any proto in serialized form must be <2GB (Total Size of the Message)

To use ort.InferenceSession(), we call model.SerializeToString() to pass the model as bytes. However, for large models (greater than 2GB), the serialized form also exceeds 2GB, which is not supported. As a result, passing such a model to ort.InferenceSession() causes an error during inference.

Related tickets

Ref: 164211

Tests

Current scope

@andrey-churkin andrey-churkin requested a review from alexsu52 April 18, 2025 09:49
@andrey-churkin andrey-churkin requested a review from a team as a code owner April 18, 2025 09:49
@github-actions github-actions bot added NNCF ONNX Pull requests that updates NNCF ONNX NNCF PTQ Pull requests that updates NNCF PTQ API Public API-impacting changes labels Apr 18, 2025

external_data_dir = get_external_data_dir(advanced_parameters)
if external_data_dir:
model.metadata_props.add(key="nncf.external_data_dir", value=external_data_dir)
Copy link
Contributor

Choose a reason for hiding this comment

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

Will NNCF return a model with metadata_props nncf.external_data_dir?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a good question. I will check. We probably shouldn't do that.

Adding this parameter to metadata_props is just one possible solution (the simplest one that requires minimal changes). We could also pass such a parameter explicitly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@alexsu52 alexsu52 self-assigned this Apr 20, 2025
@andrey-churkin andrey-churkin requested a review from alexsu52 April 24, 2025 13:27
@andrey-churkin
Copy link
Contributor Author

@alexsu52 Could you please take another look?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Public API-impacting changes NNCF ONNX Pull requests that updates NNCF ONNX NNCF PTQ Pull requests that updates NNCF PTQ
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants