This repository contains a script and information to convert a Huggingface models to CoreML.
- Model to transform: microsoft/DialoGPT-small Try it by executing in command line
$ python3 create-chat-model.py
- Also create this microsoft/DialoGPT-small
- 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
- https://huggingface.co/microsoft/DialoGPT-small?text=Hi.
- Converting from PyTorch
- Clone repo:
$ git clone https://github.com/madcato/huggingface-coreml.git
- Execute chatbot to try chatbot (optional),
$ python3 try.py
- Install huggingface exporters submodule,
$ git submodule init && git submodule update
$ cd exporters && pip3 install -e . && cd ..
python3 export
The last step will create two mlpackage
files in the exported
folder: one for decoder and another for decoder part of the model. These files can be opened with Xcode and the model can be tested in the playground or project.
$ python3 -m exporters.coreml --model=t5-small --feature=text2text-generation exported
$ python3 -m exporters.coreml --model=distilgpt2 --feature=text2text-generation exported
- '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'