Huggingface to CoreML
This repository contains a script and information to convert a Huggingface models to CoreML.
Info
- Model to transform: “facebook/blenderbot-400M-distill”Example of usage Try it by executing in command line
$ python3 try.py
Links
- HuggingFace
- HuggingFace Transformers
- HuggingFace Core ML Models
- Using Stable Diffusion with Core ML on Apple Silicon
- Export Hugging Face models to Core ML and TensorFlow Lite
- Swift Core ML implementations of Transformers: GPT-2, DistilGPT-2, BERT, DistilBERT, more coming soon!
- Figuring out the shape of a Transformer Model To translate it to a coreML model
- Core ML Stable Diffusion
- Deploying Transformers on the Apple Neural Engine
- Swift app demonstrating Core ML Stable Diffusion
- Apple Core ML –BenderbotTokenizer doc
- BenderbotTokenizer implementation
Initial steps
- Clone repo:
$ git clone https://github.com/madcato/huggingface-coreml.git
- Execute chatbot to download model,
$ python3 try.py
- Install huggingface exporters submodule,
$ git submodule init && git submodule update
$ cd exporters && pip3 install -e . && cd ..
python3 -m exporters.coreml --model=facebook/blenderbot-400M-distill exported/ --feature=text2text-generation
The last step will create an mlpackage
file in the exported
folder. This file can be opened with Xcode and the model can be tested in the playground or project.
Exporters features
- ‘feature-extraction’,
- ‘feature-extraction-with-past’,
- ‘fill-mask’,
- ‘image-classification’,
- ‘masked-im’,
- ‘multiple-choice’,
- ‘next-sentence-prediction’,
- ‘object-detection’,
- ‘question-answering’,
- ‘semantic-segmentation’,
- ‘text-classification’,
- ‘text-generation’,
- ‘text-generation-with-past’,
- ‘text2text-generation’,
- ‘token-classification’,
- ‘sequence-classification’,
- ‘causal-lm’,
- ‘causal-lm-with-past’,
- ‘seq2seq-lm’,
- ‘seq2seq-lm-with-past’,
- ‘speech2seq-lm’,
- ‘speech2seq-lm-with-past’,
- ‘masked-lm’,
- ‘vision2seq-lm’,
- ‘default’,
- ‘default-with-past’,
- ‘automatic-speech-recognition’,
- ‘ctc’