Skip to content

Commit

Permalink
Update api backward compatibility (microsoft#20136)
Browse files Browse the repository at this point in the history
### Description
Update api backward compatibility

### Motivation and Context
Update api backward compatibility
  • Loading branch information
xiaoyu-work authored Apr 2, 2024
1 parent 3e2b659 commit 3979f53
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
12 changes: 10 additions & 2 deletions onnxruntime/python/tools/quantization/shape_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@


def quant_pre_process(
input_model: Union[str, Path, onnx.ModelProto],
output_model_path: Union[str, Path],
input_model: Optional[Union[str, Path, onnx.ModelProto]] = None,
output_model_path: Optional[Union[str, Path]] = None,
skip_optimization: bool = False,
skip_onnx_shape: bool = False,
skip_symbolic_shape: bool = False,
Expand All @@ -36,6 +36,7 @@ def quant_pre_process(
all_tensors_to_one_file: bool = False,
external_data_location: Optional[str] = None,
external_data_size_threshold: int = 1024,
**deprecated_kwargs,
) -> None:
"""Shape inference and model optimization, in preparation for quantization.
Expand Down Expand Up @@ -63,6 +64,13 @@ def quant_pre_process(
external_data_location: The file location to save the external file
external_data_size_threshold: The size threshold for external data
"""

if input_model is None:
input_model = deprecated_kwargs.pop("input_model_path", None)
assert input_model is not None

assert output_model_path is not None, "output_model_path is required."

with tempfile.TemporaryDirectory(prefix="pre.quant.") as quant_tmp_dir:
temp_path = Path(quant_tmp_dir)
model = None
Expand Down
7 changes: 6 additions & 1 deletion onnxruntime/python/tools/transformers/optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@


def optimize_by_onnxruntime(
onnx_model: Union[str, ModelProto],
onnx_model: Optional[Union[str, ModelProto]] = None,
use_gpu: bool = False,
optimized_model_path: Optional[str] = None,
opt_level: Optional[int] = 99,
Expand All @@ -79,6 +79,7 @@ def optimize_by_onnxruntime(
external_data_file_threshold: int = 1024,
*,
provider: Optional[str] = None,
**deprecated_kwargs,
) -> str:
"""
Use onnxruntime to optimize model.
Expand All @@ -99,6 +100,10 @@ def optimize_by_onnxruntime(
assert opt_level in [1, 2, 99]
from torch import version as torch_version

if onnx_model is None:
onnx_model = deprecated_kwargs.pop("onnx_model_path", None)
assert onnx_model is not None

if (
use_gpu
and provider is None
Expand Down

0 comments on commit 3979f53

Please sign in to comment.