Spaces:
Runtime error
TFLite๋ก ๋ด๋ณด๋ด๊ธฐ[[export-to-tflite]]
TensorFlow Lite๋ ์์์ด ์ ํ๋ ํด๋ํฐ, ์๋ฒ ๋๋ ์์คํ
, ์ฌ๋ฌผ์ธํฐ๋ท(IoT) ๊ธฐ๊ธฐ์์
๊ธฐ๊ณํ์ต ๋ชจ๋ธ์ ๋ฐฐํฌํ๊ธฐ ์ํ ๊ฒฝ๋ ํ๋ ์์ํฌ์
๋๋ค.
TFLite๋ ์ฐ์ฐ ๋ฅ๋ ฅ, ๋ฉ๋ชจ๋ฆฌ, ์ ๋ ฅ ์๋น๊ฐ ์ ํ๋ ๊ธฐ๊ธฐ์์ ๋ชจ๋ธ์ ํจ์จ์ ์ผ๋ก ์ต์ ํํ๊ณ ์คํํ๊ธฐ ์ํด
์ค๊ณ๋์์ต๋๋ค.
TensorFlow Lite ๋ชจ๋ธ์ .tflite
ํ์ผ ํ์ฅ์๋ก ์๋ณ๋๋ ํน์ํ๊ณ ํจ์จ์ ์ธ ํด๋์ฉ ํฌ๋งท์ผ๋ก ํํ๋ฉ๋๋ค.
๐ค Optimum์ exporters.tflite
๋ชจ๋๋ก ๐ค Transformers ๋ชจ๋ธ์ TFLite๋ก ๋ด๋ณด๋ด๋ ๊ธฐ๋ฅ์ ์ ๊ณตํฉ๋๋ค.
์ง์๋๋ ๋ชจ๋ธ ์ํคํ
์ฒ ๋ชฉ๋ก์ ๐ค Optimum ๋ฌธ์๋ฅผ ์ฐธ๊ณ ํ์ธ์.
๋ชจ๋ธ์ TFLite๋ก ๋ด๋ณด๋ด๋ ค๋ฉด, ํ์ํ ์ข ์์ฑ์ ์ค์นํ์ธ์:
pip install optimum[exporters-tf]
๋ชจ๋ ์ฌ์ฉ ๊ฐ๋ฅํ ์ธ์๋ฅผ ํ์ธํ๋ ค๋ฉด, ๐ค Optimum ๋ฌธ์๋ฅผ ์ฐธ๊ณ ํ๊ฑฐ๋ ํฐ๋ฏธ๋์์ ๋์๋ง์ ์ดํด๋ณด์ธ์:
optimum-cli export tflite --help
์๋ฅผ ๋ค์ด ๐ค Hub์์์ bert-base-uncased
๋ชจ๋ธ ์ฒดํฌํฌ์ธํธ๋ฅผ ๋ด๋ณด๋ด๋ ค๋ฉด, ๋ค์ ๋ช
๋ น์ ์คํํ์ธ์:
optimum-cli export tflite --model 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
๋ฅผ ์ ๋ฌํ๋ฉด ๋ฉ๋๋ค.