Compare commits

..
2 Commits
Author SHA1 Message Date
admin 4f5f99d8c6 probe(review): fp8 serve row + 3-ref fixture + fp8 quality-collapse diagnosis
Build Wheel / build (3.12) (pull_request) Failing after 50s
Build Wheel / build (3.11) (pull_request) Failing after 50s
pre-commit / pre-commit (pull_request) Failing after 54s
Review follow-up on PR #4: run --quantization fp8 through the served
path on the 3090 (the flag issue 1 validated for capacity), add the
untested 3-reference fixture, and measure all counts.

Capacity: confirmed — all of 1/2/3/4 references fit and run (4-ref
44.1-44.4s, server peak 23,522MB, nvidia-smi max 23,983MiB; Marlin
W8A16 is faster than BF16, 3.3x the Diffusers nocache baseline).

Quality: every fp8 output is structurally broken on this commit and
card (~97% transparent RGBA, grey RGB, PSNR 7-9dB) — on the edit path
at every reference count and on T2I alike (issue 1's fp8 artifacts
reinspected: same collapse; that run validated rc+image, not output
structure). img_mlp exclusion does not fix it; transformer-only fp8
also collapses, pinning the culprit on the Marlin-quantized DiT.
3090 verdict stays not-built; upstream fix order is fp8 output
correctness before any capacity role for it.
2026-10-08 06:27:36 -04:00
admin 67eb7fdb48 probe: Qwen-Image conditioning-KV spill probe on RTX 3090 / RTX 5080 (issue 2)
Build Wheel / build (3.11) (pull_request) Failing after 33s
Build Wheel / build (3.12) (pull_request) Failing after 40s
pre-commit / pre-commit (pull_request) Failing after 41s
Evidence-only change: probe kit (serve wrapper, API client, PSNR
comparator, offline fp8_v driver), per-host run summaries, and the
findings report. No code changes to the stack.

Verdicts: not-built on both cards. On the 3090 the served reference
ceiling is two condition images with the conditioning cache on
(2.2x the Diffusers nocache baseline, pair PSNR mean 27.57 dB);
four references OOM on the resident BF16 working set, not the KV
(~0.3 GiB/reference, per-request). On the 5080 the server cannot
initialize under any flag: init_parameters materializes the
unquantized skeleton on-device before quantization/offload engage.
Also documents that the recipe's deploy-YAML extras route for
prefix_kv_cache_dtype does not reach the served transformer on
8484d85d (offline Omni engine kwarg does).
2026-10-08 00:58:29 -04:00
16 changed files with 2288 additions and 496 deletions

No files matched your search

+297
View File
@@ -0,0 +1,297 @@
# Issue 2 probe: Qwen-Image conditioning KV on RTX 3090 (24 GB) and RTX 5080 (16 GB)
Probed 2026-10-07/08 on `cachyos-alexander` (RTX 3090, sm_86) and
`cachyos-9900x-o11d` (RTX 5080, sm_120), both at upstream main `8484d85d1`,
vLLM-Omni 0.31.0 recipe (Python 3.13 venv, torch 2.13.0+cu130,
transformers 5.14.1, diffusers git `122b1e11`), served from the
digest-pinned snapshot `Qwen/Qwen-Image-2.1@790c9263` with
`HF_HUB_OFFLINE=1`. Eager mode, one request at a time, fixed seeds,
20 steps, `true_cfg_scale 1.0`, no negative prompt — mirroring the sealed
Diffusers attempt `2026-10-07T170729Z-q3-4r` (profile
`image-q3-int8-dit-20-steps-nocache-4ref`) fixture-for-fixture: same
frozen references-suite-2 images, same rendered brief-prose/1 prompts,
same seeds 2301–2304, same per-fixture resolutions.
## Verdicts
**RTX 3090 (24 GB): not-built.** No host-DRAM spill path for the
conditioning KV exists anywhere in the pipeline (verified by code read and
by exhausting every reachable knob). At BF16 the served reference ceiling
is two condition images at `--enable-cpu-offload` — with the conditioning
cache ON, at 2.2× the Diffusers nocache baseline's speed. Four references
OOM inside the DiT forward under every BF16 flag combination, and the
binding constraint is the resident BF16 working set plus a fixed ~490 MiB
image-MLP activation, not the conditioning KV: the per-request cache
contributes only roughly 0.25–0.3 GiB per reference (see "KV size" below).
FP8 weight quantization (`--quantization fp8`) does free the ~6 GiB the
arithmetic calls for — all of one, two, three, and four references then
fit and run (4-ref: 44.1–44.4 s, server peak 23,522 MB, nvidia-smi series
max 23,983 MiB) — **but on this commit and card the FP8 path produces
structurally broken output** (~96.5–97% transparent RGBA, grey noise RGB,
PSNR 7–9 dB), for the edit path at every reference count and for T2I
alike (see "FP8 quality collapse"). So the verdict stands: no usable path
to four references, and none that spills the KV.
**RTX 5080 (16 GB): not-built, stronger — the server cannot initialize.**
Six init attempts (default, cpu-offload, cpu+layerwise offload, fp8,
fp8+expandable-segments, int8) all OOM at the same late-init 96 MiB
allocation with the card full. The failure is in
`vllm_omni/diffusion/models/utils.py:159-168` (`init_parameters`): the
unquantized parameter skeleton is allocated on-device at construction,
before any quantization or offload path engages, so no runtime flag can
shrink the load-time peak. The reference path is unreachable on this card
with this stack; its one-reference Diffusers ceiling (B2g) relied on a
torchao-int8 + group-offload load path that never materializes the full
BF16 model on the GPU. The conditioning-KV question is moot on this card.
## Where the cache lives (issue scope item 2)
- Created per request at
`vllm_omni/diffusion/models/qwen_image_21/pipeline_qwen_image_21.py:1204-1207`
(`state.extra["kv_cache"]`, one dict per DiT block — 32 — keyed by CFG
branch `cond`/`uncond`), valid because `causal_condition=True` makes
text + condition-image K/V timestep-independent.
- Written at prefill (first denoise step) and read at decode in
`qwen_image_21/.../qwen_image_21_transformer.py:538-598`
(`branch_cache["key"] = key[:, :cache_write_len].clone()` and the
decode-side `torch.cat` prepend).
- Batched mixed-phase assembly/scatter at
`pipeline_qwen_image_21.py:1218-1265` (`_assemble_kv_cache`) and
`:1303-1325` (`_scatter_kv_cache`); decode-graph static copies in
`qwen_image_21/decode_graph.py` (inactive here — eager).
- **Allocator**: plain `torch.Tensor` `.clone()`s on the GPU. Not vLLM's
paged KVCacheManager — the model deliberately runs `DENSE_LEGACY`
(`recipes/Qwen/Qwen-Image-2.1.md:318-329` documents the rejection of
`PAGED_SCHEDULER`). Optional FP8-E4M3 storage (K+V or V-only) via
`extras.prefix_kv_cache_dtype`.
- **Lifetime**: per-request only; freed by refcount when the runner drops
the request state (`diffusion/worker/diffusion_model_runner.py:1034ff`).
No cross-request retention, no LRU, no dedup — unlike Diffusers' helper
cache, nothing persists between requests.
- **Flags that reach it**: `extras.prefix_kv_cache_dtype` (`fp8` /
`fp8_v`; deploy-YAML stage extras or offline `Omni(...)` kwarg — see the
propagation gap below), `--enforce-eager` / `--enable-cuda-graph-decode`
(static-buffer copy), `cuda_graph_max_decode_graphs`.
`--swap-space` and `--cpu-offload-gb` **do not exist** in this fork;
`--gpu-memory-utilization` sizes only the unrelated paged-scheduler
path. The weight-offload flags (`--enable-cpu-offload`,
`--enable-layerwise-offload`) never move KV tensors.
- **Spill path**: none. A host-DRAM contribution would go at the prefill
write / decode read (`qwen_image_21_transformer.py:541-598` — allocate
on pinned CPU, prefetch before the decode `torch.cat`) or at the batch
boundary helpers (`pipeline_qwen_image_21.py:1218-1325`), preserving the
request-owns-independent-storage invariant that the decode-graph weakref
identity check at `decode_graph.py:350-363` depends on.
## KV size (empirical)
Between one and two references the per-request peak moves by only
~200–450 MiB (cpuoff: 23,444→23,638 MB server-reported; cpuoff+
expandable: 21,458→21,896 MB), i.e. ≈0.25–0.3 GiB per condition image —
roughly 64 KiB/prefix-token — versus the 2.8 GiB per reference the
helper-system measured Diffusers retaining (multi-model-helper-server
#160). The cache is per-request and lean; it is not what blocks four
references.
## Run matrix — RTX 3090
All runs: `vllm serve <snapshot> --omni --port 8091 --enforce-eager
--served-model-name Qwen/Qwen-Image-2.1 [+ flags]`, readiness via
`/health`, VRAM via 1 Hz `nvidia-smi` series; per-run artifacts under
`~/Projects/vllm-omni-val/issue2/runs/<label>/` on the host.
| Run | Flags | Init | 1-ref | 2-ref | 4-ref | nvidia-smi peak |
| --- | --- | --- | --- | --- | --- | --- |
| default | (none) | **OOM in 14 s** (23.51 GiB in use at load) | — | — | — | 23,939 MiB |
| cpuoff | `--enable-cpu-offload` | ok | OK 34.2 s | OK 36.7 s | **OOM** in request | 24,015 MiB |
| cpuoff-layerwise | `+ --enable-layerwise-offload` | ok | **OOM** | **OOM** | **OOM** | 24,137 MiB |
| cpuoff-fp8v (yaml) | `+ --deploy-config deploy-fp8v.yaml` | ok | OK 34.3 s | OK 36.8 s | **OOM** | 24,015 MiB |
| cpuoff-expandable | `+ PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True` | ok | OK 33.8 s | OK 36.7 s | **OOM** | 24,095 MiB |
| fp8 | `--enable-cpu-offload --quantization fp8` | ok | OK 29.9 s | OK 34.1 s (+3-ref OK 38.9 s) | OK 44.3 s — **output broken** | 23,983 MiB |
The `fp8` row (review follow-up; #1 validated this flag's capacity
offline) also covered the previously untested three-reference count via
`edit-compose-three` — derived from `edit-compose-four` minus
`ref-shop-hesper` and its Subject line, four→three wording, same
instrument (recorded in `fixtures.json`). Measured under fp8, seeds
2301–2304: four 44.06–44.35 s (peak 22,918 MB), pair 34.62–35.05 s
(peak 21,504 MB), three 39.44–39.69 s (peak 23,532 MB) — every request
succeeds capacity-wise, and Marlin W8A16 is *faster* than BF16
(4-ref 44.3 s vs Diffusers' 145.8 s = 3.3×). The quality outcome is in
the next section.
- 4-ref OOM signature (identical ask across configs): `Tried to allocate
490.00 MiB` inside the image-branch MLP forward
(`qwen_image_21_transformer.py:293`, via `predict_noise` — prefill
encoding has already succeeded). At cpuoff: 21.02 GiB allocated + 1.84
GiB reserved-unallocated; at cpuoff-expandable: 22.29 GiB allocated,
505 MiB reserved-unallocated — fragmentation removed, still short:
genuine capacity gap.
- Layerwise offload is strictly counterproductive here: even one reference
OOMs (21.76 GiB allocated during the request).
- Determinism: seed-2301 outputs are byte-identical (sha256
`45fac0b8…` pair, `3c4eb2ef…` single) across cpuoff, cpuoff-fp8v,
cpuoff-expandable — the frozen-seed instrument is sound.
### FP8 quality collapse (and a correction to issue 1)
Every FP8-weight output this probe produced is structurally broken, not
merely noisier:
- Signature (identical everywhere): RGBA output ~96.5–97% transparent
(opaque fraction 0.008–0.035, alpha mean ≈115), near-flat grey RGB
(mean ≈120–130), PSNR vs the Diffusers baseline 6.6–9.0 dB. The BF16
path on the same requests is 100% opaque and 26–29 dB.
- Scope: the serve path at 1, 2, 3, and 4 references (all seeds measured),
the offline path with `fp8` minus `img_mlp`, and the offline path with
**transformer-only** FP8 (`quantization_config={"transformer":
{"method": "fp8"}}` — the text encoder stays BF16). Transformer-only
still collapsing pins the culprit on the Marlin-quantized DiT, not the
encoder and not the image-MLP. An encoder-only isolator could not
initialize (the encoder's bf16→fp8 conversion transient lands on the GPU
on top of the resident BF16 DiT and exceeds the card).
- **Correction to issue 1**: #1's offline FP8 validation
(`qwen_image_21_fp8_all_rtx3090.png`, `…_fp8_imgmlp_…`) shows the same
collapse on reinspection (opaque fraction 0.035 both) — that run
validated rc=0 and image production, not output structure, so "FP8
weight-only works on this card" from #1 overstated it. #1's 18.4 GB
capacity measurement stands; its quality implication does not.
- Upstream relevance: the recipe's H200 FP8 numbers quote PSNR only for
text-encoder FP8 (32.1 dB T2I); DiT-FP8 output quality appears
unmeasured upstream, and this probe adds the Ampere/Marlin cell:
online FP8 DiT weights yield near-noise latents for Qwen-Image-2.1.
Until that is fixed (or validated as Ampere-specific), FP8 cannot serve
as the capacity unlock on this card — which is why the 3090 verdict
remains `not-built` despite the fp8 capacity row passing.
### Offline knob runs (3090, `Omni(...)` engine kwargs)
The one knob that reaches the cache — `extras.prefix_kv_cache_dtype` —
was exercised offline (`offline_fp8v.py`, `--enforce-eager
--enable-cpu-offload` + engine kwarg):
| Run | 4-ref seed 2301 | Detail |
| --- | --- | --- |
| offline fp8_v | **OOM** | 20.86 GiB allocated + 2.14 GiB reserved-unallocated; same 490 MiB img-MLP ask |
| offline fp8_v + expandable | **OOM** | 22.22 GiB allocated, 483 MiB reserved-unallocated |
FP8-V halves the V half of a cache that contributes only ~0.3 GiB per
reference — an order of magnitude too small to bridge the gap. The
conditioning KV cannot rescue four references on this card by quantization
or by anything else; only a genuinely leaner resident working set
(quantized DiT weights) would, and on this commit that is blocked by the
init path (see 5080).
### Measured run + PSNR (3090)
`edit-compose-pair` (2 refs, 1248×832), seeds 2301–2304, on
cpuoff-expandable, versus the sealed Diffusers attempt's pair samples
(same references, 20 steps; Diffusers side ran an int8-quantized DiT with
KV cache off, wall 81.16 s):
- Wall: **36.6–36.9 s per image** (2.2× faster than Diffusers nocache;
server `denoise_step_latency` ≈ 1.83 s × 20 steps).
- Peak: 21,976–23,332 MB server-reported; 24,095 MiB nvidia-smi series
max.
- PSNR vs Diffusers (RGBA-on-RGBA, #1's comparator): **26.09 / 28.75 /
26.51 / 28.92 dB; mean 27.57 dB** (n=4). Cross-implementation agreement
at matched seed/inputs, not parity — expected given the different
samplers/kernels and the Diffusers side's int8 DiT.
The four-reference PSNR cell the issue nominally asks for is
**capacity-blocked at BF16** (every served flag set, and offline with
fp8_v). Under the fp8 serve row it becomes obtainable but meaningless as
quality: measured seeds 2301–2304 give 7.03–7.21 dB (mean 7.11) against
the sealed 4r baseline because the outputs are the collapsed ~97%
transparent renders of the FP8 quality section — recorded in
`evidence/rtx3090/psnr-fp8-rows.json` as the broken-output datum, not as
a usable comparison. The pair row above (27.57 dB at BF16) remains the
highest-reference-count usable comparison this card can produce.
`edit-compose-four` wall for reference: Diffusers 145.8 s (nocache);
vLLM 44.3 s under fp8 (fast but broken) — no valid BF16 number exists.
## Run matrix — RTX 5080
Environment built fresh per #1's recipe (userspace CPython 3.13.16 venv —
the host only ships 3.14 and has no `/usr/bin/python3.13`; clone pinned to
`8484d85d1`; weights/suite verified, the `q3-4r` attempt copied from the
3090 so both legs compare against the identical baseline).
| Run | Flags | Init result |
| --- | --- | --- |
| default | (none) | OOM in 12 s (15.22 GiB allocated at load) |
| cpuoff | `--enable-cpu-offload` | **OOM in 9 s** — DiT stays GPU-resident under cpu-offload; 14.99 GiB allocated |
| cpuoff-layerwise | `+ --enable-layerwise-offload` | **OOM in 10 s** — layerwise streams per-forward, after load |
| fp8 | `--enable-cpu-offload --quantization fp8` | **OOM in ~10 s** — FP8 path engaged (DeepGEMM init visible) but init still fills the card |
| fp8-expandable | `+ expandable_segments` | **OOM** |
| int8 | `--enable-cpu-offload --quantization int8` | **OOM in 8 s** — 15.55 GiB in use |
Common failure: `torch.OutOfMemoryError` at a 96 MiB allocation in
`vllm_omni/diffusion/models/utils.py:159-168 init_parameters`
(`empty_like` under a device context) — the unquantized parameter
skeleton is materialized on-device at pipeline construction, before
weight loading, quantization, or offload can act. Host RAM (30 GiB + zram)
is a separate ceiling for full weight offload (~32 GiB of BF16 weights)
but is not what kills these runs.
## Propagation gap found (3090 leg)
The recipe-documented deploy-YAML route for
`extras.prefix_kv_cache_dtype` **does not reach the transformer through
`vllm serve` on this commit**: with and without the YAML, serve outputs
are byte-identical, and the drop is verified offline at the exact
serve-time construction (`build_diffusion_config` →
`stage_configs[0].diffusion_config.extras` carries only
`auxiliary_text_encoder`/`default_llama_model_id` defaults; deploy stage
`engine_extras.extras` is parsed correctly by `_stage_engine_overrides`
but lost in the structured-config bridge). The offline `Omni(extras=…)`
engine kwarg is accepted (load proceeds; the knob then behaves as
documented). Shapes tried: flat stage key, `engine_extras.<key>`, and
`engine_extras.extras.<key>`. This is a one-line-ish fix candidate in the
config bridge, independent of any KV-spill contribution.
## Reproducibility
Scripts live in this directory (`serve.sh`, `probe.py`, `psnr.py`,
`offline_fp8v.py`, `deploy-fp8v.yaml`) and were pushed verbatim to
`~/Projects/vllm-omni-val/issue2/` on each host; `fixtures.json` (rendered
brief-prose/1 prompts, reference bindings, dimensions) was generated on
the 3090 from the helper repo (`evaluation/media/image/suite.py` +
`services/media/image_service/renderer.py`) and copied to the 5080.
Server lifecycle ran under transient user units
(`systemd-run --user --unit=issue2-serve`); per-run serve/vram logs and
request records are under `runs/<label>/` on each host; condensed
summaries in `evidence/rtx3090/runs-summary.json` and
`evidence/rtx5080/runs-summary.json`.
## Helper-system follow-through (input to multi-model-helper-server #27 and #164 — not implemented here)
- **#27 (serving-profile candidacy)**: on the 3090 the vLLM-Omni path
serves 1–2 references at 33–37 s/image with the conditioning cache on —
2.2× the sealed Diffusers nocache baseline — and per-request cache
pressure of ~0.3 GiB/reference means concurrent multi-reference sessions
do not accumulate Diffusers-style 2.8 GiB/reference retention. Candidacy
holds for ≤2-reference profiles on 24 GB; 4-reference profiles remain
Diffusers-only: FP8 unlocks the capacity (all four counts fit, 3.3×
baseline speed) but its output is broken on this commit, so the unlock
order is upstream FP8-output correctness first, then serving.
- **#164 (topology input)**: the 5080 (16 GB) cannot host this stack at
all — init-time parameter skeleton exceeds the card before any flag
acts (`diffusion/models/utils.py:159-168`). Any topology plan pairing
the 5080 with Qwen-Image-2.1 on vLLM-Omni needs upstream load-path work
(quantized or CPU-materialized init) first; the B-series torchao-int8
Diffusers stack remains that card's only viable image backend.
- Upstream contribution seam, if ever pursued: prefill-write/decode-read
at `qwen_image_21_transformer.py:541-598` or the batch helpers at
`pipeline_qwen_image_21.py:1218-1325`; but note the cache itself is not
the binding constraint on either card — the 3090 blocks on the resident
BF16 working set + img-MLP activation, the 5080 on init. A spill path
alone would not change either verdict, which answers the issue's
"does it still serve us before committing to anything upstream-sized":
**no — not as the next step**; the load/init path comes first.
## Out-of-scope confirmation
No code changes; no upstream PRs; no TP/multi-GPU paths touched; no
helper-system deployment evidence produced. The only artifacts are this
report, the probe scripts, and per-host run records.
+7
View File
@@ -0,0 +1,7 @@
# Issue 2 probe: Qwen-Image-2.1 with FP8 V-only prefix-KV storage.
# Merged over the pipeline's declared single-stage topology; every other
# field falls back to StageDeployConfig defaults.
stages:
- stage_id: 0
engine_extras:
prefix_kv_cache_dtype: "fp8_v"
@@ -0,0 +1,30 @@
{
"cpuoff-expandable": {
"rows": [
{
"seed": 2301,
"psnr_db": 26.09,
"modes": "RGBA/RGBA"
},
{
"seed": 2302,
"psnr_db": 28.75,
"modes": "RGBA/RGBA"
},
{
"seed": 2303,
"psnr_db": 26.51,
"modes": "RGBA/RGBA"
},
{
"seed": 2304,
"psnr_db": 28.92,
"modes": "RGBA/RGBA"
}
],
"mean_db": 27.57,
"min_db": 26.09,
"max_db": 28.92,
"n": 4
}
}
@@ -0,0 +1,112 @@
{
"edit-compose-four": {
"cpuoff-fp8": {
"rows": [
{
"seed": 2301,
"psnr_db": 7.03,
"modes": "RGBA/RGBA"
},
{
"seed": 2302,
"psnr_db": 7.11,
"modes": "RGBA/RGBA"
},
{
"seed": 2303,
"psnr_db": 7.1,
"modes": "RGBA/RGBA"
},
{
"seed": 2304,
"psnr_db": 7.21,
"modes": "RGBA/RGBA"
}
],
"mean_db": 7.11,
"min_db": 7.03,
"max_db": 7.21,
"n": 4
},
"offline-fp8-imgmlp": {
"rows": [
{
"seed": 2301,
"psnr_db": 7.27,
"modes": "RGBA/RGBA"
},
{
"seed": 2302,
"error": "missing"
},
{
"seed": 2303,
"error": "missing"
},
{
"seed": 2304,
"error": "missing"
}
],
"mean_db": 7.27,
"min_db": 7.27,
"max_db": 7.27,
"n": 1
},
"offline-fp8-dit": {
"rows": [
{
"seed": 2301,
"psnr_db": 6.69,
"modes": "RGBA/RGBA"
},
{
"seed": 2302,
"error": "missing"
},
{
"seed": 2303,
"error": "missing"
},
{
"seed": 2304,
"error": "missing"
}
],
"mean_db": 6.69,
"min_db": 6.69,
"max_db": 6.69,
"n": 1
}
},
"edit-compose-pair": {
"cpuoff-fp8": {
"rows": [
{
"seed": 2301,
"psnr_db": 6.57,
"modes": "RGBA/RGBA"
},
{
"seed": 2302,
"psnr_db": 7.88,
"modes": "RGBA/RGBA"
},
{
"seed": 2303,
"psnr_db": 9.02,
"modes": "RGBA/RGBA"
},
{
"seed": 2304,
"psnr_db": 8.95,
"modes": "RGBA/RGBA"
}
],
"mean_db": 8.11,
"min_db": 6.57,
"max_db": 9.02,
"n": 4
}
}
}
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,40 @@
{
"runs": {
"cpuoff": {
"flags": "--enable-cpu-offload",
"serve_rc": 1,
"serve_wall_s": 9,
"vram_peak_mib": 15856
},
"cpuoff-layerwise": {
"flags": "--enable-cpu-offload --enable-layerwise-offload",
"serve_rc": 1,
"serve_wall_s": 10,
"vram_peak_mib": 15856
},
"default": {
"flags": "flags:",
"serve_rc": 1,
"serve_wall_s": 12,
"vram_peak_mib": 15926
},
"fp8": {
"flags": "--enable-cpu-offload --quantization fp8",
"serve_rc": 1,
"serve_wall_s": 13,
"vram_peak_mib": 15930
},
"fp8-expandable": {
"flags": "--enable-cpu-offload --quantization fp8",
"serve_rc": 1,
"serve_wall_s": 9,
"vram_peak_mib": 15876
},
"int8": {
"flags": "--enable-cpu-offload --quantization int8",
"serve_rc": 1,
"serve_wall_s": 8,
"vram_peak_mib": 15930
}
}
}
+49
View File
@@ -0,0 +1,49 @@
{
"edit-expression-ysolde": {
"mode": "edit",
"references": [
"ref-portrait-ysolde"
],
"width": 864,
"height": 1152,
"prompt": "Change only her expression and the chart: she now laughs openly and lowers the chart; keep her face, hair, clothing, the room, the framing, and the lighting as in the reference. Result: Ysolde laughs at something off-frame in the map room. Emotional tone: sudden delight.\nSubject: Ysolde Varn, an adult woman in her early thirties, with deep brown skin, close-cropped black hair with one silver-beaded braid behind the left ear, and amber eyes; wearing a teal oilskin coat with brass buttons over a cream linen shirt; a thin pale scar through the right eyebrow and a brass compass on a cord at her throat. Laughing openly, the chart lowered to her chest.\nSetting: The map room of a harbor guildhall, charts pinned to timber walls, rain on the window.\nComposition: close-up; head and shoulders, three-quarter view, face in sharp focus; lighting: cool grey window light from the left with a warm lamp glow from below\nStyle: Semi-realistic digital painting: natural proportions, painterly texture, soft realistic lighting.",
"negative_prompt": null
},
"edit-compose-pair": {
"mode": "edit",
"references": [
"ref-portrait-ysolde",
"ref-cutout-tamsin"
],
"width": 1248,
"height": 832,
"prompt": "Place the woman from the first reference and the figure from the second reference together; keep both identities exactly. Result: Ysolde and Tamsin share one unrolled map at a harbor wall. Emotional tone: wary cooperation.\nSubject: Ysolde Varn, an adult woman in her early thirties, with deep brown skin, close-cropped black hair with one silver-beaded braid behind the left ear, and amber eyes; wearing a teal oilskin coat with brass buttons over a cream linen shirt; a thin pale scar through the right eyebrow and a brass compass on a cord at her throat. Holding one end of an unrolled map, explaining a route.\nSubject: Tamsin Rook, an adult androgynous person in their late twenties, with warm olive skin, straight shoulder-length silver-white hair, and dark brown eyes; wearing a crimson hooded mantle over fitted grey leather armour; three thin black geometric lines tattooed down the left cheek. Holding the other end of the map, listening sceptically.\nSetting: A sea wall above the harbor at midday, fishing boats below.\nComposition: medium shot; both figures side by side, the map between them; lighting: bright midday sun with short shadows\nStyle: Semi-realistic digital painting: natural proportions, painterly texture, soft realistic lighting.",
"negative_prompt": null
},
"edit-compose-four": {
"mode": "edit",
"references": [
"ref-portrait-ysolde",
"ref-storm-corvin",
"ref-cutout-tamsin",
"ref-shop-hesper"
],
"width": 1344,
"height": 768,
"prompt": "Bring the four characters from the references together in one scene; keep every identity exactly. Result: All four gather around the apothecary counter. Emotional tone: conspiratorial calm.\nSubject: Ysolde Varn, an adult woman in her early thirties, with deep brown skin, close-cropped black hair with one silver-beaded braid behind the left ear, and amber eyes; wearing a teal oilskin coat with brass buttons over a cream linen shirt; a thin pale scar through the right eyebrow and a brass compass on a cord at her throat. Unfolding a chart on the counter.\nSubject: Corvin Ashdown, an adult man in his mid-fifties, with pale, heavily freckled skin, short receding red hair and a grey-streaked red beard, and pale blue eyes; wearing a dark green harbormaster's greatcoat with a silver chain of office; a black leather patch over the left eye. Leaning on the doorframe.\nSubject: Tamsin Rook, an adult androgynous person in their late twenties, with warm olive skin, straight shoulder-length silver-white hair, and dark brown eyes; wearing a crimson hooded mantle over fitted grey leather armour; three thin black geometric lines tattooed down the left cheek. Sniffing a stoppered bottle.\nSubject: Hesper Quill, an adult woman in her early seventies, with light brown, deeply weathered skin, long white hair in one thick plait, and grey-green eyes; wearing a lavender dress under a stained canvas apothecary's apron; round wire-rimmed spectacles and a silver ring on every finger of the right hand. Behind the counter, weighing herbs on a brass scale.\nSetting: Inside the apothecary: shelves of bottled remedies, drying herbs hanging from the beams, a long counter.\nComposition: wide shot; from behind the counter's end, all four faces visible; lighting: warm lamplight with green light filtering through bottle glass\nStyle: Anime illustration: clean line art, cel shading, flat vivid colour, expressive faces.",
"negative_prompt": null
},
"edit-compose-three": {
"mode": "edit",
"references": [
"ref-portrait-ysolde",
"ref-storm-corvin",
"ref-cutout-tamsin"
],
"width": 1344,
"height": 768,
"prompt": "Bring the three characters from the references together in one scene; keep every identity exactly. Result: All three gather around the apothecary counter. Emotional tone: conspiratorial calm.\nSubject: Ysolde Varn, an adult woman in her early thirties, with deep brown skin, close-cropped black hair with one silver-beaded braid behind the left ear, and amber eyes; wearing a teal oilskin coat with brass buttons over a cream linen shirt; a thin pale scar through the right eyebrow and a brass compass on a cord at her throat. Unfolding a chart on the counter.\nSubject: Corvin Ashdown, an adult man in his mid-fifties, with pale, heavily freckled skin, short receding red hair and a grey-streaked red beard, and pale blue eyes; wearing a dark green harbormaster's greatcoat with a silver chain of office; a black leather patch over the left eye. Leaning on the doorframe.\nSubject: Tamsin Rook, an adult androgynous person in their late twenties, with warm olive skin, straight shoulder-length silver-white hair, and dark brown eyes; wearing a crimson hooded mantle over fitted grey leather armour; three thin black geometric lines tattooed down the left cheek. Sniffing a stoppered bottle.\nSetting: Inside the apothecary: shelves of bottled remedies, drying herbs hanging from the beams, a long counter.\nComposition: wide shot; from behind the counter's end, all four faces visible; lighting: warm lamplight with green light filtering through bottle glass\nStyle: Anime illustration: clean line art, cel shading, flat vivid colour, expressive faces.",
"negative_prompt": null,
"derived_from": "edit-compose-four minus ref-shop-hesper and its Subject line; four->three wording"
}
}
+146
View File
@@ -0,0 +1,146 @@
#!/usr/bin/env python
"""Issue 2 probe: offline Qwen-Image-2.1 edit driver with prefix-KV extras.
The served path cannot reach `extras.prefix_kv_cache_dtype` on commit
8484d85d (the structured-config bridge drops deploy-YAML extras), so this
driver exercises the knob through the offline `Omni(...)` engine kwargs —
the other route the recipe names. It mirrors image_edit.py's request
construction: same prompt builder, same sampling fields, one request at a
time.
Usage: offline_fp8v.py --out RUN_DIR [--kv-dtype fp8_v] [--fixture FID]
"""
from __future__ import annotations
import argparse
import hashlib
import json
import pathlib
import time
import torch
from PIL import Image
from vllm_omni.entrypoints.omni import Omni
from vllm_omni.inputs.data import OmniDiffusionSamplingParams
from vllm_omni.model_extras import (
build_image_to_image_prompt,
get_model_class_name,
)
from vllm_omni.platforms import current_omni_platform
W = pathlib.Path.home() / "Projects/vllm-omni-val/issue2"
SUITE = (
pathlib.Path.home()
/ ".local/share/multi-model-helper-server/data/evaluation/media/image/references-suite-2"
)
SNAP = (
pathlib.Path.home()
/ ".local/state/multi-model-helper-server/state/image-service/weights/hub/models--Qwen--Qwen-Image-2.1/snapshots/790c92633540aa0cb11d9abf19eb46d861714758"
)
STEPS = 20
CFG = 1.0
def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument("--out", required=True, type=pathlib.Path)
parser.add_argument("--kv-dtype", default="fp8_v")
parser.add_argument(
"--quant",
default="none",
choices=["none", "fp8", "fp8-imgmlp", "fp8-dit", "fp8-encoder"],
help="weight quantization: none, fp8 (all), fp8 minus img_mlp, transformer-only, or text-encoder-only",
)
parser.add_argument("--fixture", default="edit-compose-four")
parser.add_argument("--seeds", type=lambda s: tuple(int(x) for x in s.split(",")), default=(2301,))
parser.add_argument("--no-extras", action="store_true", help="run without the extras knob (control)")
args = parser.parse_args()
fixture = json.loads((W / "fixtures.json").read_text())[args.fixture]
refs = [Image.open(SUITE / f"{r}.png").convert("RGB") for r in fixture["references"]]
omni_kwargs = dict(
model=str(SNAP),
enforce_eager=True,
enable_cpu_offload=True,
init_timeout=1200,
)
if args.quant == "fp8":
omni_kwargs["quantization"] = "fp8"
elif args.quant == "fp8-imgmlp":
omni_kwargs["quantization_config"] = {
"method": "fp8",
"ignored_layers": ["img_mlp"],
}
elif args.quant == "fp8-dit":
omni_kwargs["quantization_config"] = {"transformer": {"method": "fp8"}}
elif args.quant == "fp8-encoder":
omni_kwargs["quantization_config"] = {"text_encoder": {"method": "fp8"}}
if not args.no_extras:
omni_kwargs["extras"] = {"prefix_kv_cache_dtype": args.kv_dtype}
t0 = time.time()
omni = Omni(**omni_kwargs)
print(
f"load_s={time.time() - t0:.1f} quant={args.quant} extras={omni_kwargs.get('extras')}",
flush=True,
)
model_class_name = get_model_class_name(omni)
args.out.mkdir(parents=True, exist_ok=True)
records = []
for seed in args.seeds:
generator = torch.Generator(device=current_omni_platform.device_type).manual_seed(seed)
prompt_dict = build_image_to_image_prompt(
model_class_name=model_class_name,
prompt=fixture["prompt"],
negative_prompt=None,
input_image=refs[0] if len(refs) == 1 else refs,
height=fixture["height"],
width=fixture["width"],
)
params = OmniDiffusionSamplingParams(
generator=generator,
seed=seed,
true_cfg_scale=CFG,
num_inference_steps=STEPS,
height=fixture["height"],
width=fixture["width"],
)
torch.cuda.reset_peak_memory_stats()
t1 = time.time()
rec = {"fixture_id": args.fixture, "seed": seed, "n_references": len(refs), "kv_dtype": args.kv_dtype, "quant": args.quant}
try:
outputs = omni.generate(prompt_dict, sampling_params_list=[params])
wall = time.time() - t1
images = None
for output in outputs:
images = getattr(output, "images", None)
if images:
break
if not images:
raise RuntimeError("no images in output")
out_path = args.out / "measured" / f"{args.fixture}.s{seed}.png"
out_path.parent.mkdir(parents=True, exist_ok=True)
images[0].save(out_path)
png = out_path.read_bytes()
rec.update(
wall_s=round(wall, 2),
peak_gpu_mb=round(torch.cuda.max_memory_allocated() / 2**20, 1),
bytes=len(png),
sha256=hashlib.sha256(png).hexdigest(),
)
except Exception as exc: # noqa: BLE001 - recorded as the probe result
rec.update(wall_s=round(time.time() - t1, 2), error=f"{type(exc).__name__}: {exc}"[:2000])
records.append(rec)
print(json.dumps(rec), flush=True)
(args.out / f"offline-{args.fixture}.json").write_text(json.dumps(records, indent=1) + "\n")
ok = all("sha256" in r for r in records)
print(("PASS" if ok else "FAIL") + f" {len(records)} requests", flush=True)
return 0 if ok else 1
if __name__ == "__main__":
raise SystemExit(main())
@@ -1,23 +1,15 @@
#!/usr/bin/env python
"""Issue 5 probe client: reference-conditioned requests against the int8
weight-only compressed-tensors artifact, with the structure gate applied to
every response.
"""Issue 2 probe client: reference-conditioned requests through the API.
Matrix pass (the issue's capacity matrix): one-, two-, three-, and
four-reference fixtures at seeds 2301-2304 — wall time and per-image
structure metrics land in the record for every request. Every request
mirrors the sealed Diffusers baseline attempt 2026-10-07T170729Z-q3-4r
(same frozen references, same rendered prompt, 20 steps, true_cfg_scale
1.0, fixture resolution, no negative prompt), submitted one at a time
through POST /v1/images/edits.
Functional pass: one-, two-, and four-reference fixtures at seed 2301.
Measured pass: the four-reference fixture at seeds 2301-2304.
The structure gate (the lesson from issue 1's FP8 misread): a run only
counts when the output is structurally sound — fully opaque RGBA and
non-flat RGB. Broken FP8 output measured ~96.5-97% transparent with
near-flat grey RGB; the BF16 path is 100% opaque. The gate numbers are
recorded on every request regardless; `gate.py` summarizes them.
Every request mirrors the sealed Diffusers baseline attempt
2026-10-07T170729Z-q3-4r (same frozen references, same rendered prompt,
20 steps, true_cfg_scale 1.0, fixture resolution, no negative prompt),
submitted one at a time through POST /v1/images/edits.
Usage: probe.py --out RUN_DIR [--matrix] [--host H:P]
Usage: probe.py --out RUN_DIR [--functional] [--measured] [--host H:P]
"""
from __future__ import annotations
@@ -25,42 +17,27 @@ from __future__ import annotations
import argparse
import base64
import hashlib
import io
import json
import pathlib
import time
import numpy as np
import requests
from PIL import Image
W = pathlib.Path.home() / "Projects/vllm-omni-val/issue5"
W = pathlib.Path.home() / "Projects/vllm-omni-val/issue2"
SUITE = (
pathlib.Path.home()
/ ".local/share/multi-model-helper-server/data/evaluation/media/image/references-suite-2"
)
STEPS = 20
CFG = 1.0
MATRIX_FIXTURES = (
FUNCTIONAL_FIXTURES = (
"edit-expression-ysolde", # 1 reference
"edit-compose-pair", # 2 references
"edit-compose-three", # 3 references (derived; see fixtures.json)
"edit-compose-four", # 4 references
)
MATRIX_SEEDS = (2301, 2302, 2303, 2304)
def structure_metrics(png: bytes) -> dict:
"""Opacity + non-flatness numbers for the structure gate."""
image = Image.open(io.BytesIO(png))
array = np.asarray(image.convert("RGBA"))
alpha = array[..., 3]
rgb = array[..., :3].astype(np.float64)
return {
"opaque_fraction": round(float((alpha == 255).mean()), 4),
"alpha_mean": round(float(alpha.mean()), 1),
"rgb_std": [round(float(rgb[..., i].std()), 1) for i in range(3)],
}
MEASURED_FIXTURE = "edit-compose-four"
MEASURED_SEEDS = (2301, 2302, 2303, 2304)
def submit(host: str, fixture: dict, seed: int) -> tuple[dict, bytes | None]:
@@ -94,7 +71,7 @@ def submit(host: str, fixture: dict, seed: int) -> tuple[dict, bytes | None]:
t0 = time.time()
try:
response = requests.post(
f"http://{host}/v1/images/edits", data=data, files=files, timeout=1800
f"http://{host}/v1/images/edits", data=data, files=files, timeout=1200
)
rec["wall_s"] = round(time.time() - t0, 2)
rec["http"] = response.status_code
@@ -103,7 +80,6 @@ def submit(host: str, fixture: dict, seed: int) -> tuple[dict, bytes | None]:
png = base64.b64decode(body["data"][0]["b64_json"])
rec["bytes"] = len(png)
rec["sha256"] = hashlib.sha256(png).hexdigest()
rec["structure"] = structure_metrics(png)
rec["usage"] = body.get("usage")
for key in ("stage_metrics", "metrics", "timings"):
if body.get(key):
@@ -124,17 +100,18 @@ def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument("--out", required=True, type=pathlib.Path)
parser.add_argument("--host", default="127.0.0.1:8091")
parser.add_argument("--matrix", action="store_true")
parser.add_argument("--functional", action="store_true")
parser.add_argument("--measured", action="store_true")
parser.add_argument(
"--fixture",
default="edit-compose-four",
help="single fixture id for --single",
default=MEASURED_FIXTURE,
help="fixture id for --measured (default: edit-compose-four)",
)
parser.add_argument("--single", action="store_true", help="one fixture, all seeds")
parser.add_argument(
"--seeds",
type=lambda s: tuple(int(x) for x in s.split(",")),
default=MATRIX_SEEDS,
default=MEASURED_SEEDS,
help="comma-separated seeds for --measured",
)
args = parser.parse_args()
@@ -142,20 +119,19 @@ def main() -> int:
args.out.mkdir(parents=True, exist_ok=True)
plan: list[tuple[str, pathlib.Path, int]] = []
if args.matrix:
for fixture_id in MATRIX_FIXTURES:
for seed in args.seeds:
plan.append(
(
fixture_id,
args.out / "matrix" / f"{fixture_id}.s{seed}.png",
seed,
)
)
if args.single:
if args.functional:
for fixture_id in FUNCTIONAL_FIXTURES:
plan.append(
(fixture_id, args.out / "functional" / f"{fixture_id}.png", 2301)
)
if args.measured:
for seed in args.seeds:
plan.append(
(args.fixture, args.out / "matrix" / f"{args.fixture}.s{seed}.png", seed)
(
args.fixture,
args.out / "measured" / f"{args.fixture}.s{seed}.png",
seed,
)
)
records = []
@@ -170,8 +146,15 @@ def main() -> int:
elif rec.get("http") == 200:
print(f"warning: 200 but no image for {fixture_id} seed {seed}", flush=True)
suffix = "matrix" if args.matrix else f"single-{args.fixture}"
(args.out / f"{suffix}.json").write_text(json.dumps(records, indent=1) + "\n")
suffix_parts = []
if args.functional:
suffix_parts.append("functional")
if args.measured:
suffix_parts.append(f"measured-{args.fixture}")
suffix = "-".join(suffix_parts)
(args.out / f"{suffix}.json").write_text(
json.dumps(records, indent=1) + "\n"
)
ok = all(r.get("http") == 200 and "sha256" in r for r in records)
print(("PASS" if ok else "FAIL") + f" {len(records)} requests", flush=True)
return 0 if ok else 1
@@ -1,14 +1,12 @@
#!/usr/bin/env python
"""Issue 5 probe: PSNR of the int8 artifact's vLLM outputs against the
sealed Diffusers baseline attempt 2026-10-07T170729Z-q3-4r.
"""Issue 2 probe: PSNR of vLLM outputs against the sealed Diffusers
four-reference baseline attempt 2026-10-07T170729Z-q3-4r.
Usage: psnr.py --fixture FIXTURE_ID RUN_DIR [RUN_DIR ...]
Compares each RUN_DIR/matrix/FIXTURE_ID.sSEED.png against the baseline
Compares each RUN_DIR/measured/FIXTURE_ID.sSEED.png against the baseline
sample with the same fixture and seed. RGBA outputs are composited over
white, matching issue 1's comparator. The sealed baseline covers the 1-,
2-, and 4-reference fixtures; the derived 3-reference fixture has no
sealed row (gate.py + visual check cover it).
white, matching issue 1's comparator.
"""
from __future__ import annotations
@@ -59,7 +57,7 @@ def main() -> int:
for run_dir in args.runs:
rows = []
for seed, base_path in sorted(baseline.items()):
ours = run_dir / "matrix" / f"{fixture}.s{seed}.png"
ours = run_dir / "measured" / f"{fixture}.s{seed}.png"
if not ours.exists():
rows.append({"seed": seed, "error": "missing"})
continue
+29
View File
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
# Issue 2 probe: serve Qwen-Image-2.1 on the RTX 3090 with one labeled
# flag set. VRAM is polled once per second for the whole server lifetime,
# matching issue 1's instrument (nvidia-smi csv series).
#
# Usage: serve.sh LABEL [extra vllm flags...]
set -uo pipefail
BASE=$HOME/Projects/vllm-omni-val
W=$BASE/issue2
LABEL=$1; shift
RUN=$W/runs/$LABEL
mkdir -p "$RUN"
SNAP=$HOME/.local/state/multi-model-helper-server/state/image-service/weights/hub/models--Qwen--Qwen-Image-2.1/snapshots/790c92633540aa0cb11d9abf19eb46d861714758
export HF_HOME=$HOME/.local/state/multi-model-helper-server/state/image-service/weights
export HF_HUB_OFFLINE=1
( while sleep 1; do nvidia-smi --query-gpu=memory.used,utilization.gpu --format=csv,noheader; done ) > "$RUN/vram.log" 2>&1 &
POLL=$!
T0=$(date +%s)
echo "flags: $*" > "$RUN/flags.txt"
$BASE/venv/bin/vllm serve "$SNAP" --omni --port 8091 \
--served-model-name Qwen/Qwen-Image-2.1 \
--enforce-eager "$@" > "$RUN/serve.log" 2>&1
RC=$?
kill $POLL 2>/dev/null
echo "serve_rc=$RC wall=$(( $(date +%s) - T0 ))s" >> "$RUN/serve.log"
-94
View File
@@ -1,94 +0,0 @@
#!/usr/bin/env python
"""Issue 5 structure gate + capacity summarizer.
Applies the gate rule from issue 1's FP8 misread to every recorded request
and folds a run directory into the capacity matrix row: per reference
count, wall time, peak VRAM, and the server-reported peak.
Gate rule (a run only counts when structurally sound):
opaque_fraction >= 0.99 AND mean(rgb_std) >= 10
Broken FP8 output measured opaque 0.008-0.035 with flat grey RGB (std of a
few); the BF16 path is 100% opaque with healthy channel spread.
Usage: gate.py RUN_DIR [RUN_DIR ...] # reads matrix.json / matrix-*.json
"""
from __future__ import annotations
import argparse
import json
import pathlib
import re
def peak_vram_mb(vram_log: pathlib.Path) -> int | None:
if not vram_log.exists():
return None
peak = 0
for line in vram_log.read_text().splitlines():
match = re.match(r"\s*(\d+)\s+MiB\s*,", line) or re.match(r"\s*(\d+),", line)
if match:
peak = max(peak, int(match.group(1)))
return peak or None
def server_peak_mb(serve_log: pathlib.Path) -> int | None:
if not serve_log.exists():
return None
peaks = [int(m) for m in re.findall(r"peak.*?(\d[\d,]+)\s*MB", serve_log.read_text())]
if not peaks:
return None
return max(peaks)
def gate(structure: dict) -> bool:
return (
structure["opaque_fraction"] >= 0.99
and sum(structure["rgb_std"]) / len(structure["rgb_std"]) >= 10
)
def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument("runs", nargs="+", type=pathlib.Path)
args = parser.parse_args()
for run_dir in args.runs:
records: list[dict] = []
for candidate in sorted(run_dir.glob("matrix*.json")):
records.extend(json.loads(candidate.read_text()))
by_refs: dict[int, list[dict]] = {}
for rec in records:
by_refs.setdefault(rec.get("n_references", 0), []).append(rec)
print(f"== {run_dir.name} ==")
all_pass = bool(records)
for n_refs in sorted(by_refs):
rows = by_refs[n_refs]
walls = [r["wall_s"] for r in rows if "wall_s" in r]
gates = [gate(r["structure"]) for r in rows if "structure" in r]
row_pass = bool(rows) and all(gates) and len(gates) == len(rows)
all_pass = all_pass and row_pass
print(
f" {n_refs}-ref: n={len(rows)} gate={'PASS' if row_pass else 'FAIL'} "
f"wall {min(walls):.1f}-{max(walls):.1f}s"
+ (f" (mean {sum(walls) / len(walls):.1f}s)" if walls else "")
)
for rec in rows:
s = rec.get("structure")
tag = "" if s is None else (" ok" if gate(s) else " BROKEN")
err = f" error={rec['error'][:80]}" if rec.get("error") else ""
print(
f" {rec.get('fixture_id')} s{rec.get('seed')}: "
f"{rec.get('wall_s')}s {json.dumps(s) if s else 'no-image'}{tag}{err}"
)
peak = peak_vram_mb(run_dir / "vram.log")
server_peak = server_peak_mb(run_dir / "serve.log")
print(f" nvidia-smi peak: {peak} MiB; server peak: {server_peak} MB")
print(f" STRUCTURE GATE: {'PASS' if all_pass else 'FAIL'}")
return 0
if __name__ == "__main__":
raise SystemExit(main())
-208
View File
@@ -1,208 +0,0 @@
#!/usr/bin/env python
"""Issue 5: quantize the Qwen-Image-2.1 DiT to int8 weight-only (W8A16) and
save it as a compressed-tensors pack-quantized checkpoint.
Quantizes exactly the linears the vllm-omni transformer constructs with
``quant_config`` — per-block attention (to_q/to_k/to_v/to_out.0) and
img_mlp (proj/gate_layer/out) — and copies every boundary layer (img_in,
txt_in, time_text_embed, modulation, norm_out, proj_out) plus the RMSNorm
q/k scales through in BF16. Per-output-channel symmetric int8, scales in
fp32, weights packed 4x uint8 (biased by 128) per int32 via
compressed-tensors' own ``pack_to_int32`` so the artifact matches the
llm-compressor storage convention bit for bit.
The artifact is a full diffusers-layout model directory: the quantized
``transformer/`` is real, the remaining components are symlinks into the
sealed snapshot. ``transformer/config.json`` carries the quantization
metadata wrapped per-component (``{"transformer": {...}}``) so vLLM-Omni's
auto-detection quantizes the DiT only — the text encoder and VAE stay BF16.
A MANIFEST.json (inputs, versions, per-file sha256, quantization stats) is
written beside the weights. Nothing here enters Git; the artifact lives
under the helper-system state root.
Usage:
quantize_dit_int8wo.py --snapshot SNAPSHOT_DIR --out ARTIFACT_DIR
"""
from __future__ import annotations
import argparse
import datetime as dt
import hashlib
import json
import platform
import re
import sys
from pathlib import Path
import torch
from compressed_tensors.compressors.pack_quantized.helpers import pack_to_int32
from compressed_tensors.config import CompressionFormat
from compressed_tensors.quantization import (
QuantizationArgs,
QuantizationConfig,
QuantizationScheme,
QuantizationStatus,
QuantizationStrategy,
QuantizationType,
)
from safetensors.torch import load_file, save_file
SNAPSHOT_COMMIT = "790c92633540aa0cb11d9abf19eb46d861714758"
# Boundary layers the vllm-omni model pins to quant_config=None (BF16), plus
# the non-linear tensors; everything else in a block is quantized.
IGNORED_TARGETS = ["img_in", "txt_in", "time_text_embed", "modulation", "norm_out", "proj_out"]
QUANTIZED_KEY = re.compile(
r"^transformer_blocks\.\d+\."
r"(attn\.(to_q|to_k|to_v|to_out\.0)|img_mlp\.(proj|gate_layer|out))\.weight$"
)
SYMLINKED_COMPONENTS = ("scheduler", "text_encoder", "vae", "processor")
SYMLINKED_FILES = ("model_index.json",)
def build_quantization_dict() -> dict:
"""Serialized compressed-tensors int8 weight-only metadata (llm-compressor schema)."""
weights = QuantizationArgs(
num_bits=8,
type=QuantizationType.INT,
symmetric=True,
strategy=QuantizationStrategy.CHANNEL,
dynamic=False,
observer="minmax",
)
scheme = QuantizationScheme(targets=["Linear"], weights=weights)
config = QuantizationConfig(
config_groups={"group_0": scheme},
format=CompressionFormat.pack_quantized,
ignore=list(IGNORED_TARGETS),
quant_method="compressed-tensors",
quantization_status=QuantizationStatus.FROZEN,
)
return config.to_dict()
def sha256_file(path: Path) -> str:
digest = hashlib.sha256()
with path.open("rb") as handle:
for chunk in iter(lambda: handle.read(1 << 20), b""):
digest.update(chunk)
return digest.hexdigest()
def quantize_weight(weight: torch.Tensor) -> tuple[torch.Tensor, torch.Tensor, dict]:
"""Per-output-channel symmetric int8: q = round(W/s), s = rowmax(|W|)/127.
Returns (weight_packed int32 [out, in/4], weight_scale fp32 [out, 1],
stats) using compressed-tensors' packer (uint8 biased by 128, 4 per int32).
"""
w = weight.detach().to(torch.float32)
scale = w.abs().amax(dim=1, keepdim=True).clamp_min(1e-12) / 127.0
q = torch.round(w / scale).clamp(-127, 127).to(torch.int8)
packed = pack_to_int32(q.contiguous(), 8).contiguous()
dequant = q.to(torch.float32) * scale
err = (w - dequant).norm() / w.norm().clamp_min(1e-12)
stats = {"rel_l2": float(err), "out": int(w.shape[0]), "in": int(w.shape[1])}
return packed, scale.to(torch.float32).contiguous(), stats
def main() -> int:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--snapshot", type=Path, required=True, help="sealed snapshot dir")
parser.add_argument("--out", type=Path, required=True, help="artifact dir to create")
args = parser.parse_args()
snapshot = args.snapshot.resolve()
if not (snapshot / "transformer" / "config.json").exists():
sys.exit(f"snapshot transformer config not found under {snapshot}")
if args.out.exists():
sys.exit(f"refusing to overwrite existing {args.out}")
artifact = args.out
(artifact / "transformer").mkdir(parents=True)
index = json.loads(
(snapshot / "transformer" / "diffusion_pytorch_model.safetensors.index.json").read_text()
)
shards = sorted(set(index["weight_map"].values()))
state: dict[str, torch.Tensor] = {}
quant_stats: dict[str, dict] = {}
quant_params = bf16_params = 0
for shard in shards:
tensors = load_file(str(snapshot / "transformer" / shard))
for name, tensor in tensors.items():
if QUANTIZED_KEY.match(name):
packed, scale, stats = quantize_weight(tensor)
state[f"{name}_packed"] = packed
state[f"{name}_scale"] = scale
state[f"{name}_shape"] = torch.tensor(tensor.shape, dtype=torch.int64)
quant_stats[name] = stats
quant_params += tensor.numel()
print(f"q {name} {tuple(tensor.shape)} rel_l2={stats['rel_l2']:.5f}", flush=True)
else:
state[name] = tensor
bf16_params += tensor.numel()
del tensors
weights_path = artifact / "transformer" / "diffusion_pytorch_model.safetensors"
save_file(state, str(weights_path), metadata={"format": "pt"})
total_bytes = weights_path.stat().st_size
config = json.loads((snapshot / "transformer" / "config.json").read_text())
config["quantization_config"] = {"transformer": build_quantization_dict()}
(artifact / "transformer" / "config.json").write_text(json.dumps(config, indent=2) + "\n")
for name in SYMLINKED_FILES:
target = snapshot / name
(artifact / name).symlink_to(target)
for name in SYMLINKED_COMPONENTS:
target = snapshot / name
(artifact / name).symlink_to(target, target_is_directory=True)
files = [
{"path": "transformer/config.json", "bytes": (artifact / "transformer" / "config.json").stat().st_size},
{"path": "transformer/diffusion_pytorch_model.safetensors", "bytes": total_bytes},
]
for entry in files:
entry["sha256"] = sha256_file(artifact / entry["path"])
tree_json = snapshot.parent.parent / "trees" / f"{SNAPSHOT_COMMIT}.json"
manifest = {
"schema": "issue5-int8wo-v1",
"created_utc": dt.datetime.now(dt.UTC).replace(microsecond=0).isoformat(),
"description": "Qwen-Image-2.1 DiT int8 weight-only (W8A16), compressed-tensors pack-quantized",
"inputs": {
"snapshot": str(snapshot),
"revision": SNAPSHOT_COMMIT,
"tree_manifest": str(tree_json),
"tree_sha256": sha256_file(tree_json) if tree_json.exists() else None,
},
"versions": {
"python": platform.python_version(),
"torch": torch.__version__,
"compressed_tensors": __import__("compressed_tensors").__version__,
},
"quantization": {
"method": "compressed-tensors",
"format": "pack-quantized",
"weights": "int8 symmetric per-output-channel, static, minmax",
"config": build_quantization_dict(),
"ignored_layers": list(IGNORED_TARGETS),
"note": "ignore list mirrors the vllm-omni model's quant_config=None boundary layers",
},
"stats": {
"quantized_tensors": len(quant_stats),
"quantized_params": quant_params,
"bf16_params": bf16_params,
"mean_rel_l2": sum(s["rel_l2"] for s in quant_stats.values()) / max(len(quant_stats), 1),
"max_rel_l2": max((s["rel_l2"] for s in quant_stats.values()), default=0.0),
"weights_file_bytes": total_bytes,
},
"files": files,
}
(artifact / "MANIFEST.json").write_text(json.dumps(manifest, indent=1) + "\n")
print(json.dumps(manifest["stats"], indent=1))
print(f"artifact: {artifact}")
return 0
if __name__ == "__main__":
raise SystemExit(main())
-33
View File
@@ -1,33 +0,0 @@
#!/usr/bin/env bash
# Issue 5 probe: serve the int8 weight-only compressed-tensors artifact on
# the RTX 3090 with one labeled flag set. VRAM is polled once per second for
# the whole server lifetime, matching issue 2's instrument (nvidia-smi csv
# series). The default flag set is cpu-offload + eager; pass extras after
# the label to override/extend (they are appended, vLLM last-one-wins).
#
# Usage: serve.sh LABEL [extra vllm flags...]
set -uo pipefail
BASE=$HOME/Projects/vllm-omni-val
W=$BASE/issue5
LABEL=$1; shift
RUN=$W/runs/$LABEL
mkdir -p "$RUN"
STATE=$HOME/.local/state/multi-model-helper-server/state/image-service
ARTIFACT=${ARTIFACT:-$STATE/artifacts/qwen-image-2.1-dit-int8wo}
export HF_HOME=$STATE/weights
export HF_HUB_OFFLINE=1
( while sleep 1; do nvidia-smi --query-gpu=memory.used,utilization.gpu --format=csv,noheader; done ) > "$RUN/vram.log" 2>&1 &
POLL=$!
T0=$(date +%s)
echo "model: $ARTIFACT" > "$RUN/flags.txt"
echo "flags: $*" >> "$RUN/flags.txt"
$BASE/venv/bin/vllm serve "$ARTIFACT" --omni --port 8091 \
--served-model-name Qwen/Qwen-Image-2.1 \
--enforce-eager --enable-cpu-offload "$@" > "$RUN/serve.log" 2>&1
RC=$?
kill $POLL 2>/dev/null
echo "serve_rc=$RC wall=$(( $(date +%s) - T0 ))s" >> "$RUN/serve.log"
-72
View File
@@ -1,72 +0,0 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM-Omni project
"""Tests for the quantization config factory's method-name and disk-dict resolution."""
from __future__ import annotations
import pytest
from vllm.model_executor.layers.quantization.compressed_tensors.compressed_tensors import (
CompressedTensorsConfig,
)
from vllm_omni.quantization import build_quant_config, resolve_component_quant_config
from vllm_omni.quantization.component_config import (
ComponentQuantizationConfig,
resolve_encoder_quant_config,
)
from vllm_omni.quantization.factory import SUPPORTED_QUANTIZATION_METHODS, _build_single
def _int8_weight_only_disk_config() -> dict:
"""Serialized compressed-tensors int8 weight-only metadata as it appears on disk."""
weights = {
"num_bits": 8,
"type": "int",
"symmetric": True,
"strategy": "channel",
"dynamic": False,
"observer": "minmax",
}
return {
"quant_method": "compressed-tensors",
"format": "pack-quantized",
"config_groups": {"group_0": {"targets": ["Linear"], "weights": weights}},
"ignore": ["img_in"],
"quantization_status": "frozen",
}
def test_hyphenated_registry_method_builds_from_str() -> None:
config = _build_single("compressed-tensors")
assert isinstance(config, CompressedTensorsConfig)
assert config.get_name() == "compressed-tensors"
@pytest.mark.parametrize("spelling", ["compressed-tensors", "compressed_tensors"])
def test_disk_dict_builds_via_from_config(spelling: str) -> None:
disk = _int8_weight_only_disk_config()
disk["quant_method"] = spelling
config = build_quant_config(disk)
assert isinstance(config, CompressedTensorsConfig)
def test_per_component_dict_routes_transformer_only() -> None:
disk = {"transformer": _int8_weight_only_disk_config()}
config = build_quant_config(disk)
assert isinstance(config, ComponentQuantizationConfig)
assert isinstance(
resolve_component_quant_config(config, "transformer"), CompressedTensorsConfig
)
encoder = resolve_encoder_quant_config(
resolve_component_quant_config(config, "text_encoder")
)
assert encoder is None
def test_unknown_method_still_raises() -> None:
with pytest.raises(ValueError, match="Unknown quantization method"):
_build_single("not-a-real-method")
def test_supported_list_advertises_hyphenated_registry_names() -> None:
assert "compressed-tensors" in SUPPORTED_QUANTIZATION_METHODS
+6 -26
View File
@@ -326,36 +326,20 @@ def _build_from_method_and_config(method: str, config: Mapping[str, Any]) -> Qua
return _build_single(method, **config)
def _resolve_registry_method_name(method: str) -> str | None:
"""Resolve a normalized (underscore) method name to vLLM's registry spelling.
vLLM's ``QUANTIZATION_METHODS`` keeps canonical names with their historical
spelling — including hyphenated ones such as ``compressed-tensors`` — while
``_normalize_method_name`` canonicalizes dashes to underscores for the
``_OVERRIDES`` lookup. Try both spellings so hyphenated registry entries
remain reachable.
"""
for candidate in (method, method.replace("_", "-")):
if candidate in QUANTIZATION_METHODS:
return candidate
return None
def _build_single(method: str, **kwargs: Any) -> QuantizationConfig:
"""Build a single QuantizationConfig by method name.
Resolution: _OVERRIDES first, then vLLM registry via from_config().
"""
normalized = _normalize_method_name(method)
method = _normalize_method_name(method)
if normalized in _OVERRIDES:
return _OVERRIDES[normalized](**kwargs)
if method in _OVERRIDES:
return _OVERRIDES[method](**kwargs)
registry_method = _resolve_registry_method_name(normalized)
if registry_method is None:
if method not in QUANTIZATION_METHODS:
raise ValueError(f"Unknown quantization method: {method!r}. Supported: {SUPPORTED_QUANTIZATION_METHODS}")
config_cls = get_quantization_config(registry_method)
config_cls = get_quantization_config(method)
from vllm.config.quantization import resolve_quantization_config
from vllm.model_executor.layers.quantization.online.base import OnlineQuantizationConfig
@@ -363,7 +347,7 @@ def _build_single(method: str, **kwargs: Any) -> QuantizationConfig:
if config_cls is OnlineQuantizationConfig:
if "args" in kwargs:
return config_cls(**kwargs)
args = resolve_quantization_config(registry_method, kwargs or None)
args = resolve_quantization_config(method, kwargs or None)
if args is None:
raise ValueError("Online quantization requires quantization config arguments")
return config_cls(args)
@@ -371,10 +355,6 @@ def _build_single(method: str, **kwargs: Any) -> QuantizationConfig:
try:
return config_cls(**kwargs)
except TypeError:
# Registry configs built from checkpoint metadata (e.g. compressed-tensors)
# take the serialized schema through from_config rather than __init__.
if kwargs and hasattr(config_cls, "from_config"):
return config_cls.from_config(dict(kwargs))
sig = inspect.signature(config_cls.__init__)
raise TypeError(
f"Cannot instantiate {config_cls.__name__} with kwargs {kwargs}. Expected signature: {sig}"