Using LoRA adapters
BetaWorkers AI supports fine-tuned inference with adapters trained with Low-Rank Adaptation ↗. This feature is in open beta and free during this period.
- We only support LoRAs for the following models (must not be quantized):
@cf/meta-llama/llama-2-7b-chat-hf-lora
@cf/mistral/mistral-7b-instruct-v0.2-lora
@cf/google/gemma-2b-it-lora
@cf/google/gemma-7b-it-lora
- Adapter must be trained with rank
r <=8
. You can check the rank of a pre-trained LoRA adapter through the adapter’sconfig.json
file - LoRA adapter file must be < 100MB
- LoRA adapter files must be named
adapter_config.json
andadapter_model.safetensors
exactly - You can test up to 30 LoRA adapters per account
We have started a Hugging Face Collection ↗ that lists a few LoRA adapters that are compatible with Workers AI. Generally, any LoRA adapter that fits our limitations above should work.
To train your own LoRA adapter, follow the tutorial.
In order to run inference with LoRAs on Workers AI, you’ll need to create a new fine tune on your account and upload your adapter files. You should have a adapter_model.safetensors
file with model weights and adapter_config.json
with your config information. Note that we only accept adapter files in these types.
Right now, you can’t edit a fine tune’s asset files after you upload it. We will support this soon, but for now you will need to create a new fine tune and upload files again if you would like to use a new LoRA.
Before you upload your LoRA adapter, you’ll need to edit your adapter_config.json
file to include model_type
as one of mistral
, gemma
or llama
like below.
You can create a finetune and upload your LoRA adapter via wrangler with the following commands:
Alternatively, you can use our REST API to create a finetune and upload your adapter files. You will need a Cloudflare API Token with Workers AI: Edit
permissions to make calls to our REST API, which you can generate via the Cloudflare Dashboard.
You have to call the upload endpoint each time you want to upload a new file, so you usually run this once for adapter_model.safetensors
and once for adapter_config.json
. Make sure you include the @
before your path to files.
You can either use the finetune name
or id
that you used when you created the fine tune.
You can call this method to confirm what fine-tunes you have created in your account
To make inference requests and apply the LoRA adapter, you will need your model and finetune name
or id
. You should use the chat template that your LoRA was trained on, but you can try running it with raw: true
and the messages template like below.