Build LocalAI
Build
LocalAI can be built as a container image or as a single, portable binary. Note that some model architectures might require Python libraries, which are not included in the binary.
LocalAI’s extensible architecture allows you to add your own backends, which can be written in any language, and as such the container images contains also the Python dependencies to run all the available backends (for example, in order to run backends like Diffusers that allows to generate images and videos from text).
This section contains instructions on how to build LocalAI from source.
Build LocalAI locally
Requirements
In order to build LocalAI locally, you need the following requirements:
- Golang >= 1.21
- GCC
- GRPC
To install the dependencies follow the instructions below:
Install xcode from the App Store
After you have golang installed and working, you can install the required binaries for compiling the golang protobuf components via the following commands
Build
To build LocalAI with make:
This should produce the binary local-ai
Container image
Requirements:
- Docker or podman, or a container engine
In order to build the LocalAI container image locally you can use docker, for example:
Example: Build on mac
Building on Mac (M1, M2 or M3) works, but you may need to install some prerequisites using brew.
The below has been tested by one mac user and found to work. Note that this doesn’t use Docker to run the server:
Install xcode from the Apps Store (needed for metalkit)
Troubleshooting mac
If you encounter errors regarding a missing utility metal, install
Xcodefrom the App Store.After the installation of Xcode, if you receive a xcrun error
'xcrun: error: unable to find utility "metal", not a developer tool or in PATH'. You might have installed the Xcode command line tools before installing Xcode, the former one is pointing to an incomplete SDK.
If completions are slow, ensure that
gpu-layersin your model yaml matches the number of layers from the model in use (or simply use a high number such as 256).If you get a compile error:
error: only virtual member functions can be marked 'final', reinstall all the necessary brew packages, clean the build, and try again.
Build backends
LocalAI have several backends available for installation in the backend gallery. The backends can be also built by source. As backends might vary from language and dependencies that they require, the documentation will provide generic guidance for few of the backends, which can be applied with some slight modifications also to the others.
Manually
Typically each backend include a Makefile which allow to package the backend.
In the LocalAI repository, for instance you can build bark-cpp by doing:
With Docker
Building with docker is simpler as abstracts away all the requirement, and focuses on building the final OCI images that are available in the gallery. This allows for instance also to build locally a backend and install it with LocalAI. You can refer to Backends for general guidance on how to install and develop backends.
In the LocalAI repository, you can build bark-cpp by doing:
Note that make is only by convenience, in reality it just runs a simple docker command as:
Note:
- BUILD_TYPE can be either:
cublas,hipblas,sycl_f16,sycl_f32,metal. - BASE_IMAGE is tested on
ubuntu:22.04(and defaults to it) andquay.io/go-skynet/intel-oneapi-base:latestfor intel/sycl