🤗 Optimum provides an optimum.onnxruntime package that enables you to apply graph optimization on many model hosted on the 🤗 hub using the ONNX Runtime model optimization tool.
( preprocessor: typing.Union[transformers.models.auto.feature_extraction_auto.AutoFeatureExtractor, transformers.models.auto.processing_auto.AutoProcessor, transformers.models.auto.tokenization_auto.AutoTokenizer] model: PreTrainedModel feature: str = 'default' opset: typing.Optional[int] = None )
Handles the ONNX Runtime optimization process for models shared on huggingface.co/models.
( onnx_model_path: typing.Union[str, os.PathLike] onnx_optimized_model_output_path: typing.Union[str, os.PathLike] optimization_config: OptimizationConfig use_external_data_format: bool = False )
Parameters
Union[str, os.PathLike]) —
The path used to save the model exported to an ONNX Intermediate Representation (IR).
Union[str, os.PathLike]) —
The path used to save the optimized model exported to an ONNX Intermediate Representation (IR).
OptimizationConfig) —
The configuration containing the parameters related to optimization.
bool, defaults to False) —
Whether uto se external data format to store model which size is >= 2Gb.
Optimize a model given the optimization specifications defined in optimization_config.
( model_name_or_path: typing.Union[str, os.PathLike] feature: str opset: typing.Optional[int] = None )
Instantiate a ORTOptimizer from a pretrained pytorch model and preprocessor.
( onnx_model_path: typing.Union[str, os.PathLike] )
Compute the dictionary mapping the name of the fused operators to their number of apparition in the model.
( onnx_model_path: typing.Union[str, os.PathLike] onnx_optimized_model_path: typing.Union[str, os.PathLike] )
Compute the difference in the number of nodes between the original and the optimized model.
( onnx_model_path: typing.Union[str, os.PathLike] onnx_optimized_model_path: typing.Union[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.