Optimum documentation

Export functions

You are viewing v1.7.3 version. A newer version v1.14.0 is available.
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

Export functions

Main functions

optimum.exporters.tflite.export

< >

( model: TFPreTrainedModel config: TFLiteConfig output: Path task: typing.Optional[str] = None preprocessor: typing.Union[transformers.tokenization_utils_base.PreTrainedTokenizerBase, transformers.image_processing_utils.BaseImageProcessor, NoneType] = None quantization_config: typing.Optional[ForwardRef('TFLiteQuantizationConfig')] = None ) → Tuple[List[str], List[str]]

Parameters

  • model (TFPreTrainedModel) — The model to export.
  • config (TFLiteConfig) — The TFLite configuration associated with the exported model.
  • output (Path) — Directory to store the exported TFLite model.
  • task (Optional[str], defaults to None) — The task of the model. If left unspecified the task will be inferred automatically. Only needed for static quantization.
  • preprocessor (Optional[Preprocessor], defaults to None) — The preprocessor associated to the model. This is used for preprocessing the dataset before feeding data to the model during calibration.
  • quantization_config (Optional[TFLiteQuantizationConfig], defaults to None) — The dataclass containing all the needed information to perform quantization.

Returns

Tuple[List[str], List[str]]

A tuple with an ordered list of the model’s inputs, and the named inputs from the TFLite configuration.

Exports a TensorFlow model to a TensorFlow Lite model.

Utility functions

optimum.exporters.tflite.validate_model_outputs

< >

( config: TFLiteConfig reference_model: TFPreTrainedModel tflite_model_path: Path tflite_named_outputs: typing.List[str] atol: typing.Optional[float] = None )

Parameters

  • config (TFLiteConfig — The configuration used to export the model.
  • reference_model (~TFPreTrainedModel) — The model used for the export.
  • tflite_model_path (Path) — The path to the exported model.
  • tflite_named_outputs (List[str]) — The names of the outputs to check.
  • atol (Optional[float], defaults to None) — The absolute tolerance in terms of outputs difference between the reference and the exported model.

Raises

ValueError

  • ValueError — If the outputs shapes or values do not match between the reference and the exported model.

Validates the export by checking that the outputs from both the reference and the exported model match.