Transformers documentation

Export to TFLite

You are viewing main version, which requires installation from source. If you'd like regular pip install, checkout the latest stable version (v4.40.2).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

Export to TFLite

TensorFlow Liteは、モバイルフォン、組み込みシステム、およびモノのインターネット(IoT)デバイスなど、リソースに制約のあるデバイスに機械学習モデルを展開するための軽量なフレームワークです。TFLiteは、計算能力、メモリ、および電力消費が限られているこれらのデバイス上でモデルを効率的に最適化して実行するために設計されています。 TensorFlow Liteモデルは、.tfliteファイル拡張子で識別される特別な効率的なポータブル形式で表されます。

🤗 Optimumは、🤗 TransformersモデルをTFLiteにエクスポートするための機能をexporters.tfliteモジュールを介して提供しています。サポートされているモデルアーキテクチャのリストについては、🤗 Optimumのドキュメントをご参照ください。

モデルをTFLiteにエクスポートするには、必要な依存関係をインストールしてください:

pip install optimum[exporters-tf]

すべての利用可能な引数を確認するには、🤗 Optimumドキュメントを参照するか、コマンドラインでヘルプを表示してください:

optimum-cli export tflite --help

🤗 Hubからモデルのチェックポイントをエクスポートするには、例えば google-bert/bert-base-uncased を使用する場合、次のコマンドを実行します:

optimum-cli export tflite --model google-bert/bert-base-uncased --sequence_length 128 bert_tflite/

進行状況を示すログが表示され、生成された model.tflite が保存された場所も表示されるはずです:

Validating TFLite model...
	-[✓] TFLite model output names match reference model (logits)
	- Validating TFLite Model output "logits":
		-[✓] (1, 128, 30522) matches (1, 128, 30522)
		-[x] values not close enough, max diff: 5.817413330078125e-05 (atol: 1e-05)
The TensorFlow Lite export succeeded with the warning: The maximum absolute difference between the output of the reference model and the TFLite exported model is not within the set tolerance 1e-05:
- logits: max diff = 5.817413330078125e-05.
 The exported model was saved at: bert_tflite

上記の例は🤗 Hubからチェックポイントをエクスポートする方法を示しています。ローカルモデルをエクスポートする場合、まずモデルの重みファイルとトークナイザファイルを同じディレクトリ(local_path)に保存したことを確認してください。CLIを使用する場合、🤗 Hubのチェックポイント名の代わりにmodel引数にlocal_pathを渡します。

< > Update on GitHub