| <!--Copyright 2023 The HuggingFace Team. All rights reserved. | |
| Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | |
| the License. You may obtain a copy of the License at | |
| http://www.apache.org/licenses/LICENSE-2.0 | |
| Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | |
| an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | |
| specific language governing permissions and limitations under the License. | |
| โ ๏ธ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be | |
| rendered properly in your Markdown viewer. | |
| --> | |
| # TFLite๋ก ๋ด๋ณด๋ด๊ธฐ[[export-to-tflite]] | |
| [TensorFlow Lite](https://www.tensorflow.org/lite/guide)๋ ์์์ด ์ ํ๋ ํด๋ํฐ, ์๋ฒ ๋๋ ์์คํ , ์ฌ๋ฌผ์ธํฐ๋ท(IoT) ๊ธฐ๊ธฐ์์ | |
| ๊ธฐ๊ณํ์ต ๋ชจ๋ธ์ ๋ฐฐํฌํ๊ธฐ ์ํ ๊ฒฝ๋ ํ๋ ์์ํฌ์ ๋๋ค. | |
| TFLite๋ ์ฐ์ฐ ๋ฅ๋ ฅ, ๋ฉ๋ชจ๋ฆฌ, ์ ๋ ฅ ์๋น๊ฐ ์ ํ๋ ๊ธฐ๊ธฐ์์ ๋ชจ๋ธ์ ํจ์จ์ ์ผ๋ก ์ต์ ํํ๊ณ ์คํํ๊ธฐ ์ํด | |
| ์ค๊ณ๋์์ต๋๋ค. | |
| TensorFlow Lite ๋ชจ๋ธ์ `.tflite` ํ์ผ ํ์ฅ์๋ก ์๋ณ๋๋ ํน์ํ๊ณ ํจ์จ์ ์ธ ํด๋์ฉ ํฌ๋งท์ผ๋ก ํํ๋ฉ๋๋ค. | |
| ๐ค Optimum์ `exporters.tflite` ๋ชจ๋๋ก ๐ค Transformers ๋ชจ๋ธ์ TFLite๋ก ๋ด๋ณด๋ด๋ ๊ธฐ๋ฅ์ ์ ๊ณตํฉ๋๋ค. | |
| ์ง์๋๋ ๋ชจ๋ธ ์ํคํ ์ฒ ๋ชฉ๋ก์ [๐ค Optimum ๋ฌธ์](https://huggingface.co/docs/optimum/exporters/tflite/overview)๋ฅผ ์ฐธ๊ณ ํ์ธ์. | |
| ๋ชจ๋ธ์ TFLite๋ก ๋ด๋ณด๋ด๋ ค๋ฉด, ํ์ํ ์ข ์์ฑ์ ์ค์นํ์ธ์: | |
| ```bash | |
| pip install optimum[exporters-tf] | |
| ``` | |
| ๋ชจ๋ ์ฌ์ฉ ๊ฐ๋ฅํ ์ธ์๋ฅผ ํ์ธํ๋ ค๋ฉด, [๐ค Optimum ๋ฌธ์](https://huggingface.co/docs/optimum/main/en/exporters/tflite/usage_guides/export_a_model)๋ฅผ ์ฐธ๊ณ ํ๊ฑฐ๋ | |
| ํฐ๋ฏธ๋์์ ๋์๋ง์ ์ดํด๋ณด์ธ์: | |
| ```bash | |
| optimum-cli export tflite --help | |
| ``` | |
| ์๋ฅผ ๋ค์ด ๐ค Hub์์์ `bert-base-uncased` ๋ชจ๋ธ ์ฒดํฌํฌ์ธํธ๋ฅผ ๋ด๋ณด๋ด๋ ค๋ฉด, ๋ค์ ๋ช ๋ น์ ์คํํ์ธ์: | |
| ```bash | |
| optimum-cli export tflite --model bert-base-uncased --sequence_length 128 bert_tflite/ | |
| ``` | |
| ๋ค์๊ณผ ๊ฐ์ด ์งํ ์ํฉ์ ๋ํ๋ด๋ ๋ก๊ทธ์ ๊ฒฐ๊ณผ๋ฌผ์ธ `model.tflite`๊ฐ ์ ์ฅ๋ ์์น๋ฅผ ๋ณด์ฌ์ฃผ๋ ๋ก๊ทธ๊ฐ ํ์๋ฉ๋๋ค: | |
| ```bash | |
| 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`๋ฅผ ์ ๋ฌํ๋ฉด ๋ฉ๋๋ค. |