diff --git a/docs/deploy.md b/docs/deploy.md index 279e2129..007693e9 100644 --- a/docs/deploy.md +++ b/docs/deploy.md @@ -1,5 +1,7 @@ # One-command deployment: `leleka up` +**Windows 11:** `leleka.exe` (WSL2 bridge and native engine) is described in [`windows.md`](windows.md). + 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](#10-what-was-run-and-what-was-not); nothing here is a performance or model-quality diff --git a/docs/windows.md b/docs/windows.md new file mode 100644 index 00000000..44206dc2 --- /dev/null +++ b/docs/windows.md @@ -0,0 +1,243 @@ +# Leleka on Windows 11 (RTX 3080 Laptop 16 GB) + +Branch `claude/windows`. Two routes, both started by the same `leleka.exe`: + +* **Route A, the WSL2 bridge.** The engine runs inside WSL2 exactly as `docs/laptop-profile.md` and `docs/deploy.md` describe; + `leleka.exe` is the Windows front end: it starts the Linux `leleka` through `wsl.exe`, translates paths, checks + `%UserProfile%\.wslconfig`, and reads status / sends `reconfigure` / stops the service from Windows over the loopback HTTP + that WSL2 forwards. +* **Route B, the native engine.** No WSL: `leleka-inference.exe` (engine), `leleka-daemon.exe` (gateway) and `strata-next.exe` + (API) run as Windows processes under `leleka.exe run`. The Windows primitives replace the Linux ones: `nvcuda.dll` for + `libcuda.so.1`, read-only file mappings for `mmap`, `VirtualLock` for `mlock`, `GlobalMemoryStatusEx` / `GetProcessMemoryInfo` + for `/proc`, Ctrl-C and a stop file for signals. + +No performance claim is made anywhere in this document; nothing here has a quality gate beyond what the Linux path has. + +## What works and what does not (honest state) + +| Milestone | State | Evidence | +| --- | --- | --- | +| A. `leleka.exe` as the WSL2 front end | **Works** for `help`, `version`, `profiles`, `doctor`, `status`, `down`, `preflight`, `up --dry-run` on this laptop (real `wsl.exe`, real distribution). `up` (real start), `reconfigure`, `verify` use the same code path but were **not run against the model**: the owner tests them | `cargo test -p leleka-deploy` passes on Windows (94 tests) and in WSL (98); `leleka.exe preflight` / `up --dry-run` ran the Linux `leleka` in `Ubuntu` and printed its plan | +| B. native engine, compiles | **Compiles and unit-tests** natively for `x86_64-pc-windows-msvc`: `leleka-libc-shim`, `leleka-cuda-driver` (`cuda-driver,sm86`), `leleka-memory`, `leleka-model-format`, `leleka-native-cpu-expert`, `leleka-runtime`, `strata-desktop-core` (`leleka-inference`, `leleka-daemon`, `leleka-cli`), `strata-control` (`strata-next`), `leleka-deploy` (`leleka.exe`). Linux workspace check and tests stay green in WSL | commits on `claude/windows`; `scripts\windows\build-release.ps1` builds all of it | +| B. native engine, runs | **Not run against the real model.** A model-free GPU smoke through `nvcuda.dll` passed (context creation and the installed-driver fixed-kernel test, one run, 4.5 s). `leleka-inference.exe` and `strata-next.exe` start and print their usage. The load of 80 GB of shards + the 55 GB archive, the mapped expert source and a decode on Windows are **untested**: that is what you test | - | +| C. this document | written | - | + +Known limits (all of them apply to route B unless stated): + +* **Model volume is not built or downloaded on Windows.** `strata-next model fetch` / archive preparation / `service-install` are + Unix-only. Prepare the shards, the KAR archive, the MTP pack and the expert profile on the WSL disk (or copy a finished volume), + then copy them to a Windows disk (section "Model files"). +* **Only the file-backed form**: the profile must be `rtx3080-16g` (`kar_source=file`, `expert_source=mapped`). The sealed-memfd form + (55 GB in RAM) and the 50 GB resident expert copy do not exist on Windows; `rtx5090-32g` is refused by the preflight. +* **cuBLAS 12 DLLs are not downloaded** (`cublas64_12.dll`, `cublasLt64_12.dll`); you place them and pass `--cublas-dir`. +* **No systemd on Windows**: `--mode system/user` are refused; the service runs in the terminal that started it (`--foreground`, + the default). It is not a Windows Service; closing the terminal stops it. +* Memory governor on Windows: `MemAvailable` is the available physical memory, swap is commit limit minus RAM, thread count, + `VmLck`/`VmPin`, cgroup and PSI are unknown (the governor fails closed on unknown figures that it needs). `RLIMIT_MEMLOCK` is reported + as unlimited, so `VirtualLock` and the working-set quota decide; the laptop profile has `lock: off`. +* The key file (`api-key`) and `runtime.env` have no mode bits on Windows: they inherit the ACL of their folder. The defaults are + under `%LOCALAPPDATA%\leleka` (other users cannot read it). Do not point `--state-dir` at a shared folder. +* CPU `expf`/`powf` come from the Windows C runtime instead of glibc: last-bit differences in the CPU SiLU / RoPE theta are possible + and were not measured. Compare greedy output against the Linux run before trusting numbers (the charter's rule for non-lossy changes). +* `arch_ptx::every_sealed_sm120_file_has_a_companion_or_a_documented_reason` fails on Linux and Windows alike (`chain_window.ptx` has + no sm_86 companion record); on the 3080 that PTX loads as sm_120 code. Pre-existing, not touched here. +* GPU safety (`project-laptop-gpu-freeze-bsod`): the laptop took 0x19C BSODs under long GPU load in the OEM 30 W profile. Run + `nvidia-smi -q -d PERFORMANCE,POWER` before a long test and prefer the Turbo mode (`docs/laptop-profile.md`, "Machine state is the dominant variable"). + +## Prerequisites + +* Windows 11, NVIDIA driver >= 595 (this laptop: 617.42). Nothing else from NVIDIA is needed for route A; no CUDA toolkit and no `nvcc` + for either route (every PTX image is sealed in the repository). +* Rust 1.99 for `x86_64-pc-windows-msvc` (the repository pins it in `rust-toolchain.toml`) and the Visual Studio Build Tools + (MSVC linker and `cl.exe`; `strata-next` compiles a small C bridge). +* Route A: WSL2 with an Ubuntu distribution that has Rust 1.99 and a C toolchain (`gcc`), the NVIDIA Windows driver (WSL2 gets the GPU + from it), `%UserProfile%\.wslconfig` with `memory=40GB` and `swap=8GB` (what this laptop has; `leleka doctor` judges it). +* Route B: the two CUDA 12 cuBLAS DLLs (below). + +## Build + +### Windows binaries (`leleka.exe` and the five native programs) + +```powershell +cd C:\Users\pavel\work\leleka-windows +powershell -ExecutionPolicy Bypass -File scripts\windows\build-release.ps1 # -> dist\bin\*.exe, with the sm86 companions +# only the front end, for route A: +cargo build --release --locked -p leleka-deploy --bin leleka # -> target\release\leleka.exe +``` + +`dist\bin` gets `leleka.exe`, `strata-next.exe`, `leleka-inference.exe`, `leleka-daemon.exe`, `leleka-cli.exe` and a stub +`leleka-seal-exec.exe` (prints "requires Linux"; nothing runs it). The first full release build takes a while (`leleka-inference.exe` is ~140 MB). + +### Linux binaries for route A (inside WSL) + +The Linux `leleka` needs its five sibling programs next to it; build them in WSL from a copy of the tree on the WSL disk +(building under `/mnt/c` works but is slow): + +```powershell +wsl -d Ubuntu -- bash -lc "mkdir -p ~/leleka-src && cd /mnt/c/Users/pavel/work/leleka-windows && git ls-files -co --exclude-standard -z | tar --null -T - -cf - | tar -xf - -C ~/leleka-src" +wsl -d Ubuntu -- bash -lc "cd ~/leleka-src && source ~/.cargo/env && 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" +``` + +The result is `~/leleka-src/target/release/` (six programs). `leleka.exe` finds `leleka` there (it also looks in +`~/.local/share/leleka/bin`, `~/leleka/target/release`, `~/leleka-bin`, `~/.cargo/bin` and `PATH`), or you pass `--wsl-bin`. +(On this laptop an older Linux build is in `/home/para/deploy-rel-target/release/`; it works for `preflight`/`up --dry-run` but +predates the laptop `strata.json` fix below, so rebuild.) + +## Model files + +`leleka` expects one **assets** directory: + +``` +ASSETS\model\Qwen3.8-Flash-Next-GSQ-RCO-IQ3_S-00001-of-00002.gguf 54,817,524,224 bytes +ASSETS\model\Qwen3.8-Flash-Next-GSQ-RCO-IQ3_S-00002-of-00002.gguf 28,800,138,432 bytes +ASSETS\qwen-iq3-s-l2-v4.kar 55,295,529,472 bytes (at the root, not in model\) +ASSETS\qwen-iq3-s-l2-v4.kar.provenance.json +ASSETS\data\mtp-rt\{dense.bin,dense.txt,draft_vocab.bin,experts.bin} +ASSETS\data\expert-profile.bin (sha256 8f59b4aa...8975baf; optional but it is the VRAM expert tier) +ASSETS\tokenizer-assets\ (made by `up`) +``` + +**Route A: the volume must be on the WSL ext4 disk** (not `/mnt/c`: 9p is far too slow for mapped reads; `leleka.exe` refuses +`--assets` under `/mnt//`). This laptop's existing `~/laptop` volume has the archive inside `model/`. Make a leleka-shaped +volume next to it with `mv` (instant on one file system; the files leave `~/laptop/model`, so your older bench scripts stop finding +them until you `mv` them back). The engine admits only a regular, single-link archive file, so a hard link or symlink is not a substitute: + +```powershell +wsl -d Ubuntu -- bash -lc "mkdir -p ~/leleka-assets/model ~/leleka-assets/data && cd ~/laptop && mv model/*.gguf ~/leleka-assets/model/ && mv model/qwen-iq3-s-l2-v4.kar model/qwen-iq3-s-l2-v4.kar.provenance.json ~/leleka-assets/ && mv data/mtp-rt ~/leleka-assets/data/ && cp data/expert-profile.bin ~/leleka-assets/data/" +``` + +**Route B: the volume must be on a Windows disk with ~150 GB free** (the NVMe on `C:` or `D:`). Copy it from the WSL volume above (about +140 GB over the 9p share; expect tens of minutes): + +```powershell +$src = '\\wsl.localhost\Ubuntu\home\para\leleka-assets'; $dst = 'D:\leleka-assets' +robocopy "$src\model" "$dst\model" *.gguf /J /NP +robocopy $src $dst qwen-iq3-s-l2-v4.kar qwen-iq3-s-l2-v4.kar.provenance.json /J /NP +robocopy "$src\data" "$dst\data" /E /J /NP +``` + +(`dist\bin` etc. are not part of the volume. Nothing of the model goes into Git.) + +## Route A: WSL2 bridge (works today) + +```powershell +cd C:\Users\pavel\work\leleka-windows +$L = "target\release\leleka.exe" # or dist\bin\leleka.exe +& $L doctor # GPU, RAM, .wslconfig advice, distributions, the Linux leleka, DLLs for route B +& $L preflight --assets '\\wsl.localhost\Ubuntu\home\para\leleka-assets' --wsl-bin /home/para/leleka-src/target/release/leleka +& $L up --assets '\\wsl.localhost\Ubuntu\home\para\leleka-assets' --wsl-bin /home/para/leleka-src/target/release/leleka --trust-archive +``` + +* `--assets` may be a Linux path (`/home/para/leleka-assets`), a `\\wsl.localhost\Ubuntu\...` path or `~/...`; Windows paths are translated to + `/mnt/c/...` and refused for `--assets`. The same translation applies to `--state-dir`, `--prefix`, `--bin-src`, `--cublas-dir`, `--mtp-pack`, + `--profile FILE`. `--wsl-distro NAME` / `$env:LELEKA_WSL_DISTRO` choose the distribution (default: the default WSL2 one that is not Docker's). +* `up` first prints the `.wslconfig` advice (memory below ~32 GB or no swap), then runs the Linux `leleka up` with its output forwarded. Without + systemd in the distribution it runs in the foreground in this window (Ctrl-C drains and stops); with systemd (this laptop has it) it installs and + starts a **user unit** and returns when `/ready` answers. Keep a WSL session alive (any open `wsl` window) so the VM is not shut down while idle. +* `--trust-archive` accepts the existing archive without the hours-long strict re-derivation (the engine still checks its SHA-256 and every CRC at each + load) and makes it read-only, which the file form requires. The first `up` also verifies the shards (about 3 min with hash reuse; a cold cache + is 5-7 min) and unpacks cuBLAS 12.9.1.4 from NVIDIA's pinned redistributable **inside WSL** (download ~890 MiB; or pass `--cublas-dir`). +* When it is ready, `leleka.exe` prints (and the foreground form prints while `up` is still running): + +``` +Leleka (WSL2 route) is reachable from Windows: + endpoint http://127.0.0.1:8081 + api key \\wsl.localhost\Ubuntu\home\para\.local\state\leleka\api-key (WSL: /home/para/.local/state/leleka/api-key) + try $k=(Get-Content -Raw '...api-key').Trim(); Invoke-RestMethod -Method Post -Uri http://127.0.0.1:8081/v1/responses ... +``` + +`leleka.exe` remembers the distribution, the Linux binary, the state directory and the API address of the last `up` in +`%LOCALAPPDATA%\leleka\wsl-bridge.json` (no secret in it), so `status`, `reconfigure` and `down` need no flags afterwards. + +## Route B: native engine (compiled, untested with the model) + +```powershell +# 1. cuBLAS 12 (a CUDA 12.x toolkit's bin folder also works). Pinned by NVIDIA's redistrib_12.9.1.json: +# libcublas 12.9.1.4, windows-x86_64, 549,755,186 bytes, sha256 d534d98b0b453a98914dbf3adf47d7e84b55037abf02f87466439e1dcef581ed +# (read from that manifest; this repository did not download the file). +mkdir C:\leleka -Force | Out-Null +Invoke-WebRequest https://developer.download.nvidia.com/compute/cuda/redist/libcublas/windows-x86_64/libcublas-windows-x86_64-12.9.1.4-archive.zip -OutFile C:\leleka\libcublas.zip +(Get-FileHash C:\leleka\libcublas.zip -Algorithm SHA256).Hash # must equal the sha256 above (case-insensitive) +Expand-Archive C:\leleka\libcublas.zip C:\leleka\cublas +# the DLLs are in C:\leleka\cublas\libcublas-windows-x86_64-12.9.1.4-archive\bin + +# 2. check, then start (engine + gateway + API in this window; Ctrl-C drains and stops) +$bin = "C:\Users\pavel\work\leleka-windows\dist\bin" +& $bin\leleka.exe preflight --native --bin-src $bin --assets D:\leleka-assets --cublas-dir C:\leleka\cublas\libcublas-windows-x86_64-12.9.1.4-archive\bin +& $bin\leleka.exe up --native --foreground --bin-src $bin --assets D:\leleka-assets --cublas-dir C:\leleka\cublas\libcublas-windows-x86_64-12.9.1.4-archive\bin --trust-archive +``` + +What `up --native` does: preflight with Windows facts (`nvidia-smi.exe`, `GlobalMemoryStatusEx`, `GetDiskFreeSpaceEx`, DLL search for +`nvcuda.dll` / `cublas64_12.dll`), checks that the two shards and the archive are on the volume with their pinned sizes (it never downloads or +builds), installs the five `.exe` files into `%LOCALAPPDATA%\leleka\bin`, generates the tokens and the API key (`strata-next api-key init`), +extracts the tokenizer from shard 1, writes `leleka.json` / `daemon.json` / `strata.json` / `runtime.env` in `%LOCALAPPDATA%\leleka\state`, +and runs the supervisor (`leleka.exe run`): gateway, engine, typed `load-mtp`, API, `/ready`. Logs are in `...\state\logs\{leleka,engine,gateway,api}.log`. +The cuBLAS directory reaches the engine through `LELEKA_DLL_DIRS` (the loader flags used by the engine do not search `PATH`). + +If the engine does not come up, read `engine.log` first; the first thing to check is the load line for `nvcuda.dll`, then the mapped-expert and archive +admission messages. `leleka.exe verify --native` hashes both shards in full and renews the verification stamps. + +## Reading `leleka status` + +`leleka status` (add `--json` for a machine-readable form; exit code 1 when not ready) prints: + +``` +ready: true +supervisor: phase ready (pid 1234), engine restarts 0, updated 2026-10-25T13:00:00Z +engine load (decode): + gpu 91% busy (memory bus 40%), VRAM 14.1 of 16.0 GiB, 98 W, 1800 MHz + cpu 6.4 of 16 cores busy in the engine (whole system 52%) + ram 9.3 of 39.0 GiB available, engine 22.0 GiB resident (0.5 GiB pinned), swap in use 1.2 GiB + prefill 310 tok/s last, ... + decode 9 tok/s last, ... average, ... lifetime, ... now + cache 87% of requests hit, 91% of prompt tokens reused (last request ... of ...) + context 1200 of 8192 tokens (14.6%) +settings in force: + context_tokens 8192 ... +``` + +The numbers above are the layout, not measurements. `phase` is the supervisor's state (`starting`, `loading`, `ready`, `engine_restarting`, `draining`, +`stopped`, `failed`). *gpu* is the engine's GPU as NVML reports it, *cpu* the engine's busy cores, *ram* the host figures and the engine's resident / +page-locked memory (on Windows these come from Win32 and are approximations; see the limits), *prefill*/*decode* tokens per second of the last request, the +running average and since start, *cache* the cross-session prefix cache, *context* the live tokens against the ceiling. Route A reads the same +document from Windows over HTTP; if the distribution is stopped it says so instead of booting it. + +## `leleka reconfigure` + +Changes the inference settings of the running engine without reloading the model (it reopens its serve stack in tens of seconds; requests wait; a refused +value keeps the previous settings; the VRAM budget and the preset need a restart): + +```powershell +leleka reconfigure --context-tokens 8192 --prefill-capacity 2048 --kv-resident 32768 +leleka reconfigure --prefix-cache-mib 4096 --prefix-cache-tail reply --cpu-workers 7 --spec-min-p 0.5 +``` + +All flags: `--context-tokens 1..262144`, `--prefill-capacity 256..8192`, `--kv-resident N` (0 = all, else >= 20480), `--prefix-cache-mib auto|off|N`, +`--prefix-cache-tail off|prompt|reply`, `--prefix-cache-block N`, `--prefix-retention-min N`, `--cpu-workers 1..64`, `--spec-min-p 0..1`. On the +16 GB laptop the context is capped by the VRAM left for the KV window; a value that does not fit is refused by the engine, not applied. + +## Stopping + +* Route A: Ctrl-C in the `up` window (foreground), or `leleka down` from any window (stops the user unit if there is one, else sends SIGINT to the + supervisor and waits up to 120 s). `wsl --shutdown` also kills it, but not gracefully. +* Route B: Ctrl-C in the window, or `leleka down --native` from another one (a stop file in `state\run` that the supervisor polls every 0.5 s). + +## Troubleshooting + +| Symptom | Cause / fix | +| --- | --- | +| `the Linux leleka was not found in Ubuntu` | build it in WSL (above) and pass `--wsl-bin`, or put it in `~/.local/share/leleka/bin` | +| `--assets ... is a Windows drive seen from WSL` | move the volume to the WSL disk (section "Model files") | +| preflight `cuBLAS 12 ... not found` (native) | `--cublas-dir` with `cublas64_12.dll` and `cublasLt64_12.dll` | +| `the profile rtx5090-32g holds the archive in a sealed memfd` | native Windows serves the file form only: `--profile rtx3080-16g` | +| `step kar is blocked ... must already be on the model volume` (native) | copy the archive and its `.provenance.json` to `ASSETS\` (root) | +| `status` says `ready: false` and the distribution is stopped | start the service again with `leleka up`; keep a `wsl` window open | +| `strata-next doctor` fails on Windows ("requires Linux") | expected: that check is Linux-only | +| the API refuses with `max_output_tokens` | fixed on this branch: `strata.json` now uses `min(32768, context-1)` (8191 on the laptop); rerun `up` to rewrite the config | + +## Where the code is + +`crates/deploy/src/wsl.rs` (parsers, path translation, `.wslconfig`), `winfront.rs` (the Windows commands), `winsys.rs` (Win32 calls), `facts.rs` (Windows probe), +`crates/libc-shim` (`dlopen` -> `LoadLibrary`, `mlock` -> `VirtualLock`, read-only file views), `crates/leleka-memory/src/winproc.rs` (Win32 rendered as `/proc` text), +`scripts/windows/build-release.ps1`. WSL check used during development: tar the tree with `git ls-files -co --exclude-standard`, then +`cargo check --offline --release --workspace --tests` and `cargo test -p leleka-deploy` in WSL.