Skip to content

Llava-hd Support - #92

Merged
Ying1123 merged 7 commits into
mainfrom
llava-hd
Jan 24, 2024
Merged

Ying1123 merged 7 commits into
mainfrom
llava-hd

Conversation

@caoshiyi

Copy link
Copy Markdown
Contributor

Add support for high-resolution llava

Comment thread python/sglang/srt/mm_utils.py Resolved
Comment thread python/sglang/srt/models/llama2.py Resolved
@caoshiyi
caoshiyi requested a review from Ying1123 January 24, 2024 08:41
@Ying1123
Ying1123 merged commit c6576e8 into main Jan 24, 2024
@Ying1123
Ying1123 deleted the llava-hd branch January 24, 2024 09:51
timethink pushed a commit to timethink/sglang that referenced this pull request Mar 9, 2025
NorthmanPKU pushed a commit to NorthmanPKU/sglang that referenced this pull request May 16, 2025
* fix & upd range

* adjust heuristics for grid dim enumeration

* better search statistics display

* add verbose flag

---------

Co-authored-by: Mengdi Wu <[email protected]>
cicirori added a commit that referenced this pull request Aug 26, 2025
CaoE referenced this pull request in CaoE/sglang Oct 28, 2025
efschu added a commit to efschu/htsglang that referenced this pull request Jul 18, 2026
…t-cause the TW Gemma-4 accept collapse

Root cause of the sgl-project#92 collapse (accept 0.03-0.11/drafted token): the
thoughtworks/Gemma-4-31B-Eagle3 head is trained on BASE google/gemma-4-31B,
not the served -it variant. Proven offline (features through the fork's own
ModelRunner, head standalone): draft/target top-1 overlap 0.61 vs bf16 BASE
self-text, but 0.24 vs bf16-IT and 0.21 vs int4-IT (int4-AutoRound itself
costs only ~0.03 — 'mild', as reported elsewhere). Wiring exonerated by
perturbation: no d2t -> 0.00, reversed aux order -> 0.02, aux ids +-1 ->
0.14/0.24; nothing moves toward healthy, so serving feeds the head
correctly. NOT a fork bug.

Fix: serve the IT-trained RedHatAI/gemma-4-31B-it-speculator.eagle3 head.
Two speculators-format (vLLM ecosystem) conventions handled:
- aux layer ids are vLLM-convention (id i = INPUT of layer i): converter
  translates [2,30,57] -> sglang outputs [1,29,56]. Raw ids cost 0.20
  overlap (0.36 vs 0.56 measured on the int4-IT serving target).
- norm_before_residual=True: input-layer residual is the NORMED hidden.
  New config flag in llama_eagle3.py, default False keeps the SpecForge
  path byte-identical (the False branch is the unmodified original code).
- test/manual/spec/convert_speculators_eagle3.py writes the SpecForge-style
  config and hardlinks the safetensors unchanged.

E2E on the sgl-project#92 rig/battery (TP=3 uneven 5090+2x3080, int4 target, boots
7-11): healthy 40-60s, zero divergence, 4/4 temp-0 coherence probes
byte-identical to the no-spec oracle, needle@8k found, deterministic across
identical-cache-state repeats, cross-boot bit-identical accepts.
Tree (3,4,8): accept-len incl bonus 1.87-2.89 (was 1.19-1.5); decode 68.7
tok/s code / 66.0 prose / 84.1 json vs 58.2 no-spec baseline (1.13-1.44x).
Creative-fiction decode 55.1 (0.95x) and deep@8k decode remain net-negative
on this rig: fixed per-verify overhead dominates (cycle rate 29-39/s vs
59.6 no-spec) — speculation recommended for instruct/code/structured
workloads only. Full data: T92_RESULTS.md section 4 (T101) in the task dir.
efschu added a commit to efschu/htsglang that referenced this pull request Jul 22, 2026
… free patterns

Pins the four structural guards that make the upstream-sglang SWAKVPool
double-free bug-class (hit by the Thoughtworks Gemma-4 EAGLE3 bring-up)
impossible in this fork:
- slot 0 of both sub-pools is a reserved dummy -> mapping value 0
  unambiguously means unmapped
- free() clears the full->swa mapping, so the SWA side of a repeated
  free is a no-op by construction
- the -1 tail sentinel (last_loc translation) survives clear()
- the slot-conservation assert catches caller-level full-side
  double-frees instead of silently corrupting the free list

Includes an explicit double-free probe and a 60-cycle verify-shaped
alloc/free workload with exact slot-conservation checks. CPU-only.
Test result: 5 passed (pytest, no GPU).
efschu added a commit to efschu/htsglang that referenced this pull request Jul 22, 2026
…n, TW head accept collapsed

Gemma-4-31B int4-AutoRound + thoughtworks Gemma-4-31B-Eagle3, TP=3 uneven
(5090 + 2x3080, --rank-tp-ratio auto), chain (steps=3, topk=1, draft=4),
ctx 16384, graphs ON. Full battery vs same-commit no-spec oracle:

- Boots healthy in 35 s after the sgl-project#100 LlamaMLP fix (32b972f); rope
  override 4096->16384 fired on all ranks; zero divergence/desync warnings.
- Correctness: 4/4 temp-0 coherence probes byte-IDENTICAL to the oracle;
  needle@8k FOUND; deterministic across identical-cache-state repeats.
  The 512-tok story probe diverges at a near-tie (both texts coherent) and
  the server is not self-deterministic across cached-vs-uncached prefill of
  the same prompt (run2==run3, run1 differs) -> batch-shape numerics, not
  attributable to the verify path.
- Acceptance: COLLAPSED. accept-len 1.19-1.5 incl. bonus; log accept rate
  0.03-0.11 per drafted token. Decode 41.9 tok/s shallow (0.72x of the
  58.2 no-spec graph baseline), 22.3 tok/s @8k (0.43x of 51.5) — the chain
  config is a net slowdown with this head on this target.
- Deep accept did NOT collapse vs shallow (1.5 @8k) — rope extrapolation
  fallback (--speculative-draft-window-size) not triggered.
- Embed-normalizer hypothesis REFUTED structurally: hardcoded-ON A/B run
  produced bit-identical accept (prose 1.4021739130434783 both runs) —
  the EAGLE3 input layer RMSNorms the embeds, so any uniform embed scale
  is mathematically invisible. Patch reverted. (Also learned: scheduler
  children are spawned with a constructed minimal env; ad-hoc launcher env
  vars do not reach model forwards.)
- Root cause of low accept (d2t map, aux-layer indices, int4-target vs
  bf16-trained-head mismatch, ...) intentionally out of scope for sgl-project#92.

Full battery table: T92_RESULTS.md section 3.2 (job workspace), probe JSONs
probes_oracle.json / probes_eagle3.json / probes_eagle3_normB.json.
efschu added a commit to efschu/htsglang that referenced this pull request Jul 22, 2026
…t-cause the TW Gemma-4 accept collapse

Root cause of the sgl-project#92 collapse (accept 0.03-0.11/drafted token): the
thoughtworks/Gemma-4-31B-Eagle3 head is trained on BASE google/gemma-4-31B,
not the served -it variant. Proven offline (features through the fork's own
ModelRunner, head standalone): draft/target top-1 overlap 0.61 vs bf16 BASE
self-text, but 0.24 vs bf16-IT and 0.21 vs int4-IT (int4-AutoRound itself
costs only ~0.03 — 'mild', as reported elsewhere). Wiring exonerated by
perturbation: no d2t -> 0.00, reversed aux order -> 0.02, aux ids +-1 ->
0.14/0.24; nothing moves toward healthy, so serving feeds the head
correctly. NOT a fork bug.

Fix: serve the IT-trained RedHatAI/gemma-4-31B-it-speculator.eagle3 head.
Two speculators-format (vLLM ecosystem) conventions handled:
- aux layer ids are vLLM-convention (id i = INPUT of layer i): converter
  translates [2,30,57] -> sglang outputs [1,29,56]. Raw ids cost 0.20
  overlap (0.36 vs 0.56 measured on the int4-IT serving target).
- norm_before_residual=True: input-layer residual is the NORMED hidden.
  New config flag in llama_eagle3.py, default False keeps the SpecForge
  path byte-identical (the False branch is the unmodified original code).
- test/manual/spec/convert_speculators_eagle3.py writes the SpecForge-style
  config and hardlinks the safetensors unchanged.

E2E on the sgl-project#92 rig/battery (TP=3 uneven 5090+2x3080, int4 target, boots
7-11): healthy 40-60s, zero divergence, 4/4 temp-0 coherence probes
byte-identical to the no-spec oracle, needle@8k found, deterministic across
identical-cache-state repeats, cross-boot bit-identical accepts.
Tree (3,4,8): accept-len incl bonus 1.87-2.89 (was 1.19-1.5); decode 68.7
tok/s code / 66.0 prose / 84.1 json vs 58.2 no-spec baseline (1.13-1.44x).
Creative-fiction decode 55.1 (0.95x) and deep@8k decode remain net-negative
on this rig: fixed per-verify overhead dominates (cycle rate 29-39/s vs
59.6 no-spec) — speculation recommended for instruct/code/structured
workloads only. Full data: T92_RESULTS.md section 4 (T101) in the task dir.
yicyang pushed a commit to yicyang/sglang that referenced this pull request Nov 11, 2026
* fix(multimodal): bound ROCm IPC waits with server watchdog timeout

- Reuse --watchdog-timeout for stream-ordered ROCm IPC readiness waits.
- Track GPU completion independently of scheduler batch activity.
- Log wait diagnostics and terminate consumers on timeout or query failure.
- Preserve supervision after event-record failures and reject graph capture.
- Add timeout and cached/uncached peer-IPC tests with two-GPU AMD CI.

Signed-off-by: Xiake Sun <[email protected]>
(cherry picked from commit b8fb891)

* eval: enable cuda_ipc for qwen3.8 by default

Signed-off-by: Xiake Sun <[email protected]>
(cherry picked from commit a11f80c)

* fix(multimodal): skip the fast-processor MemPool on ROCm

With concurrent image requests on MI308X the server can abort with
"captures_underway.empty() INTERNAL ASSERT FAILED" in HIPCachingAllocator
(synchronize_and_free_events). _temporary_fast_processor_cuda_pool enters a
torch.cuda.MemPool around the fast image processor; PyTorch counts an active
pool as a capture underway, so when another thread's allocation has to free
cached blocks at the same time, the allocator asserts.

The GPU fast-processor path runs one processor worker by default, which
avoids it; with --mm-processor-worker-num 2, Qwen3.8 TP2 aborted 8.5 s into
16 concurrent requests. Skip the pool on ROCm: the same run completes all 48
requests, and sequential latency is unchanged.

(cherry picked from commit c1c07832415ab71de53c562fa3dfd4b31696f6d8)
(cherry picked from commit ce41c73)
Signed-off-by: Xiake Sun <[email protected]>

* feat(multimodal): decode JPEG inputs with rocJPEG on ROCm

Image inputs on ROCm are always decoded on the CPU with PIL: the GPU path in
_load_image only runs when is_cuda() is true. With torchvision built with
rocJPEG, decode_jpeg(device="cuda") works on MI300-series GPUs.

SGLANG_ROCM_GPU_JPEG_DECODE=1 enables it (sglang/srt/utils/rocjpeg_decoder.py):
- rocJPEG converts YCbCr to RGB with BT.709 coefficients instead of JPEG's
  BT.601; one Triton kernel maps its output back with a 3x3 matrix. On first
  use a color test image is decoded and compared with PIL; if rocJPEG is
  unavailable or the corrected output does not match, PIL is used as before.
- Decoding JPEGs one by one serializes on torchvision's rocJPEG decoder lock,
  so _load_single_item keeps the bytes of JPEGs rocJPEG accepts (checked from
  the frame header) and the load functions decode a request's JPEGs in one
  decode_jpeg(list) call on the io executor. Other images (PNG, progressive,
  CMYK, below 64x64) go through PIL; if the batch call fails, the images are
  decoded with PIL.

(cherry picked from commit 698e07e10578b882fbcc151e5ed7e021b477b5fc)
(cherry picked from commit 6533d5e)
Signed-off-by: Xiake Sun <[email protected]>

* fix(multimodal): apply the rocJPEG color correction only when needed

rocJPEG before 1.10.0 converts YCbCr to RGB with BT.709 coefficients; 1.10.0
switched to BT.601 (ROCm/rocm-systems#11520) and keeps BT.709 as a build
option. The self-check now compares the decoded test image with PIL as decoded
and after the correction, and uses whichever matches, so a rocJPEG that already
outputs BT.601 keeps the GPU path instead of falling back to PIL.

Also cite the sources of the correction matrix (JFIF/BT.601 and BT.709 luma
weights, rocJPEG's kernel coefficients) and write out its values.

(cherry picked from commit f5a664e)
Signed-off-by: Xiake Sun <[email protected]>

* feat(multimodal): allow forcing the rocJPEG color correction on or off

For A/B tests of the BT.709-to-BT.601 correction (bit level and end-to-end
evaluation), decode_deferred_jpegs takes color_correction=True/False, and
SGLANG_ROCM_JPEG_COLOR_CORRECTION=1/0 sets it for the server, which calls
decode_deferred_jpegs without arguments. Unset, the self-check decides as
before.

Also note in the self-check's docstring that it runs once per process on a
128x128 image, so only 48 KiB is copied to the host; request images stay on
the GPU.

(cherry picked from commit 122f866)
Signed-off-by: Xiake Sun <[email protected]>

* refactor(multimodal): simplify the rocJPEG decoder

- The BT.709-to-BT.601 color correction is a torch matmul instead of a
  Triton kernel. Its output is within 1 of the kernel's (rounding); it
  takes about 3 ms per request with 8 1080p images (0.3 ms before).
- rocjpeg_can_decode reads the JPEG header with PIL instead of a
  hand-written marker parser. On real rocJPEG it makes the same decisions
  for every tested variant (4:2:0, 4:2:2, 4:4:4, gray, progressive, CMYK,
  sizes, 4:1:1, truncated).
- The self-check measures the error vs PIL with and without the
  correction and keeps the smaller. One log line says whether GPU JPEG
  decoding is on, or why it is off and which libva settings it needs.
- base_processor keeps its original load_image call: on ROCm load_image
  never decodes on the GPU, so passing gpu_image_decode=False was a no-op.

Signed-off-by: bobofang11235 <[email protected]>
(cherry picked from commit 2c960dc)
Signed-off-by: Xiake Sun <[email protected]>

* test: add multimodal & cuda ipc setting in eval launch scripts and ci test

Signed-off-by: Xiake Sun <[email protected]>

* ci: enhance multimodal test for rocjpeg image decoding

Signed-off-by: Xiake Sun <[email protected]>

* eval: make libva env vairable overridable in launch script

Signed-off-by: Xiake Sun <[email protected]>

---------

Signed-off-by: Xiake Sun <[email protected]>
Signed-off-by: bobofang11235 <[email protected]>
Co-authored-by: bobofang11235 <[email protected]>
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.

3 participants