Skip to main content

serve

Synopsis

ramalama serve [options] model

Description

Serve specified AI Model as a chat bot. RamaLama pulls specified AI Model from registry if it does not exist in local storage.

MODEL TRANSPORTS

RamaLama defaults to the Ollama registry transport. This default can be overridden in the ramalama.conf file or via the RAMALAMA_TRANSPORTS environment. export RAMALAMA_TRANSPORT=huggingface Changes RamaLama to use huggingface transport. Modify individual model transports by specifying the huggingface://, oci://, ollama://, https://, http://, file:// prefix to the model. URL support means if a model is on a web site or even on your local system, you can run it directly.

REST API ENDPOINTS

Under the hood, ramalama-serve uses the llama.cpp HTTP server by default. When using --runtime=vllm, it uses the vLLM server. When using --runtime=mlx, it uses the MLX LM server. For REST API endpoint documentation, see:

Options

—add-to-unit

format: —add-to-unit section:key:value Adds to the generated unit file (quadlet) in the section section the key key with the value value. Useful, for instance, to add environment variables to the generated unit file, or to place the container in a specific pod/network (Container:Network:xxx.network). Only valid with —generate parameter. Section, key and value are required and must be separated by colons.

—api=llama-stack | none**

Unified API layer for Inference, RAG, Agents, Tools, Safety, Evals, and Telemetry.(default: none) The default can be overridden in the ramalama.conf file.

—authfile=password

Path of the authentication file for OCI registries

—cache-reuse=256

Min chunk size to attempt reusing from the cache via KV shifting

—ctx-size, -c

size of the prompt context. This option is also available as —max-model-len. Applies to llama.cpp and vllm regardless of alias (default: 4096, 0 = loaded from model)

—detach, -d

Run the container in the background and print the new container ID. The default is TRUE. The —nocontainer option forces this option to False. Use the ramalama stop command to stop the container running the served ramalama Model.

—device

Add a host device to the container. Optional permissions parameter can be used to specify device permissions by combining r for read, w for write, and m for mknod(2). Example: —device=/dev/dri/renderD128:/dev/xvdc:rwm The device specification is passed directly to the underlying container engine. See documentation of the supported container engine for more information. Pass ‘—device=none’ explicitly add no device to the container, eg for running a CPU-only performance comparison.

—dri=on | off

Enable or disable mounting /dev/dri into the container when running with --api=llama-stack (enabled by default). Use to prevent access to the host device when not required, or avoid errors in environments where /dev/dri is not available.

—env=

Set environment variables inside of the container. This option allows arbitrary environment variables that are available for the process to be launched inside of the container. If an environment variable is specified without a value, the container engine checks the host environment for a value and set the variable only if it is set on the host.

—generate=type

Generate specified configuration format for running the AI Model as a service Optionally, an output directory for the generated files can be specified by appending the path to the type, e.g. --generate kube:/etc/containers/systemd.

—help, -h

show this help message and exit

—host=“0.0.0.0”

IP address for llama.cpp to listen on.

—image=IMAGE

OCI container image to run with specified AI model. RamaLama defaults to using images based on the accelerator it discovers. For example: quay.io/ramalama/ramalama. See the table above for all default images. The default image tag is based on the minor version of the RamaLama package. Version 0.13.0 of RamaLama pulls an image with a :0.12 tag from the quay.io/ramalama OCI repository. The —image option overrides this default. The default can be overridden in the ramalama.conf file or via the RAMALAMA_IMAGE environment variable. export RAMALAMA_IMAGE=quay.io/ramalama/aiimage:1.2 tells RamaLama to use the quay.io/ramalama/aiimage:1.2 image. Accelerated images:

—keep-groups

pass —group-add keep-groups to podman (default: False) If GPU device on host system is accessible to user via group access, this option leaks the groups into the container.

—max-tokens=integer

Maximum number of tokens to generate. Set to 0 for unlimited output (default: 0). This parameter is mapped to the appropriate runtime-specific parameter:
  • llama.cpp: -n parameter
  • MLX: --max-tokens parameter
  • vLLM: --max-tokens parameter

—model-draft

A draft model is a smaller, faster model that helps accelerate the decoding process of larger, more complex models, like Large Language Models (LLMs). It works by generating candidate sequences of tokens that the larger model then verifies and refines. This approach, often referred to as speculative decoding, can significantly improve the speed of inferencing by reducing the number of times the larger model needs to be invoked. Use —runtime-arg to pass the other draft model related parameters. Make sure the sampling parameters like top_k on the web UI are set correctly.

—name, -n

Name of the container to run the Model in.

—network=""

set the network mode for the container

—ngl

number of gpu layers, 0 means CPU inferencing, 999 means use max layers (default: -1) The default -1, means use whatever is automatically deemed appropriate (0 or 999)

—oci-runtime

Override the default OCI runtime used to launch the container. Container engines like Podman and Docker, have their own default oci runtime that they use. Using this option RamaLama will override these defaults. On Nvidia based GPU systems, RamaLama defaults to using the nvidia-container-runtime. Use this option to override this selection.

—port, -p

port for AI Model server to listen on. It must be available. If not specified, the serving port will be 8080 if available, otherwise a free port in 8081-8090 range.

—privileged

By default, RamaLama containers are unprivileged (=false) and cannot, for example, modify parts of the operating system. This is because by de‐ fault a container is only allowed limited access to devices. A “privi‐ leged” container is given the same access to devices as the user launch‐ ing the container, with the exception of virtual consoles (/dev/tty\d+) when running in systemd mode (—systemd=always). A privileged container turns off the security features that isolate the container from the host. Dropped Capabilities, limited devices, read- only mount points, Apparmor/SELinux separation, and Seccomp filters are all disabled. Due to the disabled security features, the privileged field should almost never be set as containers can easily break out of confinement. Containers running in a user namespace (e.g., rootless containers) can‐ not have more privileges than the user that launched them.

—pull=policy

  • always: Always pull the image and throw an error if the pull fails.
  • missing: Only pull the image when it does not exist in the local containers storage. Throw an error if no image is found and the pull fails.
  • never: Never pull the image but use the one from the local containers storage. Throw an error when no image is found.
  • newer: Pull if the image on the registry is newer than the one in the local containers storage. An image is considered to be newer when the digests are different. Comparing the time stamps is prone to errors. Pull errors are suppressed if a local image was found.

—rag=

Specify path to Retrieval-Augmented Generation (RAG) database or an OCI Image containing a RAG database :::note RAG support requires AI Models be run within containers, —nocontainer not supported. Docker does not support image mounting, meaning Podman support required. :::

—runtime-args=“args

Add args to the runtime (llama.cpp or vllm) invocation.

—seed=

Specify seed rather than using random seed model interaction

—selinux=true

Enable SELinux container separation

—temp=“0.8”

Temperature of the response from the AI Model. llama.cpp explains this as: The lower the number is, the more deterministic the response. The higher the number is the more creative the response is, but more likely to hallucinate when set too high. Usage: Lower numbers are good for virtual assistants where we need deterministic responses. Higher numbers are good for roleplay or creative tasks like editing stories

—thinking=true

Enable or disable thinking mode in reasoning models

—threads, -t

Maximum number of cpu threads to use. The default is to use half the cores available on this system for the number of threads.

—tls-verify=true

require HTTPS and verify certificates when contacting OCI registries

—webui=on | off

Enable or disable the web UI for the served model (enabled by default). When set to “on” (the default), the web interface is properly initialized. When set to “off”, the --no-webui option is passed to the llama-server command to disable the web interface.

Examples

Run two AI Models at the same time. Notice both are running within Podman Containers.

Generate quadlet service off of HuggingFace granite Model

Generate quadlet service off of tiny OCI Model

Generate quadlet service off of tiny OCI Model and output to directory

Generate a kubernetes YAML file named MyTinyModel

Generate Compose file

Generate a Llama Stack Kubernetes YAML file named MyLamaStack

Generate a kubernetes YAML file named MyTinyModel shown above, but also generate a quadlet to run it in.

NVIDIA CUDA Support

See ramalama-cuda(7) for setting up the host Linux system for CUDA support.

MLX Support

The MLX runtime is designed for Apple Silicon Macs and provides optimized performance on these systems. MLX support has the following requirements:
  • Operating System: macOS only
  • Hardware: Apple Silicon (M1, M2, M3, or later)
  • Container Mode: MLX requires --nocontainer as it cannot run inside containers
  • Dependencies: The mlx-lm uv package installed on the host system as a uv tool
To install MLX dependencies, use uv:
Example usage:

See Also

ramalama(1), ramalama-stop(1), quadlet(1), systemctl(1), podman(1), podman-ps(1), ramalama-cuda(7)
Aug 2024, Originally compiled by Dan Walsh <dwalsh@redhat.com>