Convert a Hugging Face Model to Cerebras Model Zoo
Learn how to convert Hugging Face models to the Cerebras Model Zoo format, enabling seamless deployment and optimization on Cerebras’s advanced hardware.
This guide uses the BertForPretraining
class as an example. You’ll download the checkpoint and config files, convert the checkpoint, verify the output, and then use the newly converted model.
Download Checkpoint and Config Files
First, you need to download the model’s checkpoint and configuration files from Hugging Face.
Here’s how you can do it for BertForPreTraining
:
This code will save two files in the bert_checkpoint
directory:
-
config.json: The model’s configuration file.
-
pytorch_model.bin: The model’s weights.
Convert Checkpoint to Cerebras Format
Now that you have the necessary files, you can convert them to a format compatible with the Cerebras Model Zoo. Use the provided conversion script in the Cerebras Model Zoo toolkit. Here’s the command:
Replace <modelzoo path>
with the actual path to the Model Zoo directory on your system.
Verify the Output
After running the conversion script, check the bert_checkpoint
directory for the output files:
-
pytorch_model_to_cs-2.0.mdl
: The converted model checkpoint. -
config_to_cs-2.0.yaml
: The converted configuration file.
Use the Converted Model
With the converted files, you can now use the Cerebras Model Zoo tools and workflows to further train or deploy the model on Cerebras hardware.
-
If you’re converting a different model (not BERT), replace
--model bert
with the appropriate model flag. -
If the model you’re converting has a specific variant or is a fine-tuning model, ensure you’re using the correct converter and flags as per the Cerebras documentation.