Optimum
  • 🌍OVERVIEW
    • Optimum
    • Installation
    • Quick tour
    • Notebooks
    • 🌍CONCEPTUAL GUIDES
      • Quantization
  • 🌍HABANA
    • BOINC AI Optimum Habana
    • Installation
    • Quickstart
    • 🌍TUTORIALS
      • Overview
      • Single-HPU Training
      • Distributed Training
      • Run Inference
      • Stable Diffusion
      • LDM3D
    • 🌍HOW-TO GUIDES
      • Overview
      • Pretraining Transformers
      • Accelerating Training
      • Accelerating Inference
      • How to use DeepSpeed
      • Multi-node Training
    • 🌍CONCEPTUAL GUIDES
      • What are Habana's Gaudi and HPUs?
    • 🌍REFERENCE
      • Gaudi Trainer
      • Gaudi Configuration
      • Gaudi Stable Diffusion Pipeline
      • Distributed Runner
  • 🌍INTEL
    • BOINC AI Optimum Intel
    • Installation
    • 🌍NEURAL COMPRESSOR
      • Optimization
      • Distributed Training
      • Reference
    • 🌍OPENVINO
      • Models for inference
      • Optimization
      • Reference
  • 🌍AWS TRAINIUM/INFERENTIA
    • BOINC AI Optimum Neuron
  • 🌍FURIOSA
    • BOINC AI Optimum Furiosa
    • Installation
    • 🌍HOW-TO GUIDES
      • Overview
      • Modeling
      • Quantization
    • 🌍REFERENCE
      • Models
      • Configuration
      • Quantization
  • 🌍ONNX RUNTIME
    • Overview
    • Quick tour
    • 🌍HOW-TO GUIDES
      • Inference pipelines
      • Models for inference
      • How to apply graph optimization
      • How to apply dynamic and static quantization
      • How to accelerate training
      • Accelerated inference on NVIDIA GPUs
    • 🌍CONCEPTUAL GUIDES
      • ONNX And ONNX Runtime
    • 🌍REFERENCE
      • ONNX Runtime Models
      • Configuration
      • Optimization
      • Quantization
      • Trainer
  • 🌍EXPORTERS
    • Overview
    • The TasksManager
    • 🌍ONNX
      • Overview
      • 🌍HOW-TO GUIDES
        • Export a model to ONNX
        • Add support for exporting an architecture to ONNX
      • 🌍REFERENCE
        • ONNX configurations
        • Export functions
    • 🌍TFLITE
      • Overview
      • 🌍HOW-TO GUIDES
        • Export a model to TFLite
        • Add support for exporting an architecture to TFLite
      • 🌍REFERENCE
        • TFLite configurations
        • Export functions
  • 🌍TORCH FX
    • Overview
    • 🌍HOW-TO GUIDES
      • Optimization
    • 🌍CONCEPTUAL GUIDES
      • Symbolic tracer
    • 🌍REFERENCE
      • Optimization
  • 🌍BETTERTRANSFORMER
    • Overview
    • 🌍TUTORIALS
      • Convert Transformers models to use BetterTransformer
      • How to add support for new architectures?
  • 🌍LLM QUANTIZATION
    • GPTQ quantization
  • 🌍UTILITIES
    • Dummy input generators
    • Normalized configurations
Powered by GitBook
On this page
  • Export functions
  • Main functions
  • Utility functions
  1. EXPORTERS
  2. TFLITE
  3. REFERENCE

Export functions

PreviousTFLite configurationsNextTORCH FX

Last updated 1 year ago

Export functions

Main functions

optimum.exporters.tflite.export

( model: TFPreTrainedModelconfig: TFLiteConfigoutput: Pathtask: typing.Optional[str] = Nonepreprocessor: typing.Union[transformers.tokenization_utils_base.PreTrainedTokenizerBase, transformers.image_processing_utils.BaseImageProcessor, NoneType] = Nonequantization_config: typing.Optional[ForwardRef('TFLiteQuantizationConfig')] = None ) β†’ Tuple[List[str], List[str]]

Parameters

  • model (TFPreTrainedModel) β€” The model to export.

  • config () β€” 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: TFLiteConfigreference_model: TFPreTrainedModeltflite_model_path: Pathtflite_named_outputs: typing.List[str]atol: typing.Optional[float] = None )

Parameters

  • 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.

config ( β€” The configuration used to export the model.

🌍
🌍
🌍
<source>
TFLiteConfig
<source>
TFLiteConfig