Skip to content

Withdrawn - #831

Closed
Graffioh wants to merge 2 commits into
Luce-Org:mainfrom
Graffioh:feat/model-swap-engine
Closed

Graffioh wants to merge 2 commits into
Luce-Org:mainfrom
Graffioh:feat/model-swap-engine

Conversation

@Graffioh

@Graffioh Graffioh commented Oct 9, 2026 •

Copy link
Copy Markdown
Collaborator

Serve several named models from one luce_server process and swap models that share a GPU while retaining their host prefix snapshots. A named request drains conflicting residents, runs eviction and reinstatement on each model's serial worker, and then admits work to the requested model. Failed swaps restore displaced models and apply a retry cooldown.

  • --luce-mix invokes the installed pair/topology launcher before GPU/model initialization, forwarding its options and this engine's executable path. The launcher resolves model blocks, then execs the normal engine/gateway path. LUCE_MIX_LAUNCHER overrides the launcher on PATH; --print-profile exports the existing engine profiles for reuse. CLI tests verify argument preservation and profile export; the complete handoff was exercised in hardware-detection/dry-run mode.
  • --routing-gateway /path/to/executable starts and supervises an installed local gateway on POSIX hosts. The gateway serves the requested --host/--port; the engine moves to loopback port 8491 (--routing-engine-port overrides it). The child receives --engine-url, --host, and --port. Shutdown reaps the gateway, and unexpected child exit stops the engine with failure. Routing policy remains external. See managed launch.
  • --model-routing name selects a model by the request's model field; omitted/auto requests use resident capacity. --unknown-model reject|primary controls alias fallback.
  • --swap-residency supports Qwen3.5 cold/warm eviction and DeepSeek V4 partial/cold eviction. Partial DeepSeek eviction retains the secondary expert tier and streamed cache; reinstatement preserves expert placement and router biases. Retained devices participate in conflict handling. --swap-keep-weights keeps selected Qwen weights warm between single-device models.
  • Non-streaming Qwen chat completions can return logprobs / top_logprobs. /v1/hidden_states reports selected prefill residual streams and can seed the prefix cache. Out-of-range unsigned layer indices are rejected before signed conversion.
  • Qwen loading supports tied embeddings and the eight capture layers used by the Qwen3.5-9B DFlash drafter.

The listener owns routing reservations and residency bookkeeping; each model's worker executes ControlOp transitions; each backend owns device teardown, reconstruction, and retained host snapshots. Startup loads and evicts inactive blocks before loading the resident set.

Swapping currently requires the serial worker (--max-concurrency 1). Qwen eviction requires a supported single-device configuration with host snapshots; DeepSeek eviction requires the supported in-process two-GPU expert placement. Streaming and unsupported backends continue to ignore logprobs. See the design and usage for configuration restrictions and earlier performance measurements.

Validation on the current branch, based on Luce-Org/lucebox main 5740ef0a3:

  • HIP build for gfx1151;gfx1201 passed.

  • ctest -L cpu: 753/753 passed, including gateway lifecycle coverage; the CLI validation suite passed. The unsigned-layer regression failed before the fix and passed afterwards.

  • R9700 Qwen3.8-27B + DFlash2: three cold eviction/reinstatement cycles preserved greedy snapshot continuations with no device-memory growth.

  • Real HTTP checks with Qwen3.5-0.8B passed in serial, batched, cold-swap, and warm-swap modes: hidden-state readouts, prefix seeding, logprobs, invalid-layer rejection, and identical greedy replies across swaps. Concurrent hidden-state readouts had cosine similarity above 0.998 against the single-request readout (the reference probe's criterion is >0.99).

  • R9700 + Strix Halo DeepSeek V4.1 + DSpark: ten partial cycles and a cold reload passed. The secondary tier survived partial eviction without re-upload, frozen placement survived environment changes, restored greedy output matched, and primary free memory was identical after the first and last partial eviction.

  • Managed gateway integration with two Qwen3.5-0.8B slots: engine-owned startup, internal URL forwarding, streamed and non-streamed consultation, eviction/reinstatement, switch back, graceful child reaping, and gateway-failure propagation passed. The installed gateway determines the public API endpoints.

Final review fix: capture LUCE_DS4_HYBRID_F16_VERIFY_KV at initialization and preserve it through partial and cold reinstatement. The GPU regression now changes the environment after loading and checks the captured mode during restores. Engine and GPU test compilation are checked; this extended GPU case has not run because an unrelated long-running benchmark occupies the machine. Earlier GPU results above predate this extension.

@Graffioh
Graffioh force-pushed the feat/model-swap-engine branch from bf1c31c to 7f06751 Compare October 10, 2026 06:54
…a shared GPU

Load every named model block and pin named requests to its capacity, while
unnamed and auto requests retain primary-first balancing. Report OpenAI
chat logprobs from raw logits, including tokens substituted by the thinking
budget. Load tied-embedding Qwen3.5 models without a separate output head
and support the Qwen3.5-9B DFlash drafter. Expose prefill residual streams
through POST /v1/hidden_states, with an optional prefix checkpoint for a
subsequent chat request.

Run eviction and reinstatement on each model's serial worker, retaining host
prefix snapshots and rebuilding the layout fixed at load. Swap residency
drains overlapping models and admits requests only to the named resident.
Keep selected Qwen weights warm, retry cold if necessary, restore displaced
models on failure and enforce a shared 30-second failure cooldown. Load and
evict initially inactive blocks before loading the resident set, so the
models never need to fit together during startup.

DeepSeek4 has partial and cold eviction with frozen expert ownership. A
partial eviction releases the primary device and keeps the secondary expert
tier, streamed cache and host snapshots. Control operations carry an
eviction level; the manager evicts a model partially when its secondary
devices do not overlap the target, keeps those devices as retained, and
cold-evicts a retained or warm-held model whose devices the target needs.
One model block may set --expert-device and --peer-access, a later block
no longer turns the peer-access opt-in off, and a DeepSeek4 block that would
inherit the expert device from the environment is refused. Residency names
auto:N devices by the compiled backend and requires --draft-device for a
draft, so aliases and unplaced drafts cannot hide a shared GPU. An automatic
request that exceeds every resident model's context is rejected instead of
waiting for a swap it cannot trigger. On integrated GPUs the
DeepSeek4 memory queries are clamped to system RAM and available host
memory, so the streamed cache no longer sizes itself from the 1.25 TiB the
driver reports without a carve and exhausts host memory.

On an R9700 (PCIe Gen5 x16) with a Strix Halo, Qwen 3.8 27B + DFlash2 and
DeepSeek V4.1 Flash (ds41-lucebox placement) share the R9700 in one process.
DeepSeek V4.1 evicts partially in 2-58 ms and reinstates in 9-14 s without
reloading its 90 GiB Strix Halo tier; the 27B reinstates in 7.6-8.4 s and
decodes at the same speed afterwards. Ten partial cycles returned the R9700
to the same free memory with identical restored snapshots, and greedy
outputs matched across swaps. Earlier on an R9700 over PCIe Gen3 x4, the
27B and Qwen3.5-9B reinstated cold in 5.1 s and 2.1-2.35 s and warm in
5-9 ms, and a 52.7k-token session returned in 2.5 s instead of about 80 s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Graffioh
Graffioh force-pushed the feat/model-swap-engine branch from 7f06751 to 1507f87 Compare October 12, 2026 06:55
@Graffioh
Graffioh marked this pull request as ready for review October 12, 2026 06:55

@davide221 davide221 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review

Found 1 issue:

  1. Partial reinstatement silently drops the hybrid F16 verify K/V mode · likely (server/src/deepseek4/deepseek4_backend.cpp:4150-4151)

Reviewed 1507f877 · 5 candidate issues checked, kept at ≥70% confidence · add the code-review label to review again

Comment thread server/src/deepseek4/deepseek4_backend.cpp Outdated
@Graffioh
Graffioh force-pushed the feat/model-swap-engine branch from 408024e to b379a3f Compare October 12, 2026 07:45
@Graffioh
Graffioh force-pushed the feat/model-swap-engine branch from b379a3f to fd4bb6a Compare October 12, 2026 07:52
@Graffioh Graffioh added the code-review Request an automated code review label Oct 12, 2026

@davide221 davide221 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review

No issues found. Checked for bugs and logic errors in the changed code.

Reviewed fd4bb6a0 · 2 candidate issues checked, kept at ≥70% confidence · add the code-review label to review again

@davide221 davide221 removed the code-review Request an automated code review label Oct 12, 2026
@Graffioh Graffioh closed this Oct 12, 2026
@Graffioh
Graffioh deleted the feat/model-swap-engine branch October 12, 2026 14:32
@Graffioh Graffioh changed the title feat(server): serve several models from one process and swap them on a shared GPU Withdrawn Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants