๐ฆ llama.cpp
llama.cpp is a popular port of Facebook’s LLaMA model in C/C++.
Note
The ggml
file format has been deprecated. If you are using ggml
models and you are configuring your model with a YAML file, specify, use the llama-stable
backend instead. If you are relying in automatic detection of the model, you should be fine.
Features
The llama.cpp
model supports the following features:
Setup
LocalAI supports llama.cpp
models out of the box. You can use the llama.cpp
model in the same way as any other model.
Manual setup
It is sufficient to copy the ggml
model files in the models
folder. You can refer to the model in the model
parameter in the API calls.
You can optionally create an associated YAML model config file to tune the model’s parameters or apply a template to the prompt.
Prompt templates are useful for models that are fine-tuned towards a specific prompt.
Automatic setup
LocalAI supports model galleries which are indexes of models. For instance, the huggingface gallery contains a large curated index of models from the huggingface model hub for ggml
models.
For instance, if you have the galleries enabled, you can just start chatting with models in huggingface by running:
curl http://localhost:8080/v1/chat/completions -H "Content-Type: application/json" -d '{
"model": "TheBloke/WizardLM-13B-V1.2-GGML/wizardlm-13b-v1.2.ggmlv3.q2_K.bin",
"messages": [{"role": "user", "content": "Say this is a test!"}],
"temperature": 0.1
}'
LocalAI will automatically download and configure the model in the model
directory.
Models can be also preloaded or downloaded on demand. To learn about model galleries, check out the model gallery documentation.
YAML configuration
To use the llama.cpp
backend, specify
๐ ๐ฆ Exllama
Exllama is a “A more memory-efficient rewrite of the HF transformers implementation of Llama for use with quantized weights”
Prerequisites
This is an extra backend - in the container images is already available and there is nothing to do for the setup.
If you are building LocalAI locally, you need to install exllama manually first.
Model setup
Download the model as a folder inside the model
directory and create a YAML file specifying the exllama
backend. For instance with the TheBloke/WizardLM-7B-uncensored-GPTQ
model:
$ git lfs install
$ cd models && git clone https://huggingface.co/TheBloke/WizardLM-7B-uncensored-GPTQ
$ ls models/
.keep WizardLM-7B-uncensored-GPTQ/ exllama.yaml
$ cat models/exllama.yaml
name: exllama
parameters:
model: WizardLM-7B-uncensored-GPTQ
backend: exllama
# ...
Test with:
curl http://localhost:8080/v1/chat/completions -H "Content-Type: application/json" -d '{
"model": "exllama",
"messages": [{"role": "user", "content": "How are you?"}],
"temperature": 0.1
}'
๐ ๐ฆ AutoGPTQ
AutoGPTQ is an easy-to-use LLMs quantization package with user-friendly apis, based on GPTQ algorithm.
Prerequisites
This is an extra backend - in the container images is already available and there is nothing to do for the setup.
If you are building LocalAI locally, you need to install AutoGPTQ manually.
Model setup
The models are automatically downloaded from huggingface
if not present the first time. It is possible to define models via YAML
config file, or just by querying the endpoint with the huggingface
repository model name. For example, create a YAML
config file in models/
:
name: orca
backend: autogptq
model_base_name: "orca_mini_v2_13b-GPTQ-4bit-128g.no-act.order"
parameters:
model: "TheBloke/orca_mini_v2_13b-GPTQ"
# ...
Test with:
curl http://localhost:8080/v1/chat/completions -H "Content-Type: application/json" -d '{
"model": "orca",
"messages": [{"role": "user", "content": "How are you?"}],
"temperature": 0.1
}'
๐ ๐ถ Bark
Bark allows to generate audio from text prompts.
Setup
This is an extra backend - in the container is already available and there is nothing to do for the setup.
Model setup
There is nothing to be done for the model setup. You can already start to use bark. The models will be downloaded the first time you use the backend.
Usage
Use the tts
endpoint by specifying the bark
backend:
curl http://localhost:8080/tts -H "Content-Type: application/json" -d '{
"backend": "bark",
"input":"Hello!"
}' | aplay
To specify a voice from https://github.com/suno-ai/bark#-voice-presets ( https://suno-ai.notion.site/8b8e8749ed514b0cbf3f699013548683?v=bc67cff786b04b50b3ceb756fd05f68c ), use the model
parameter:
curl http://localhost:8080/tts -H "Content-Type: application/json" -d '{
"backend": "bark",
"input":"Hello!",
"model": "v2/en_speaker_4"
}' | aplay
๐ ๐งจ Diffusers
Diffusers is the go-to library for state-of-the-art pretrained diffusion models for generating images, audio, and even 3D structures of molecules. LocalAI has a diffusers backend which allows image generation using the diffusers
library.
(Generated with AnimagineXL)
Note: currently only the image generation is supported. It is experimental, so you might encounter some issues on models which weren’t tested yet.
Setup
This is an extra backend - in the container is already available and there is nothing to do for the setup.
Model setup
The models will be downloaded the first time you use the backend from huggingface
automatically.
Create a model configuration file in the models
directory, for instance to use Linaqruf/animagine-xl
with CPU:
name: animagine-xl
parameters:
model: Linaqruf/animagine-xl
backend: diffusers
# Force CPU usage - set to true for GPU
f16: false
diffusers:
pipeline_type: StableDiffusionXLPipeline
cuda: false # Enable for GPU usage (CUDA)
scheduler_type: euler_a
Local models
You can also use local models, or modify some parameters like clip_skip
, scheduler_type
, for instance:
name: stablediffusion
parameters:
model: toonyou_beta6.safetensors
backend: diffusers
step: 30
f16: true
diffusers:
pipeline_type: StableDiffusionPipeline
cuda: true
enable_parameters: "negative_prompt,num_inference_steps,clip_skip"
scheduler_type: "k_dpmpp_sde"
cfg_scale: 8
clip_skip: 11
Configuration parameters
The following parameters are available in the configuration file:
Parameter |
Description |
Default |
f16 |
Force the usage of float16 instead of float32 |
false |
step |
Number of steps to run the model for |
30 |
cuda |
Enable CUDA acceleration |
false |
enable_parameters |
Parameters to enable for the model |
negative_prompt,num_inference_steps,clip_skip |
scheduler_type |
Scheduler type |
k_dpp_sde |
cfg_scale |
Configuration scale |
8 |
clip_skip |
Clip skip |
None |
pipeline_type |
Pipeline type |
StableDiffusionPipeline |
There are available several types of schedulers:
Scheduler |
Description |
ddim |
DDIM |
pndm |
PNDM |
heun |
Heun |
unipc |
UniPC |
euler |
Euler |
euler_a |
Euler a |
lms |
LMS |
k_lms |
LMS Karras |
dpm_2 |
DPM2 |
k_dpm_2 |
DPM2 Karras |
dpm_2_a |
DPM2 a |
k_dpm_2_a |
DPM2 a Karras |
dpmpp_2m |
DPM++ 2M |
k_dpmpp_2m |
DPM++ 2M Karras |
dpmpp_sde |
DPM++ SDE |
k_dpmpp_sde |
DPM++ SDE Karras |
dpmpp_2m_sde |
DPM++ 2M SDE |
k_dpmpp_2m_sde |
DPM++ 2M SDE Karras |
Pipelines types available:
Pipeline type |
Description |
StableDiffusionPipeline |
Stable diffusion pipeline |
StableDiffusionImg2ImgPipeline |
Stable diffusion image to image pipeline |
StableDiffusionDepth2ImgPipeline |
Stable diffusion depth to image pipeline |
DiffusionPipeline |
Diffusion pipeline |
StableDiffusionXLPipeline |
Stable diffusion XL pipeline |
Usage
Text to Image
Use the image
generation endpoint with the model
name from the configuration file:
curl http://localhost:8080/v1/images/generations \
-H "Content-Type: application/json" \
-d '{
"prompt": "<positive prompt>|<negative prompt>",
"model": "animagine-xl",
"step": 51,
"size": "1024x1024"
}'
Image to Image
https://huggingface.co/docs/diffusers/using-diffusers/img2img
An example model (GPU):
name: stablediffusion-edit
parameters:
model: nitrosocke/Ghibli-Diffusion
backend: diffusers
step: 25
f16: true
diffusers:
pipeline_type: StableDiffusionImg2ImgPipeline
cuda: true
enable_parameters: "negative_prompt,num_inference_steps,image"
IMAGE_PATH=/path/to/your/image
(echo -n '{"image": "'; base64 $IMAGE_PATH; echo '", "prompt": "a sky background","size": "512x512","model":"stablediffusion-edit"}') |
curl -H "Content-Type: application/json" -d @- http://localhost:8080/v1/images/generations
Depth to Image
https://huggingface.co/docs/diffusers/using-diffusers/depth2img
name: stablediffusion-depth
parameters:
model: stabilityai/stable-diffusion-2-depth
backend: diffusers
step: 50
# Force CPU usage
f16: true
diffusers:
pipeline_type: StableDiffusionDepth2ImgPipeline
cuda: true
enable_parameters: "negative_prompt,num_inference_steps,image"
cfg_scale: 6
(echo -n '{"image": "'; base64 ~/path/to/image.jpeg; echo '", "prompt": "a sky background","size": "512x512","model":"stablediffusion-depth"}') |
curl -H "Content-Type: application/json" -d @- http://localhost:8080/v1/images/generations