Files
leleka/docs/deploy.md
T
Pavlo RatushnyiandClaude Sonnet 5.5 e03d97dd86 fix(runtime): production Original Load admits the routed-expert bank; deploy: operation polling, expert-source profile field
The Original serve Load never admitted an expert source (the serve smokes call
load_resident_expert_source themselves), so the stack's prompt arena failed with
InputRead on the first real Load through leleka-inference. leleka-inference gains
--expert-source resident|mapped; backend.rs admits the chosen bank before the
driver. leleka up passes it per profile and the supervisor stops waiting when the
load operation is FAILED/INDETERMINATE.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-17 15:18:02 +02:00

19 KiB

One-command deployment: leleka up

Status 2026-10-17, branch claude/deploy (base claude/port-gpu-bringup @ 5e0bd84). This page describes the deployment tool leleka (crate crates/deploy, no Python at run time), what it does, every flag, and what was and was not run to check it. Results are in section 10; nothing here is a performance or model-quality claim. Background: rust-runtime-run.md (the processes), model-assets.md (the model commands leleka drives), laptop-profile.md, sm86-assets.md, delivery-gap-audit.md section 5 (the packaging gaps this closes in part).

1. Quickstart

Server (Linux x86_64, NVIDIA driver >= 595, systemd), as root, from the unpacked release:

tar -xJf leleka-VERSION-linux-x86_64.tar.xz && cd leleka-VERSION-linux-x86_64
sudo ./install.sh --assets /data/leleka        # preflight, fetch+verify, KAR archive, install, start, wait for ready

WSL2 laptop (RTX 3080 16 GB), as your user, in a terminal (WSL2 usually has no systemd):

./install.sh --assets ~/leleka --foreground    # keep the terminal open; Ctrl-C drains and stops

Both do the same thing, idempotently, and print the endpoint, model digest, GPU, the VRAM/RAM budget that was chosen, and the log directory when the service answers /ready. Look first with --dry-run: it prints the preflight and the plan and changes nothing.

./bin/leleka up --dry-run --assets /data/leleka

Container: section 7. Build your own release: section 8.

2. What up does

# step what happens idempotency
1 preflight driver >= 595, GPU architecture, VRAM free vs budget, RAM total/available, disk on each volume, WSL2 mounts, libcublas.so.12, memfd_create, ports, systemd, the six binaries read-only; any FAIL stops before anything is changed
2 layout state (0700), logs, run, stamps, assets mkdir -p
3 binaries copy bin/* to PREFIX/bin, SHA-256 checked against MANIFEST.json skipped when identical; replaced by rename (safe for a running binary)
4 cuBLAS 12 uses what the host has; otherwise downloads the pinned NVIDIA 12.9.1.4 redistributable (SHA-256 pinned, resumable) into PREFIX/lib/cublas skipped when libcublas.so.12 and libcublasLt.so.12 are found
5 secrets two service tokens into STATE/runtime.env (0600), API key through strata-next api-key init never rotated; only missing/invalid ones are created
6 model strata-next model fetch qwen-iq3-s then model verify (resumable .part files, SHA-256) stamped with size+mtime: skipped on re-runs unless --reverify
7 KAR archive strata-next model ensure-sharded-streamed qwen-iq3-s --levels 2 (level 2, the pinned 55,295,529,472-byte archive + provenance) stamped; also checks the length the engine admits
8 MTP pack ASSETS/data/mtp-rt must exist; --mtp-pack imports it from a directory or tarball skipped when present
9 tokenizer model extract-tokenizer from shard 1 skipped when present
10 config leleka.json, daemon.json, strata.json, profile.json, runtime.env rewritten only when the content changes
11 service systemd unit (system or user), daemon-reload, enable; none in foreground mode rewritten only when the content changes; a changed unit restarts a running service
12 start / ready start the unit (or run the supervisor in this terminal), poll /ready with the key, print the summary an already ready service is left alone

The archive step runs ensure-sharded-streamed, which fetches and verifies the shards itself, so on a first run step 6 is folded into step 7 (the plan says so). The strict verification of an existing archive re-derives the 708 GB virtual F32 stream and is slow; a machine that already holds the archive can pass --trust-archive: the archive is accepted when it has the pinned length and a provenance file, and the engine checks its SHA-256 and every CRC against the pinned digest at each load anyway.

A failed run is resumable: fix the cause and run the same command; finished steps are skipped (downloads continue from .part).

3. The processes and files

leleka run (supervisor, the systemd ExecStart or your terminal)
  |- seals the KAR archive into a memfd ONCE (memfd profile) -- or hands the engine a read-only file (file profile)
  |- leleka-daemon      gateway for the typed lifecycle, 127.0.0.1:18080
  |- leleka-inference   engine, gRPC 127.0.0.1:18766   (started through `leleka exec-inherit`, which passes the sealed fd)
  |- leleka-cli load-mtp qwen-iq3 qwen4exp-kar-ple-mtp-v1  -> wait for model_ready (the engine verifies shards + archive here)
  `- strata-next serve  public API (Responses, Chat, Messages, tools, ...), 127.0.0.1:8081, bearer key
PREFIX/bin/{leleka,strata-next,leleka-inference,leleka-daemon,leleka-cli,leleka-seal-exec}   PREFIX/lib/cublas/
STATE/{leleka.json,daemon.json,strata.json,profile.json,runtime.env,api-key}   STATE/{logs,run/status.json,stamps,mtp-staging}
ASSETS/model/*.gguf  ASSETS/qwen-iq3-s-l2-v4.kar(.provenance.json)  ASSETS/data/mtp-rt/  ASSETS/tokenizer-assets/

Defaults: root gets /opt/leleka, /var/lib/leleka/state, /var/lib/leleka/assets; a user gets ~/.local/share/leleka, ~/.local/state/leleka, ~/.local/share/leleka/assets. Environment: LELEKA_PREFIX, LELEKA_STATE, LELEKA_ASSETS. Put --assets on the big volume: about 140 GB (shards 83.6 GB + archive 55.3 GB); the first run needs that plus slack.

The sealed KAR archive is made by the service

The engine accepts the archive only as a sealed memfd (regular, unlinked, pinned length, WRITE|GROW|SHRINK|SEAL). Until now an operator tool (kar_holder.py / seal_exec.py, outside the repository) did that. leleka run now does it natively: it copies the archive into a sealed memfd once (about 10 s for 55 GB from a warm cache, minutes cold), keeps the descriptor close-on-exec in the supervisor, and hands a duplicate to each engine start through leleka exec-inherit (standard input in, a descriptor number >= 3 out). An engine restart therefore does not copy 55 GB again, and the API, the gateway and the CLI never see the descriptor. leleka-seal-exec still ships for manual runs. --kar-fd N (on up and run) reuses a descriptor inherited from a parent that already holds one (a holder, a test harness): no second copy, and its RAM is not demanded.

The file profile (laptop) cannot afford 55 GB of shmem. leleka-inference gained --kar-archive-file PATH --kar-provenance PATH (InheritedKarArchive::open_read_only_file, the form docs/laptop-profile.md measured in a bench): the archive stays an ordinary file; it must be regular, single-link, owned by the service user and without write bits (up sets mode 0400). It is weaker than the seal (immutability rests on the file system) and is selected only by that profile. The full SHA-256 and all CRCs are still checked at load.

4. Memory profiles

--profile auto (default) picks by the GPU nvidia-smi reports; --profile NAME or --profile FILE.json overrides it, and --gpu-budget-gib / --context-tokens override single values. leleka profiles lists them, leleka profiles show NAME prints one to copy and edit. The files live in deploy/rust-runtime/profiles/ and are embedded in the binary.

profile selected for GPU budget context KAR RAM floor (total / available) other
rtx5090-32g sm_12x, >= 30 GB VRAM 24 GiB 262,144 sealed memfd (55.3 GB of RAM) 64 GiB / 60 GB the documented bring-up configuration
rtx3080-16g sm_80..119, 14-24 GB VRAM 15 GiB (needs 14,500 MiB free) 8,192 read-only file 22 GiB / 10 GiB; advice .wslconfig memory=32GB optional VRAM expert tier when ASSETS/data/expert-profile.bin has the pinned SHA-256 8f59b4aa...388975baf

Both profiles run --backend-mode original and the level-2 archive. They select documented switches only (budget, context, archive form, the LELEKA_ORIGINAL_SERVE_* environment); they are not tuned, not quality-gated and carry no speed claim. A GPU that fits neither (a 24 GB 4090, say) gets an error that names the way out: write a profile file. Fields: see crates/deploy/src/profile.rs (gpu_budget_bytes, context_tokens, prefill_capacity, kv, kv_resident, prompt_cache, kar_source, min_*, engine_env restricted to LELEKA_ORIGINAL_SERVE_*); unknown fields are refused.

One binary serves both architectures: the sealed sm_120 PTX is used as is on Blackwell, and the build with --features sm86 (every release) swaps in the sm_86 companion PTX on 8.6 <= cc < 12.0 cards (sm86-assets.md). Preflight reads MANIFEST.json and refuses a binary built without sm86 on such a card. All PTX is embedded in the binaries (the release also ships the files and a SHA256SUMS for audit).

5. Flags

leleka up [OPTIONS] (also accepted by preflight, status, down):

flag meaning
--dry-run print preflight and plan (and the exact engine command); change nothing; exit 1 if a check fails or a step is blocked
--json machine-readable plan / summary on stdout (logs stay on stderr)
--profile auto|NAME|FILE memory profile
--gpu N CUDA device ordinal (default 0)
--assets DIR --state-dir DIR --prefix DIR the three roots (section 3)
--bin-src DIR where the six binaries come from (default: the directory of leleka, i.e. the release bin/)
--mode auto|system|user|foreground|none, --foreground auto: root with systemd -> system unit; a user with a systemd user session -> user unit; otherwise foreground. none prepares and starts nothing
--service-user NAME system unit only: the account the service runs as (default leleka, created with useradd --system; state and assets are chowned to it)
--api-port --engine-port --daemon-port ports (defaults 8081, 18766, 18080)
--api-bind IP API listen address, default 127.0.0.1; 0.0.0.0 only inside a container whose port is published to the host's loopback or tunnelled (the bearer key is the only protection, no TLS). The engine and gateway are always loopback
--gpu-budget-gib N --context-tokens N override one profile value
--no-fetch never download or build; require verified files to exist
--reverify ignore the stamps and hash everything again
--trust-archive accept an existing pinned-length archive + provenance without the strict re-derivation (section 2)
--mtp-pack PATH import the MTP pack (directory or .tar/.tar.gz/.tgz/.tar.xz, sub-directories searched)
--cublas-dir DIR / --no-install-cublas use this CUDA 12 cuBLAS / fail instead of downloading it
--kar-fd N an already sealed archive descriptor inherited from the parent (foreground or --mode none only)
--timeout-s N wait this long for /ready (default 3600)

Other commands: leleka preflight (checks only, exit 1 on FAIL), leleka status (cheap: no GPU probe; exit 0 only when ready; this is the container health check), leleka down (stop the systemd unit), leleka run --config STATE/leleka.json [--kar-fd N] (the supervisor), leleka profiles [show NAME]. HF_TOKEN in the environment is used only by model fetch, is sent only to https://huggingface.co, is removed from every child the supervisor starts, and is never printed or written.

6. Operating it

  • systemd: systemctl status leleka, journalctl -u leleka -f (user unit: add --user; run loginctl enable-linger USER to start without a login). The unit has Restart=on-failure with RestartSec=30, at most 3 starts in 30 minutes, and no restart after exit code 2 (configuration), because every start re-reads 55 GB.
  • The supervisor restarts a dead engine up to twice (counter reset after 10 ready minutes) with the same sealed descriptor and loads the model again; the API process stays up and answers not-ready meanwhile. A dead gateway (3) or API (5) is restarted too. Then it exits 1 and systemd decides.
  • SIGTERM/SIGINT drain: the API first (shutdown_grace_s 10), then the gateway and the engine (both handle SIGINT only, so the supervisor sends SIGINT), then SIGKILL after the grace.
  • Logs: STATE/logs/{leleka,engine,gateway,api,install}.log (rotated once past 64 MiB at start). Status: STATE/run/status.json (phase: sealing, starting_engine, loading, starting_api, ready, engine_restarting, draining, stopped, failed).
  • Use it: curl -H "Authorization: Bearer $(cat STATE/api-key)" -H 'content-type: application/json' -d '{"model":"qwen-iq3","input":"hello","max_output_tokens":32}' http://127.0.0.1:8081/v1/responses. Remote clients: an SSH tunnel. Known limits of this API-over-engine path (4096 output tokens, 256 generations per engine epoch, no image input) are in api-over-rust-engine.md.

7. Container image

deploy/Containerfile.rust-runtime: Ubuntu 24.04 (glibc 2.39, the floor of the binaries) + the six binaries + cuBLAS 12.9.1.4 (downloaded by BuildKit with ADD --checksum, only libcublas.so.12* and libcublasLt.so.12* kept) + the manifest/provenance. The sealed PTX is inside the binaries; ldd shows only libc, libm and libgcc_s, and the engine dlopens libcuda.so.1 (injected by the NVIDIA Container Toolkit) and libcublas.so.12. Not in the image, by design: the model, the driver, any secret. Non-root (uid 10001), volumes /models and /state, HEALTHCHECK = leleka status.

tar -xJf leleka-VERSION-linux-x86_64.tar.xz && cd leleka-VERSION-linux-x86_64
docker build -f /path/to/repo/deploy/Containerfile.rust-runtime --build-arg VERSION=VERSION -t leleka-runtime:VERSION .
# pin the base for a release:  docker buildx imagetools inspect ubuntu:24.04   then   --build-arg BASE=ubuntu:24.04@sha256:...

docker run -d --name leleka --gpus all --restart unless-stopped \
  -v /data/leleka-models:/models -v leleka-state:/state -p 127.0.0.1:8081:8081 \
  leleka-runtime:VERSION            # default command: up --foreground --no-install-cublas --api-bind 0.0.0.0
docker logs -f leleka               # first start: hours (download, verification, archive build); later starts: minutes
docker exec leleka cat /state/api-key

The memfd profile needs the host to give the container ~60 GB of RAM (no --memory below that; memfd is shmem charged to the container, not limited by --shm-size). Docker's default seccomp profile allows memfd_create. Build is not run in CI; see section 10 for what was checked.

8. Build a release tarball

On Linux/WSL, from a tree with the toolchain pinned by rust-toolchain.toml (no CUDA toolkit is needed; the PTX is checked in):

cargo build --release --locked -p strata-desktop-core --features sm86 \
  --bin leleka-inference --bin leleka-daemon --bin leleka-cli --bin leleka-seal-exec
cargo build --release --locked -p strata-control --bin strata-next
cargo build --release --locked -p leleka-deploy --bin leleka

# provenance is made where git exists (an exported tree has no .git); the tree must be clean or --allow-dirty marks it
python3 scripts/package-release.py provenance --repo . --out provenance.json
python3 scripts/package-release.py package --repo . --target-dir target --provenance provenance.json --out dist

dist/leleka-VERSION-COMMIT12-linux-x86_64.tar.xz (+ .sha256) contains bin/ (six binaries), share/leleka/ptx/{sm_120,sm_86} (the sealed PTX and SHA256SUMS), share/leleka/{profiles,templates,docs}, MANIFEST.json (version, commit, features, SHA-256 of every binary, rustc/glibc of the builder), PROVENANCE.json, SHA256SUMS for every file, and install.sh. --no-ptx omits the PTX files (they are embedded anyway); --with-cublas DIR bundles cuBLAS (NVIDIA's redistribution terms apply). PROVENANCE.json records the git commit, whether the tree was dirty (and a digest of the diff), the Cargo.lock digest, and for engine/strata: the upstream URL and commit from upstream.md, the subtree tree id, the import commit, every later commit touching the subtree, and the diff since import (shortstat + digest). The diff against the upstream tree itself is computed only when the upstream commit is present in the repository (git fetch strata-upstream); otherwise the record says so. engine/strata is not modified by this work.

9. Troubleshooting

message (preflight / run) cause and fix
NVIDIA GPU: nvidia-smi was not found no driver. Linux: install the NVIDIA driver >= 595. WSL2: install the Windows driver (never a Linux driver inside WSL), wsl --shutdown, retry
driver version: 580.x is older than 595 the sealed PTX needs ISA 9.2 (CUDA 13.2): update the driver
GPU memory: N MiB free but the engine needs M MiB another process holds VRAM (nvidia-smi); stop it or lower --gpu-budget-gib
architecture: ... built WITHOUT the sm86 feature an RTX 30-series card needs a release made with --features sm86
memory: ... available is below ... the sealed archive copy needs the whole 55 GB in RAM. Free memory, or use the file profile if the GPU fits it. On WSL2 put [wsl2] memory=32GB swap=8GB in %UserProfile%\.wslconfig and wsl --shutdown
WSL2 file system: ... is on a Windows/network mount /mnt/c is 9p: far too slow for mapped reads. Use a path on the WSL ext4 disk
cuBLAS 12: libcublas.so.12 ... not found let up download the pinned 12.9.1.4 (needs curl or wget, tar, xz), or --cublas-dir DIR, or apt install libcublas12
disk space: assets ...: N GiB free, M needed nothing was downloaded yet; point --assets at a larger volume
loopback ports: already in use another listener; --api-port / --engine-port / --daemon-port
systemd: not running WSL2 without systemd or a container: --foreground, or enable systemd in /etc/wsl.conf
step mtp-pack is blocked the MTP pack has no automated producer yet; copy data/mtp-rt from a machine that has it (--mtp-pack takes a directory or tarball)
... has N bytes but the engine only admits the pinned 55295529472-byte level-2 archive the archive was built with another level or policy; the engine would refuse it. Rebuild with --levels 2
step model failed: ... 401/403 the repository needs a token: export HF_TOKEN=... (sent only to huggingface.co)
load-mtp was refused read STATE/logs/engine.log (the engine prints a fixed code, never a path or a secret)
the model was not ready within 1800 s the engine verifies 84 GB of shards and 55 GB of archive at load; a cold disk can need longer: raise load_timeout_s in STATE/leleka.json
a stale Another supervisor is running for ... leleka down (systemd) or stop the other process; STATE/run/status.json names its pid

10. What was run and what was not

Filled in from the actual runs; see the end of this page.