optimum-onnx documentation
Optimization
Optimization
ORTOptimizer
class optimum.onnxruntime.ORTOptimizer
< source >( onnx_model_path: list[os.PathLike] config: PretrainedConfig from_ortmodel: bool = False )
Handles the ONNX Runtime optimization process for models shared on huggingface.co/models.
from_pretrained
< source >( model_or_path: str | os.PathLike | ORTModel file_names: list[str] | None = None )
Parameters
- model_or_path (
Union[str, os.PathLike, ORTModel]) — The path to a local directory hosting the model to optimize or an instance of anORTModelto quantize. Can be either:- A path to a local directory containing the model to optimize.
- An instance of ORTModel.
- file_names(
Optional[List[str]], defaults toNone) — The list of file names of the models to optimize.
Initializes the ORTOptimizer from a local directory or an ORTModel.
get_fused_operators
< source >( onnx_model_path: str | os.PathLike )
Computes the dictionary mapping the name of the fused operators to their number of apparition in the model.
get_nodes_number_difference
< source >( onnx_model_path: str | os.PathLike onnx_optimized_model_path: str | os.PathLike )
Compute the difference in the number of nodes between the original and the optimized model.
get_operators_difference
< source >( onnx_model_path: str | os.PathLike onnx_optimized_model_path: str | os.PathLike )
Compute the dictionary mapping the operators name to the difference in the number of corresponding nodes between the original and the optimized model.
optimize
< source >( optimization_config: OptimizationConfig save_dir: str | os.PathLike file_suffix: str | None = 'optimized' one_external_file: bool = True )
Parameters
- optimization_config (OptimizationConfig) — The configuration containing the parameters related to optimization.
- save_dir (
Union[str, os.PathLike]) — The path used to save the optimized model. - file_suffix (
str, defaults to"optimized") — The file suffix used to save the optimized model. - one_external_file (
bool, defaults toTrue) — Whenuse_external_data_format=True, whether to save all tensors to one external file. If False, save each tensor to a file named with the tensor name.
Optimizes a model given the optimization specifications defined in optimization_config.