onnxruntime
09927171 - Add regression test for quantize_static with in-memory ModelProto (#23268) (#28201)

Commit
85 days ago
Add regression test for quantize_static with in-memory ModelProto (#23268) (#28201) ### Description Adds a regression test covering the bug reported in #23268 and fixed in #23322. Before #23322, calling `quantize_static()` with an in-memory `ModelProto` whose weights were large enough (>= 1024 bytes) to trigger ONNX's external-data serialization would mutate the caller's `ModelProto` inside `save_and_reload_model_with_shape_infer` (via `onnx.save_model(..., save_as_external_data=True)`), clearing `raw_data` and pointing the tensor at a temp-directory path that was then deleted. Subsequent calibration would load the now-invalid proto and raise `onnx.onnx_cpp2py_export.checker.ValidationError`. PR #23322 addressed the issue by wrapping the input proto in `copy.deepcopy` inside `save_and_reload_model_with_shape_infer`, but no regression test was added. This PR adds that test. ### Motivation and Context Fixes #23268 (adds the missing regression test for the original bug). ### Changes - `onnxruntime/test/python/quantization/test_quant_issues.py` — adds `test_issue_23268_quantize_static_modelproto_no_validation_error` to `TestQuantIssues`. The test builds an in-memory Add model with a 32x32 float32 initializer (4096 bytes, above the 1024-byte external-data threshold), runs `quantize_static` against it with an inline minimal calibration reader, and asserts the call completes without raising and produces a quantized output file. No production code changes. ### Test Plan ``` python -m pytest onnxruntime/test/python/quantization/test_quant_issues.py -v ``` Both tests pass locally (`test_minimal_model` and the new `test_issue_23268_quantize_static_modelproto_no_validation_error`) in ~0.6s. `lintrunner -a` is clean.
Author
Parents
Loading