Files
UnbiasedStrata/docs/LLAMA_SWAP.md
T
Robert Karl 0197ae86eb Import PolyStrata v0.1.45-poly.1 (d0cd84dc) unmodified
The upstream release tree, every tracked file byte for byte, from
https://github.com/VecSzn/PolyStrata at tag v0.1.45-poly.1, commit
d0cd84dc6bd009d1d9e2191e4e28cc76b80f1ee3. Nothing added, removed or edited;
git diff against this commit is the whole story of the fork.

Verified: the commit's tree hash equals the upstream commit's tree hash.
2026-10-17 19:34:32 -07:00

3.4 KiB

Running PolyStrata behind llama-swap

llama-swap puts several model servers behind one address and starts the one a request names, stopping the others to free the GPU. PolyStrata works as one of its models. This page is what we needed to get it running; it was tested with llama-swap's default stop behaviour, PolyStrata 0.1.39 (Coder IQ1_M on a Tesla V100) and clients reaching the machine by its host name.

The entry

Set PolyStrata up as usual first (./setup.sh --no-start ...), then point llama-swap at the server directly. The start script setup writes (run-<model>.sh) fixes the port at 8080, so call serve/server.py with llama-swap's port instead:

healthCheckTimeout: 300            # PolyStrata takes ~1.5-2 min to load; give it room

models:
  strata:
    cmd: >-
      sh -c 'cd /path/to/PolyStrata && exec .venv/bin/python serve/server.py
      --engine strata --config strata-coder-iq1_m.json --port ${PORT}'
    env: ["STRATA_ALLOWED_HOSTS=my-server"]     # the host name your clients use -- see below
    checkEndpoint: /health
    ttl: 1800
  • exec makes the Python server the process llama-swap stops. On llama-swap's stop (SIGTERM) the server stops its engine: in our test the engine was gone and the V100's memory freed within 2 s.
  • checkEndpoint: /health -- PolyStrata's /health answers only once the model is loaded. Measured load time on our machine (model files on a SATA SSD): 80 s, 105 s while another download was using the disk.
  • If other models share the GPU, put them in a llama-swap group or let swapping unload them; PolyStrata needs the card's memory to itself.

The trap: "Host ... is not allowed"

The first request through llama-swap failed at once with:

403 Host 'my-server:8040' is not allowed (DNS rebinding protection)

PolyStrata only answers to the host names it knows, so a web page cannot reach it by pointing a DNS name at 127.0.0.1. llama-swap passes the client's Host header through, so a client that reaches the proxy by name (http://my-server:8040) is refused. Requests by IP address and to localhost always pass, which is why it can work in a quick test and fail from another machine. Any one of these fixes it:

  • STRATA_ALLOWED_HOSTS=my-server in the entry's env (comma-separated names; ports are ignored), or
  • "allowed_hosts": ["my-server"] in strata-<model>.json, or
  • an "api_key", which turns the check off -- then every client must send the key.

PolyStrata's own pages through llama-swap

llama-swap forwards /upstream/<model>/... unchanged, so PolyStrata's status and health pages stay reachable, and calling one also loads the model without sending a chat request:

curl http://my-server:8040/upstream/strata/health
curl http://my-server:8040/upstream/strata/v1/status

Claude Code and other Anthropic-API clients: the thinking level

Claude Code (and the Claude Agent SDK) send "output_config": {"effort": "high"} with every request unless told otherwise, so PolyStrata thinks at its highest level (seen by logging the requests). CLAUDE_CODE_EFFORT_LEVEL=medium (or low) in the client's environment changes it. One measurement, for scale only: on one real coding task in our setup, medium finished in 6.5 min against 9.7 min at high, both correct; low took 10.1 min (more trial-and-fix steps). One run each -- not a general result.