Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Reliable model swapping for any local OpenAI/Anthropic compatible server - llama.cpp, vllm, etc

License

NotificationsYou must be signed in to change notification settings

mostlygeek/llama-swap

Repository files navigation

llama-swap header imageGitHub Downloads (all assets, all releases)GitHub Actions Workflow StatusGitHub Repo stars

llama-swap

Run multiple LLM models on your machine and hot-swap between them as needed. llama-swap works with any OpenAI API-compatible server, giving you the flexibility to switch models without restarting your applications.

Built in Go for performance and simplicity, llama-swap has zero dependencies and is incredibly easy to set up. Get started in minutes - just one binary and one configuration file.

Features:

  • ✅ Easy to deploy and configure: one binary, one configuration file. no external dependencies
  • ✅ On-demand model switching
  • ✅ Use any local OpenAI compatible server (llama.cpp, vllm, tabbyAPI, etc.)
    • future proof, upgrade your inference servers at any time.
  • ✅ OpenAI API supported endpoints:
    • v1/completions
    • v1/chat/completions
    • v1/embeddings
    • v1/audio/speech (#36)
    • v1/audio/transcriptions (docs)
  • ✅ Anthropic API supported endpoints:
    • v1/messages
  • ✅ llama-server (llama.cpp) supported endpoints
    • v1/rerank,v1/reranking,/rerank
    • /infill - for code infilling
    • /completion - for completion endpoint
  • ✅ llama-swap API
    • /ui - web UI
    • /upstream/:model_id - direct access to upstream server (demo)
    • /models/unload - manually unload running models (#58)
    • /running - list currently running models (#61)
    • /log - remote log monitoring
    • /health - just returns "OK"
  • ✅ Customizable
    • Run multiple models at once withGroups (#107)
    • Automatic unloading of models after timeout by setting attl
    • Reliable Docker and Podman support usingcmd andcmdStop together
    • Preload models on startup withhooks (#235)

Web UI

llama-swap includes a real time web interface for monitoring logs and controlling models:

image

The Activity Page shows recent requests:

image

Installation

llama-swap can be installed in multiple ways

  1. Docker
  2. Homebrew (OSX and Linux)
  3. WinGet
  4. From release binaries
  5. From source

Docker Install (download images)

Nightly container images with llama-swap and llama-server are built for multiple platforms (cuda, vulkan, intel, etc.) includingnon-root variants with improved security.

$ docker pull ghcr.io/mostlygeek/llama-swap:cuda# run with a custom configuration and models directory$ docker run -it --rm --runtime nvidia -p 9292:8080 \ -v /path/to/models:/models \ -v /path/to/custom/config.yaml:/app/config.yaml \ ghcr.io/mostlygeek/llama-swap:cuda# configuration hot reload supported with a# directory volume mount$ docker run -it --rm --runtime nvidia -p 9292:8080 \ -v /path/to/models:/models \ -v /path/to/custom/config.yaml:/app/config.yaml \ -v /path/to/config:/config \ ghcr.io/mostlygeek/llama-swap:cuda -config /config/config.yaml -watch-config
more examples
# pull latest images per platformdocker pull ghcr.io/mostlygeek/llama-swap:cpudocker pull ghcr.io/mostlygeek/llama-swap:cudadocker pull ghcr.io/mostlygeek/llama-swap:vulkandocker pull ghcr.io/mostlygeek/llama-swap:inteldocker pull ghcr.io/mostlygeek/llama-swap:musa# tagged llama-swap, platform and llama-server version imagesdocker pull ghcr.io/mostlygeek/llama-swap:v166-cuda-b6795# non-root cudadocker pull ghcr.io/mostlygeek/llama-swap:cuda-non-root

Homebrew Install (macOS/Linux)

brew tap mostlygeek/llama-swapbrew install llama-swapllama-swap --config path/to/config.yaml --listen localhost:8080

WinGet Install (Windows)

Note

WinGet is maintained by community contributorDvd-Znf (#327). It is not an official part of llama-swap.

# installC:\> winget install llama-swap# upgradeC:\> winget upgrade llama-swap

Pre-built Binaries

Binaries are available on therelease page for Linux, Mac, Windows and FreeBSD.

Building from source

  1. Building requires Go and Node.js (for UI).
  2. git clone https://github.com/mostlygeek/llama-swap.git
  3. make clean all
  4. look in thebuild/ subdirectory for the llama-swap binary

Configuration

# minimum viable config.yamlmodels:model1:cmd:llama-server --port ${PORT} --model /path/to/model.gguf

That's all you need to get started:

  1. models - holds all model configurations
  2. model1 - the ID used in API calls
  3. cmd - the command to run to start the server.
  4. ${PORT} - an automatically assigned port number

Almost all configuration settings are optional and can be added one step at a time:

  • Advanced features
    • groups to run multiple models at once
    • hooks to run things on startup
    • macros reusable snippets
  • Model customization
    • ttl to automatically unload models
    • aliases to use familiar model names (e.g., "gpt-4o-mini")
    • env to pass custom environment variables to inference servers
    • cmdStop gracefully stop Docker/Podman containers
    • useModelName to override model names sent to upstream servers
    • ${PORT} automatic port variables for dynamic port assignment
    • filters rewrite parts of requests before sending to the upstream server

See theconfiguration documentation for all options.

How does llama-swap work?

When a request is made to an OpenAI compatible endpoint, llama-swap will extract themodel value and load the appropriate server configuration to serve it. If the wrong upstream server is running, it will be replaced with the correct one. This is where the "swap" part comes in. The upstream server is automatically swapped to handle the request correctly.

In the most basic configuration llama-swap handles one model at a time. For more advanced use cases, thegroups feature allows multiple models to be loaded at the same time. You have complete control over how your system resources are used.

Reverse Proxy Configuration (nginx)

If you deploy llama-swap behind nginx, disable response buffering for streaming endpoints. By default, nginx buffers responses which breaks Server‑Sent Events (SSE) and streaming chat completion. (#236)

Recommended nginx configuration snippets:

# SSE for UI events/logslocation /api/events{proxy_passhttp://your-llama-swap-backend;proxy_buffering off;proxy_cache off;}# Streaming chat completions (stream=true)location /v1/chat/completions{proxy_passhttp://your-llama-swap-backend;proxy_buffering off;proxy_cache off;}

As a safeguard, llama-swap also setsX-Accel-Buffering: no on SSE responses. However, explicitly disablingproxy_buffering at your reverse proxy is still recommended for reliable streaming behavior.

Monitoring Logs on the CLI

# sends up to the last 10KB of logscurl http://host/logs'# streams combined logscurl -Ns'http://host/logs/stream'# just llama-swap's logscurl -Ns'http://host/logs/stream/proxy'# just upstream's logscurl -Ns'http://host/logs/stream/upstream'# stream and filter logs with linux pipescurl -Ns http://host/logs/stream| grep'eval time'# skips history and just streams new log entriescurl -Ns'http://host/logs/stream?no-history'

Do I need to use llama.cpp's server (llama-server)?

Any OpenAI compatible server would work. llama-swap was originally designed for llama-server and it is the best supported.

For Python based inference servers like vllm or tabbyAPI it is recommended to run them via podman or docker. This provides clean environment isolation as well as responding correctly toSIGTERM signals for proper shutdown.

Star History

Note

⭐️ Star this project to help others discover it!

Star History Chart

About

Reliable model swapping for any local OpenAI/Anthropic compatible server - llama.cpp, vllm, etc

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

[8]ページ先頭

©2009-2025 Movatter.jp