Repository navigation
serve, vision, gpu-gates, tools: EmbeddingGemma 2 sampled video frames through the embedding endpoints, checked against llama-server - #397
Conversation
There was a problem hiding this comment.
Verdict: CLEAN: No must-fix defect was found in video routing, frame preparation, capacity checks, or gate comparisons.
Checked
Duplicates: 7 new functions/methods checked with Grep; no duplicate requiring extraction. Dryer reported 0 pairs. Existing preparation, assembly, HTTP, reference-reader, and server-lifetime owners are reused.
Complexity: videos (new, 37) has manifest validation, vector requests/comparisons, and refusal stages. run (75 → 87) adds mode branches; input (12 → 17) adds video selection; the input-contract test (3 → 12) adds boundary cases. No correctness defect found in these branches.
Silent failure: 1 new routing fallback followed. A failed prefix parse is parsed again by the ordered input iterator and reaches the client as a named 400 error.
Tests, static mutation check: changing > to >= at crates/vision/src/arch/gemma4v/media.rs:145 fails the exact-capacity assertions. Decoding all frames before preparation at crates/serve/src/media.rs:497 fails the first-frame-error assertion.
Tests, static mutation check: removing the encoded-video arm at crates/serve/src/media.rs:372 fails both changed tests' named-refusal assertions. Disabling video selection at crates/serve/src/embeddings.rs:291 fails prepared-frame assertions and the new HTTP gate's prompt-count check; the PR reports this FAIL-first run.
Gates: no bands or pins moved. Empty/33-frame inputs, exact context limits, capacity boundaries, distinct frame order, and encoded-part refusals are covered.
Adversarial: malformed later frames preserve the first preparation error; concurrent inference uses the existing model mutex; gate errors retain server cleanup through Served.
Escape catalog: no C1–C4 pattern matched.
Notes
Dryer did not search crates/gpu-gates; its additions were checked manually. Validation was static; no builds or runtime tests were run. The PR body reports GPU results.
Card check: gpu-evidence. This pull request changes crates/gpu-gates/src/bin/gate_gemma_embedding2_serve.rs and carries a gate run on the author's card, which counts as verified.
🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)
|
The review is done and the contribution check passed, so I'm merging this. |
Part of #59 (plan and PR order in #190), item V3:
bloomery-serveembeds a video clip that the client has already sampled at one frame per second, and a serve gate checks the served vectors against llama.cpp. It builds on V1 (#374) and V2 (#383) and has one commit.What and why
Release notes: Added: EmbeddingGemma 2 embeds sampled video. Send a
Video:text part followed by 1 to 32 one-FPSimage_urlframes to/v1/embeddings.V1 ran ordered frames through the Gemma4 vision tower, and V2 picked those frames from a decoded clip. Neither was reachable over HTTP. This PR connects them to the embedding endpoints without a new request format.
The input is the request that V2's reference collector already sends to llama-server: a content array whose first part is a text part with the exact text
Video:, followed by the sampled frames asimage_urlparts holding base64 PNG or JPEG data URLs (tools/ref/emb2/server_vectors.py:286-295). Mainline llama-server takes the same request throughtokenize_oai_content_array(server-context.cpp:6059-6065). One request therefore works on both servers; the reference collector and serve gate use that request.crates/vision/src/{media.rs,arch/gemma4v/media.rs}).MediaModelgainsembedding_video, which names the text prefix and the frame limit, andprepare_video. The trait's default refuses by name. Gemma4's implementation returnsVideo:and its 32-frame limit, and prepares the already sampled frames through V2'sprepare_video. Every supplied frame is kept in order and gets the video token budget instead of the image budget. If its prepared canvas exceeds the loaded projector's--embd-image-max-tokenscapacity, preparation refuses it before GPU dispatch. The video rule does not enlarge the tower or its named reserve.crates/serve/src/{media.rs,embeddings.rs}). When the first part is the model's prefix,embeddings::inputsends the remaining parts to the crate-privatemedia::prepare_video. That function checks the frame count before it decodes anything. It loads each file through the existing data URL loader and image keys, then decodes, prepares and drops its full-resolution RGB frame before loading the next file. Image and video inputs share this lifetime through the privateprepare_withhelper. Only prepared feeds accumulate between frames. The existingassemblestill places the delimiters, the spans and one BOS/EOS pair, and checks the context bound. Image requests without the prefix keep the image budget. Text after the prefix, an empty frame list, a 33rd frame and a projector without a video rule fail by name.input_videoorvideo_urlpart now returns a named 400 error that says to send decoded one-FPSimage_urlframes after aVideo:text part. The section "Out of scope" below explains why.crates/gpu-gates/src/bin/gate_gemma_embedding2_serve.rs). A new--video-clips <clips.json>mode on the existing serve gate reads the manifest and reference pairs that V2'svideo_oracle.pywrites. Before starting the server, it checks the loaded projector's SHA256 against the reference set's pinned value. It checks each frame's path and SHA256 against both reference sets before sending the content array through the real HTTP server, and compares prompt positions and the raw and normalized vectors with the unchanged bands derived from the CPU twin. It launches the server with an image minimum of 1 token while video preparation keeps its fixed minimum of 70, so image fallback cannot preserve the oracle prompt counts. It then checks that both encoded part types get the 400 refusal and the diagnostic that asks for decoded one-FPS frames. The mode reuses the gate's server launch and stop, HTTP client, reference reader and band rule. Thejustfilerecipe now forwards extra arguments to the gate. The existing--v1and default text modes remain in the same gate, sharing the launch and comparison helpers. Both text modes check fixture lengths and digests through the existing tokenizer-set reader before starting a plan or server. Combining--v1with--video-clipsis refused because v1 is text-only.tools/ref/emb2/README.md). A new section gives the request shape, the source citations, the gate command and the out-of-scope note.Code shape
prepare_videois the one place that turns sampled frames into feeds.Video:prefix, the frame limit, the call to the existingprepare_videoand a check against the loaded projector's token capacity. The commonMediaModeltrait gained a capability with a refusing default; no common owner gained a per-model branch.unsafeblock was added.cargo clippyand the security scan were not run. The fullcontrib-check --tier t0run includes formatting, pure-crate tests and comment checks.Duplication found or removed: image and video decoding share
crates/serve/src/media.rs:464, the privateprepare_withhelper. Their model-specific preparation rules remain separate.What I ran
The full CPU suites below use
4ecd4197, based once96affc. File-identity and HTTP-routing regression checks used6ce8fb5on that base. After rebasing onto416e4f3f, the rebuilt serve gate runs all three modes at681d034bon the DGX Spark andd80e036don the RTX 5090. Those two heads differ only in README wording. The oracle comparison tables retain the measured results at4ecd4197: frame preparation and inference math are unchanged.d35786a0acargo build -p bloomery-serve --bin bloomery-serve, thencargo test -p bloomery-serve --lib(Linux x86_64)cargo test -p bloomery-vision --lib(Linux x86_64)d80e036dcargo test -p bloomery-vision --lib videoatd80e036dpython3 tools/recipes.py --self-testbash tools/check-recipes.sh(Linux x86_64)just contrib-check --tier t0The integration test checks both sides of the loaded-capacity boundary: a 2x1 frame takes 72 rows and fails at capacities 4, 70 and 71, then passes at 72, 73 and 140. A 576x576 frame takes 121 rows and fails at 120, then passes at 121 and 122. It also covers two distinct frames' pixels, spans and corresponding image keys, BOS/EOS, the exact context limit, 1, 32 and 33 frames, an empty or malformed video, a missing projector and both named encoded-part diagnostics.
The regression input puts a valid PNG before a truncated JPEG. With a projector too small for the first frame, preparation must return its capacity error before decoding the JPEG. The all-frames-first implementation returns the later decode error and fails the assertion. The fixed implementation returns the first frame's error.
The file-identity regression uses a copy of the pinned projector with one byte appended after its tensors. At
d6ce8fb5, removing the new digest guard lets all video comparisons pass with that copy. Restoring the guard rejects it withvideo projector sha256 differs from the oraclebefore the server starts. Changing one byte in a text fixture, without changing its length, also fails before a plan or server starts in both text modes. Appending a byte to a copied PNG also fails its frame identity check; restoring the bytes makes the video gate pass.Disabling
embeddings::input's video selection makes the HTTP gate fail: its first clip reportsframes 1 positions 22instead of the oracle's 87 positions. The gate keeps--embd-image-min-tokens 1for this check. Restoring video selection makes all six vector comparisons and both named refusals pass.Not run here
The other pure-crate suites,
contrib-check --tier t0and the separate HTTP capacity and large-frame sweep have not been rerun on this head.Serve gate on a DGX Spark and an RTX 5090
Set
ARCH=sm_121on the DGX Spark andARCH=sm_86on the RTX 5090. The comparison tables retain the three CUDA and CPU-twin reference pairs collected on each card at56c32865and compared at4ecd4197. Their inputs, preparation rules and inference math are unchanged. The rebased runs rebuild the gate and run its existing--v1, default text and video modes on both cards. On the DGX Spark used for these runs, the pinned oracle pairs were prepared locally before the gate because the earlier assets were not present. The RTX 5090 reuses its retained pairs.DGX Spark:
bloomery-serveandgate_gemma_embedding2_servecargo oxide build --arch sm_121)input_videopartcheck input_video_refused: PASSvideo_urlpartcheck video_url_refused: PASS--v1mode--video-clipsmodeRTX 5090:
bloomery-serveandgate_gemma_embedding2_servecargo oxide build --arch sm_86)input_videopartcheck input_video_refused: PASSvideo_urlpartcheck video_url_refused: PASS--v1mode--video-clipsmodeThe gate kills its own server when it finishes, so the log line
video server stopped signal: 9 (SIGKILL)is expected.Comparison with the reference
The reference is mainline llama.cpp
6868a52cb337450658006ad2f9281c2eb63f1666,llama-server /v1/embeddings, built with CUDA on each card. Each comparison uses the references collected on that same card. The model isembeddinggemma-2-Q8_0.gguf(SHA2562188ac1deca4b77dffefd603c2776a9d76d9d74ec01841392982ebb840b09135) with the BF16 projectormmproj-embeddinggemma-2-BF16.gguf(SHA256d2033b3cd0223cfb2e7a2b50dc80a664c78c816d375f5b017ec3ef80ee0bc766). The flags are--embeddings --pooling mean -c 8192 -b 8192 -ub 8192 -np 1 -t 8 --image-max-tokens 140 --video-fps 1 --video-timestamp-interval 0, with-ngl 99for CUDA and-ngl 0for the CPU twin. Both servers and Bloomery got the same content array for each clip."raw" is the pooled vector and "embd" the L2-normalized one. Each band comes from the distance between the CUDA and CPU-twin references, by the gate's existing rule.
DGX Spark
[derived] DGX Spark minimum cosine-band margin across six comparisons: 8.01754180e-04. No band changed.
RTX 5090
[derived] RTX 5090 minimum cosine-band margin across six comparisons: 7.93680380e-04. No band changed.
The frame and position counts in the table are also the ones both reference sets record for llama-server; the gate requires that match. The PR makes no speed claim.
Out of scope
Encoded video parts (
input_videoandvideo_urlholding an MP4 or other container) get the named 400 error. Mainline llama-server accepts them with adataorurlfield (server-common.cpp:1228-1242) and decodes them by starting an FFmpeg subprocess (mtmd_helper_video::start_ffmpegintools/mtmd/mtmd-helper.cpp). Bloomery does not install or start a decoder. Does the maintainer want an FFmpeg subprocess on the server path for these parts? Until that is decided, this PR accepts sampled frames only and refuses encoded parts.Hardware (if the change is for a machine)
DGX Spark:
NVIDIA GB10, 595.84, CUDA 13.3.1 in the build container. The gate was built forsm_121.RTX 5090:
NVIDIA GeForce RTX 5090, 595.99.02, 32607 MiB, 400 W cap. The gate was built forsm_86.What I ran into
None of this blocks the PR.
gemma4v::prepare_clip.AI help
AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.