Run a Llama2 app
In this guide we create and deploy a llama2 inference server and expose an API to it. To run this example, follow these steps:
-
Install the
kraft
CLI tool and a container runtime engine, e.g. Docker. -
Clone the
examples
repository andcd
into theexamples/llama2/
directory:
Make sure to log into Unikraft Cloud by setting your token and a metro close to you.
We use fra0
(Frankfurt, 🇩🇪) in this guide:
When done, invoke the following command to deploy this application on Unikraft Cloud:
Note that in this example we assign 1GB of memory. The amount required will vary depending on the model (we’ll cover how to deploy different models below)
The output shows the instance URL and other details:
In this case, the instance name is llama2-cl5bw
and the URL is https://funky-rain-xds8dxbg.fra0.kraft.host
.
They are different for each run.
We can retrieve a story through the llama2
API endpoint:
At any point in time, you can list information about the instance:
When done, you can remove the instance:
Customize your Application
To customize the application, update the files in the repository, listed below:
Kraftfile
: the Unikraft Cloud specificationDockerfile
: the Docker-specified application filesystemtokenizer.bin
: Exposes an API for the modelstories15M.bin
: The LLM model.
Lines in the Kraftfile
have the following roles:
-
spec: v0.6
: The currentKraftfile
specification version is0.6
. -
runtime: llama2
: The Unikraft runtime kernel to use is llama2. -
rootfs: ./Dockerfile
: Build the application root filesystem using theDockerfile
. -
cmd: ["8080"]
: Expose the service via port 8080
Lines in the Dockerfile
have the following roles:
-
FROM alpine:3.14 as base
: Build the filesystem from thealpine:3.14
, to create a base image. -
COPY
: Copy the model and tokenizer to the Docker filesystem (to/models
).
The following options are available for customizing the application:
-
You can replace the model with others, for example from Hugging Face
-
The tokenizer we took from here, but feel free to replace it.
You can customize parameters for your story through a POST request on the same API endpoint. The following parameters are recognized:
prompt
: seed the LLM with a specific stringmodel
: use specific model instead of DEFAULTtemperature
: valid range 0.0 - 1.0; 0.0 is deterministic, 1.0 is original (default 1.0)topp
: valid range 0.0 - 1.0; top-p in nucleus sampling; 1.0 = off, 0.9 works well, but slower (default 0.9)
For example:
Learn More
Use the --help
option for detailed information on using Unikraft Cloud:
Or visit the CLI Reference.