Repository navigation
vision: SparkQwen 0.4.0 vision/video path (content-keyed vision cache, per-seq state, whole-request admission, hour video, #239 fix; ported from Enntity) - #286
Merged
Conversation
Image prompts bypassed the prefix cache entirely: every image is the same run of placeholder tokens, so radix keys built from raw tokens let a different image reuse an earlier one's KV. Once an image entered a long conversation, every later turn re-prefilled the whole history and re-encoded every image (92-97K tokens, ~35 s TTFT per turn on the pair). Key the cache by content instead, the vLLM mm_hash / SGLang pad_value way: - VisionItem::content_hash: SHA-256 (128 bits) of the preprocessed pixels, grid and temporal groups, computed where the server builds the item. - spark-runtime prefix_cache::vision_key: the cache key replaces the n-th placeholder of item i with an out-of-vocabulary id (top bit set) derived from (hash_i, n). Different images diverge at their first placeholder, a re-sent image matches in full, text before the first image keys as text. - SequenceState::vision_cache_key, stamped at chunk 0 on every rank; every prefix-cache call goes through TransformerModel::pc_key / pc_key_tokens (lookup, NVMe restore, F83 cap, restore agreement, branch planning, inserts, interval/tail checkpoints, release). Embedding, splice, MRoPE and the drafters keep the real tokens. - EP_CMD_VISION_STATE carries the item hashes (7-word item records) so the worker rebuilds the same key and its radix walk agrees with the head's. - Only items the prefill computes are encoded: on the chunked path the head stages the items, the chunk-0 lookup fixes the first computed position (min-reduced across ranks), and only items reaching it go through the ViT and over the wire. The splice offsets rows by the skipped items' rows. - proc_range's re-embed of a partly cached chunk now applies the vision splice; it never ran for vision before because vision never hit. - Scope: GLM-5 vision only (its MRoPE walker rebuilds positions from the whole prompt); ATLAS_VISION_PREFIX_CACHE=0 restores the old behaviour. A vision sequence's generated tokens are not cached: decode writes them at linear positions, a re-prefill at compressed MRoPE positions. Tests: spark-runtime vision_key (keys, mismatches, split video runs) and radix tests replacing the #58 collision test (different hashes miss, same image hits, swapped image misses from its first block, text before the first image hits, ranks agree); spark-model vision_cache, vision_transport (hash round trip, deferred flag), embed_chunk row offsets, content hash. Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit ab671c1)
…out_hidden_size()/leaf_on()/splice_vision_rows call shape, VisionWireState derive
The model held ONE vision state (encoder rows, item grids, item hashes) that every chunk of an image prompt read, and a long prompt chunks across scheduler ticks: a second image request whose chunk 0 ran in between re-encoded into the same buffer, and the first prompt's remaining chunks spliced the second request's image (reproduced on the pair: A answered with B's image). The state moves onto the sequence (SequenceState::vision, a SeqVision: items, grids, hashes, cached-row skip, computed_from, the buf_out window). Every chunk encodes only the items whose placeholders it computes, right before its embed (chunk 0's inside its prefix lookup, once the cached prefix is agreed), and the splice consumes them at once; buf_out stays one shared scratch buffer and nothing in it outlives a chunk. An item straddling a chunk boundary is re-encoded at each chunk it reaches. Before writing buf_out the encode drains the prefill stream, whose queued splice may still read the previous chunk's rows. A worker runs the same selection from its grids and receives each chunk's rows by broadcast; the wire format is unchanged. Image prompts interleave freely, with no extra device memory. A sequence's staged pixels are dropped when its last prompt chunk succeeds. Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit 4b30eb8)
A Qwen image prompt with more placeholder tokens than its image has rows (three literal `<|image_pad|>`/`<|video_pad|>` strings in a pasted code file) made the splice bail on both ranks; the EP worker treated the error as fatal and terminated, which took the pair down with it. These checks read only data every rank holds alike (the prompt, the staged grids, the agreed cached prefix) and run at the same point of the same command before the chunk's layers launch a collective, so the ranks are still in step when they fail. They now raise `RequestLocalError`, and the worker loop keeps serving on one: the head already fails the request and resets the worker's slot (0xFFFFFFF1). The head-only encode is agreed across the ranks (`ep_min_u32`) before its payload broadcast, so a head-side encode failure can no longer leave the worker waiting in a collective the head never issues. Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit 89dbef7)
… and the in-flight budget Admission ran after every item was decoded to f32, so a request over its limits could exhaust host memory before its 400 (a body of tiny PNGs declaring 4096^2 each, up to 1024 of them, several requests at once on the blocking pool). `build_msg_entries_admitted` now checks the item count before reading any item, sizes each still from its header (`probe_image`), and charges it to `vision_admit::Admission` before decoding: a 400 (`vision_input_too_large`) as soon as one item passes the window or the running total passes the request limit, a 503 with `Retry-After: 2` (`vision_capacity_busy`) when the in-flight budget cannot hold it, and the worst-chunk check once every item is charged. A video is charged once decoded (bounded by its own decode budget; no header probe). Messages say "images or videos" when a video is present, and name counts only. New knob `--vision-max-inflight-rows` (default 65536: 1.5 GiB of f32 on the Qwen tower, 1.15 GiB on GLM; 0 = unbounded) sizes the budget; the per-request limit is capped by it, since a larger request could never acquire it and would be told to retry forever. The item-count refusal now applies on a single rank too (documented). The request bound comes from the engine (`Model::vision_row_limits`): `max_seq_len` for the Qwen tower, but the native GLM tower keeps a deferred request inside its 16384-row window (no behaviour change on GLM beyond the clean 400; enlarging `GLM_MAX_OUTPUT_ROWS` is a follow-up for the GLM session). A model whose vision tower did not load (window 0) serves text: the API drops its vision config and refuses media as for a text model, instead of naming a 0-row window. Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit 7d33dd4)
…, AdmitCtx arg order, VisionConfig fields, glm_tool_boundary fixture
Only the chunked entry cleared `seq.vision.items` after its last chunk; the non-chunked, two-phase and fused-with-decode paths kept a request's pixels (and its in-flight vision permit) for its whole decode. The scheduler now drops them once a tick for every sequence in `active`, which every finished prefill passes through (`scheduler::vision_release`). The blocking path (non-streaming chat, Responses, Anthropic) deep-copied the pixels into choice 0 and held the original until every choice ended: it now moves them. The immediate encode (`prepare_vision_embed`) takes the `Vec` by value too, so no path keeps a second copy. Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit 55bebc0)
- The item count is checked before any media is fetched (with `--vision-allow-remote-images`, 1025 URLs were fetched before their 400), and remote fetches of one request bring in at most 32 MiB. - `msg_entry::media` sizes every item first (stills from their headers, videos by decoding), checking the request limit and the window as each is sized (400); then the whole-request check (400) and ONE acquire of the request's rows from the in-flight budget (503): a request holds all of its rows or none, so large requests do not hold parts and starve or fail each other, and a request that can never fit gets its 400 before any 503. Then the stills are decoded; every item shares the request's permit. - The 503 says "vision capacity is busy; retry shortly", nothing about what other requests hold. - count_tokens strips video parts as well as images (neither is decoded or charged to count). `build_msg_entries` (no bounds) is test-only. Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit b060f98)
…h cap counts data-URI bytes - `--vision-max-request-rows 0` used the whole in-flight budget, so one request could need all of it and starve behind small ones; unset it is now half the budget (or the context with no budget). The defaults are 32768 per request and 65536 in flight, already half. - The remote-fetch cap counts data-URI (base64) bytes; the message now says so, and `charge_fetched` is tested. Its doc comment no longer sits under `MediaInput`'s. Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit 92dd543)
(cherry picked from commit 9fabbf1)
(cherry picked from commit 46134a7)
…ision_preprocess::fixtures un-gated, tail/media split
…l chunks (cherry picked from commit a3ed7d2)
(cherry picked from commit fa81056)
(cherry picked from commit 2837e76)
…process_media placeholder args, video_max_pixels dedup
…unstable on stable)
… fetch_update attr (main's form builds clean)
…eplaces the corrupt hand-written constant
…col/format whitelist, f64 native_fps
…sure_decoder already inline)
# Conflicts: # crates/spark-server/src/tokenizer/chat_impl.rs
… sequence/compact.rs
…sequence.rs (502) under the 500-LoC cap
…tch_with.rs, reconcile.rs siblings
Contributor
Author
|
Ran the vision battery on the pair against this head (
|
4 of 6 tasks
Contributor
Author
|
GB10 single-Spark confirmation (sparky, post-merge): this PR was gated as part of
|
This was referenced Nov 1, 2026
6 of 7 tasks
This was referenced Nov 1, 2026
vcruz305
pushed a commit
to vcruz305/atlas
that referenced
this pull request
Nov 11, 2026
…-Inf#256) Port of Atlas-Inf#256 (Enntity/atlas f3f3876 via 5497364, plus 8a8a959 from Atlas-Inf#295) onto main's Atlas-Inf#286 video path. Atlas-Inf#256's stack base already landed through Atlas-Inf#282, and the DFlash warm-ctx port from the same stack (Atlas-Inf#255) is not included. Every video file here is byte-identical to the version gated in train Atlas-Inf#305. - ensure_decoder is the single source for the ffmpeg enabled/available check, in video_decode_ffmpeg/probe.rs (pub(super)); decode_with_plan and frames.rs call it. - The moov/faststart decode tests use the enabled() policy; on a host with ffmpeg they fail on main under FfmpegPolicy::default(). - The GLM reference path pads a single sampled frame into a temporal pair. Qwen's generic path is unchanged. - The generic-path GLM single-frame refusal test is dropped, superseded by the reference pad test (the generic GLM branches are now unreachable behind the is_glm5_next early return; follow-up). Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SparkQwen 0.4.0's vision and video path for qwen4_exp. Ported from Enntity (AGPL-3.0, data-angel). Where #233/#236/#237/#252 already carried earlier versions of this work, the result is 0.4.0's final code.
ab671c1e3: content-keyed vision prefix cache (issue [job] DFlash2: batched concurrency on main #58).4b30eb82a: per-sequence vision state and per-chunk encode.89dbef7e4: an EP vision layout error fails its request, not the ranks.7d33dd4cc,b060f9872,92dd5435d,55bebc038: header-first, whole-request admission against row budgets; an unset limit is half the in-flight budget; the fetch cap counts data-URI bytes; pixels and permits are released at prefill end.9fabbf1c5: shared image pixels across blocking choices.46134a750,a3ed7d2a0,fa8105685,2837e761a: Qwen video timestamps and per-frame positions, streaming hour-video decode in temporal chunks, video endpoints, padded temporal groups.a3ed7d2a0also fixes video: MP4 with the moov atom at the end fails to decode (ffmpeg reads the container from pipe:0) #239: ffmpeg and ffprobe read a private, seekable 0600 temp file instead ofpipe:0, so an MP4 with moov at the end decodes. A dead stdin pipe inprobe.rsthat errored on every probe is removed.VisionToweris kept.vision_admit,vision_transport,vision_limits,vision_cache,png_streamandinputare byte-identical.Test plan
--tests) and fmt are clean. A new MP4 test covers moov-at-end and faststart.union_check,lp_api_probeandapi_parityare unchanged from the parent.Generated with Devin