Metadata-Version: 2.4
Name: latentport-vllm
Version: 0.1.1
Summary: LatentPort attention KV compaction for vLLM
License-Expression: Apache-2.0
Project-URL: Repository, https://github.com/LatentPort/latentport
Project-URL: Documentation, https://github.com/LatentPort/latentport/tree/main/integrations/vllm
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: latentport==0.4.13
Requires-Dist: huggingface-hub>=2
Requires-Dist: safetensors<1,>=0.8
Provides-Extra: nf4
Requires-Dist: vllm==0.34.0; extra == "nf4"
Requires-Dist: vllm-bnb-plugin==0.0.3; extra == "nf4"
Requires-Dist: bitsandbytes<0.51,>=0.50.2; extra == "nf4"
Provides-Extra: gguf
Requires-Dist: vllm==0.34.0; extra == "gguf"
Requires-Dist: gguf<1,>=0.19; extra == "gguf"
Dynamic: license-file

# LPCompact for vLLM

This integration serves the LPCompact text models on NVIDIA GPUs. It pins the
served checkpoint and downloads the selector directly from Hugging Face.
Serving uses BF16 compute and KV. For an offline deployment, prewarm the base checkpoint's
Hugging Face cache and LatentPort's selector cache under
`LATENTPORT_HOME/huggingface`, or supply `--lpcompact-weights-path` with the pinned
selector file.

Build from the repository root with vLLM 0.34.0's upstream image.

```sh
docker build -f integrations/vllm/Dockerfile -t latentport-vllm:dev .
docker run --gpus all --ipc=host -p 8000:8000 latentport-vllm:dev \
  serve Qwen/Qwen3.8-27B \
  --lpcompact latentport/LPCompact-Qwen3.8-27B --lpcompact-ratio 8
```

For Flash-Next on a single RTX PRO 6000, the launcher can use the pinned Inferact
NVFP4 checkpoint with disk-backed embedding lookups. Put the Hugging Face cache
on fast local NVMe and mount it into the container.

```sh
docker run --gpus all --ipc=host -p 8000:8000 \
  -e LATENTPORT_HOME=/root/.cache \
  -v /path/to/huggingface:/root/.cache/huggingface latentport-vllm:dev \
  serve Inferact/Qwen3.8-Flash-Next-NVFP4 \
  --lpcompact latentport/LPCompact-Qwen3.8-Flash-Next
```

The same selector is used with the `Qwen/Qwen3.8-Flash-Next` BF16 profile. Its full
checkpoint needs substantially more memory and still requires full-weight
qualification. See the
[vLLM hardware recipe](https://recipes.vllm.ai/Qwen/Qwen3.8-Flash-Next) for
tested base-model hardware combinations.

### Install in an existing vLLM environment

In a dedicated Linux environment with vLLM 0.34.0 and its CUDA dependencies
installed, install the adapter from this checkout and apply its bundled patch once.

```sh
python -m pip install ./integrations/vllm
vllm_site="$(python -c 'import importlib.util; from pathlib import Path; print(Path(importlib.util.find_spec("vllm").origin).parent.parent)')"
patch="$(python -c 'from importlib.resources import files; print(files("latentport_vllm") / "patches" / "vllm-0.34.0.patch")')"
(cd "$vllm_site" && git apply --check "$patch" && git apply "$patch")
latentport-vllm serve Qwen/Qwen3.8-27B --lpcompact latentport/LPCompact-Qwen3.8-27B
```

### NF4 and GGUF weights

Use `--weight-format bf16` for the default Hugging Face weights. Install the
NF4 extra in the same environment to quantize those pinned weights on load.
NF4 uses one GPU rank per model replica.

```sh
python -m pip install './integrations/vllm[nf4]'
latentport-vllm serve Qwen/Qwen3.8-27B --weight-format nf4 \
  --lpcompact latentport/LPCompact-Qwen3.8-27B
```

For GGUF, install the pinned vLLM GGUF plugin with a CUDA toolkit that matches
the vLLM environment. The launcher selects the pinned GGUF file for the base
model and uses the base model's pinned config and tokenizer. For a local copy,
pass `--gguf-path` with the original filename of the first part. Keep all parts
in the same directory.

```sh
python -m pip install './integrations/vllm[gguf]' 'setuptools>=77,<81' wheel ninja
python -m pip install --no-build-isolation --no-deps \
  'vllm-gguf-plugin @ git+https://github.com/vllm-project/vllm-gguf-plugin.git@497542d12327a67f806345438238ea702cadd824'
latentport-vllm serve Qwen/Qwen3.8-27B --weight-format gguf \
  --lpcompact latentport/LPCompact-Qwen3.8-27B
```

All formats use the same BF16 KV cache and published selector. Flash-Next
stages n-gram rows from disk in NF4 and GGUF mode. Quantized profiles are
experimental and have not been qualified on GPU for this update.

## Model profiles

Use a base model and its selector from the same row. Every row accepts
`bf16`, `nf4`, and `gguf`.

| Base checkpoint | Hugging Face selector | Pinned GGUF format | Default trigger |
| --- | --- | --- | ---: |
| `Qwen/Qwen3.5-4B` | `latentport/LPCompact-Qwen3.5-4B` | Q4_K_M | 65,536 |
| `Qwen/Qwen3.5-9B` | `latentport/LPCompact-Qwen3.5-9B` | Q4_K_M | 65,536 |
| `Qwen/Qwen3-14B` | `latentport/LPCompact-Qwen3-14B` | Q4_K_M | 32,768 |
| `Qwen/Qwen3.6-35B-A3B` | `latentport/LPCompact-Qwen3.6-35B-A3B` | UD-Q4_K_M | 65,536 |
| `Qwen/Qwen3.8-27B` | `latentport/LPCompact-Qwen3.8-27B` | Q4_K_M | 65,536 |
| `Qwen/Qwen3.8-Flash-Next` | `latentport/LPCompact-Qwen3.8-Flash-Next` | Q2_K | 65,536 |
| `google/gemma-4-31B-it` | `latentport/LPCompact-Gemma-4-31B-it` | Q4_K_M | 65,536 |

The launcher limits Qwen3-14B to its native 40,960 positions by default.
Gemma 4 compacts its global attention layers and keeps its sliding-window
cache on the logical token timeline.

The launcher selects eager, synchronous, text-only serving with hybrid cache
management enabled. Startup checks require BF16 cache, no automatic prefix
caching, and sufficient pages for the configured maximum sequence length,
concurrency, and one staged compaction. Lower `--max-num-seqs` or
`--max-model-len` if the configuration exceeds cache capacity. The trigger
and supported 4×/8× ratios follow each selector's manifest.

Each committed event logs the artifact and its revision, the logical token
count, attention rows before and after, elapsed time, and net pages returned
to the vLLM pool. The attention-row ratio describes the request's attention
cache. GPU allocation also includes weights, recurrent state, and the
remaining cache pool.

The shared scheduler transaction handles capacity and page ownership.
The worker selects the model-specific cache views from the pinned profile.
Flash-Next compacts whole QSA groups, moving the compressed index and K/V
together while leaving the raw-key ring and recurrent state in place.

Use `tests/gpu_smoke.py` against a local test server to check generated tokens,
prompt accounting, and allocator page reclamation. On a single RTX PRO 6000
Blackwell Server Edition with `--max-num-batched-tokens 2048`, the real-weight
8× smoke runs observed:

| Checkpoint | Attention rows | Allocator pages reclaimed | Generated after compaction |
| --- | ---: | ---: | ---: |
| Qwen3.5-4B BF16 | 65,536 → 8,192 | 99 | 16 tokens |
| Qwen3.5-9B BF16 | 65,536 → 8,192 | 99 | 16 tokens |
| Qwen3-14B BF16 | 32,768 → 4,096 | 448 | 16 tokens |
| Qwen3.6-35B-A3B BF16 | 65,536 → 8,192 | 53 | 16 tokens |
| Qwen3.8-27B BF16 | 131,072 → 16,384 | 138 | 16 tokens |
| Flash-Next NVFP4 | 65,536 → 8,192 | 35 | 16 tokens |
| Gemma 4 31B IT BF16 | 65,536 → 8,192 | 448 | 16 tokens |

With the default prefill batch size on that GPU, Qwen3.6-35B-A3B also passed
at 8×. Gemma 4 served a 114,707-token prompt, compacted twice at 4×, returned
384 pages to the allocator each time, and generated 16 tokens.

The Flash-Next fixture also exercised repeated compaction and an incomplete
four-token QSA group with the real GPU cache kernels and dummy weights.

Two synthetic archive lookups per checkpoint used identical 65,552-token
prompts and greedy decoding in dense and compacted serving. The record
appeared near the beginning or the middle of the archive.

| Checkpoint | Exact answers dense / 8× | Median first-token latency dense / 8× |
| --- | ---: | ---: |
| Qwen3.8-27B BF16 | 2/2 / 2/2 | 12.24 s / 12.31 s |
| Flash-Next NVFP4 | 2/2 / 2/2 | 5.65 s / 5.49 s |

These two-prompt runs check continuation and report the observed latency for
that workload.

Profiles use the core model and selector catalog for checkpoint identity,
feature layers, KV head count, and positions. A new cache layout needs a worker
binding for its attention and auxiliary cache views.
