Skip to content

vision, gpu-gates, tools: EmbeddingGemma 2 video clips sampled at 1 FPS from decoded frames, checked against llama.cpp - #383

Merged
juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-emb2-video-contract
Oct 17, 2026
Merged

juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-emb2-video-contract

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

Part of #59 (plan and PR order in #190), item V2: which frames of a decoded video clip EmbeddingGemma 2 sees, and a check of that choice against llama.cpp. It builds on V1 (#374) and has one commit.

What and why

Release notes: internal: the Gemma4 vision path can pick the 1 FPS frames of a constant-rate decoded clip, and the EmbeddingGemma 2 end-to-end gate checks that choice and the resulting vectors on three clips against llama.cpp. HTTP video input and decoding are not part of it.

V1 took frames the caller had already chosen. llama.cpp starts from a whole clip and keeps one frame per second. If Bloomery picks different frames, the vectors differ even when the tower is right. This PR adds the pick and a way to compare it with the reference.

  • Sampler (crates/vision/src/arch/gemma4v/{media.rs,mod.rs}). prepare_clip takes the decoded RGB frames of a zero-origin constant-rate clip and a rational FPS, and keeps one frame per output second. It rounds to the nearest output tick, with the same end-of-clip rounding as FFmpeg n7.1, which the reference helper delegates to. It allows 1 to 32 output frames and names an invalid FPS, an empty clip and a 33rd output frame as errors. prepare_frames holds the preprocessing that prepare_clip and V1's prepare_video share. The 32-frame limit is Bloomery's own V1 interface limit; llama.cpp has no such cap.
  • The gate (crates/gpu-gates/src/bin/gate_gemma_embedding2_e2e.rs). The new --video-clips <clips.tsv> path checks each full RGB stream's size and digest, calls the production sampler, and compares the chosen indices, the PNG pixels, the frame count and the position count with the manifest. It rejects duplicate clip names and requires exactly one matching video record in each reference set. Then it runs the tower and the text encoder. This path and V1's share video_pass for span checks and pooling.
  • Fixtures and reference collector (tools/ref/emb2/{video_clips.py,video_oracle.py,README.md}). video_clips.py writes three RGB clips with different lengths, frame rates and aspect ratios, with expected indices derived from the FFmpeg source rule, not from the Bloomery sampler. video_oracle.py checks the llama.cpp pin and the model digests, then runs a CUDA server and a CPU twin one after the other for each clip. The CUDA card header comes from the CUDA driver's visible devices, so ordinal, UUID and MIG selections use the same device enumeration as the server. A missing or invalid model profile, a missing driver, a failed CUDA query or an empty visible set stops collection. The README states the constant-rate contract and the commands.

Code shape

  • No second copy. prepare_frames is the one owner of frame preprocessing for prepare_clip and prepare_video, and video_pass is the one owner of span and pooling checks for both gate paths. The collector reuses the existing model profile, server_vectors.py and the image comparison helper.
  • Model code holds only architecture facts. The sampler and the frame limit sit in the Gemma4 vision files. No common owner gained a per-model branch.
  • Dead code is gone. Nothing was left unused.
  • No silent failure. A bad FPS, an empty or over-long clip, a size or digest mismatch and a reference identity mismatch fail by name.
  • No relaxed gate. Bands, tolerances and pins are unchanged, and no unsafe block was added.
  • Comments state what is true now.
  • cargo clippy and the security scan were not run. The full contrib-check --tier t0 run includes formatting, pure-crate tests and comment checks.

Duplication removed: the clip gate now takes its per-frame token limit from gemma4v::VIDEO_TOKENS, which preprocessing also uses. Both video_pass callers use the fixed reference key owned by the helper.

What I ran

The focused regression exercises the current collector with a synthetic CUDA driver, writes its device header through the production manifest writer and reads it back. It also compiles and runs the production Rust video-header and clip-row validation blocks without the encoder or a GPU. The before/after cases use 42b3c982 and the source now committed at 0bf9f8cb.

Check Result
Focused device and input-record FAIL-first passed: hidden devices, extra video records in either twin, duplicate clip names and a failed profile load reproduce on the previous source and are rejected or corrected on the current source

The device cases cover an unset visibility mask, one and several visible devices, numeric ordering, full and partial UUIDs, MIG, an empty visible set and failed CUDA calls. These are synthetic driver responses, not a multi-GPU hardware test. The Rust cases cover missing, foreign, duplicate and malformed video records, wrong position counts, wrong image counts and invalid fixture rows.

CUDA checks on 0bf9f8cb

I collected new mainline CUDA and CPU-twin reference sets for all three clips with this head's collector, rebuilt the CUDA gate with the sampler mutant and with the restored source, and reran the Hugging Face distance calculation against those new CUDA vectors. Only the build cache, model files and isolated Hugging Face environment were reused.

Check Result
Fresh CUDA build of gate_gemma_embedding2_e2e with the sampler edited to take the wrong frame, then the gate on clip clip_1s24 rc 1: source indices [12], expected [11]
CUDA rebuild of gate_gemma_embedding2_e2e, then the gate on all three clips at 0bf9f8cb exit 0; each clip's indices, frames, positions and both vectors passed
just contrib-check --tier t0 on Linux at 0bf9f8cb DONE tier=t0 total=86 red=0 wall=431s

The edit that makes the first row fail changes (next - 1) to next in the production sampler. Pixel and position checks are in the gate, so one wrong index is enough to stop it.

Comparison with the reference

The reference is mainline llama.cpp 6868a52cb337450658006ad2f9281c2eb63f1666, llama-server /v1/embeddings, built with CUDA for architecture 120a. The model is embeddinggemma-2-Q8_0.gguf (SHA256 2188ac1deca4b77dffefd603c2776a9d76d9d74ec01841392982ebb840b09135) with the BF16 projector mmproj-embeddinggemma-2-BF16.gguf (SHA256 d2033b3cd0223cfb2e7a2b50dc80a664c78c816d375f5b017ec3ef80ee0bc766). 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. The CPU twin runs with CUDA_VISIBLE_DEVICES= and -ngl 0 --no-mmproj-offload. The gate band is unchanged: 2.5 times the CPU twin's relative L2 distance.

The table records the fresh CUDA/CPU oracle collection, Bloomery gate and Hugging Face run at 0bf9f8cb. "Mainline/Bloomery indices" is the shared choice. The indices are the FFmpeg-derived expectation that the gate checks Bloomery's sampler against. llama.cpp returns no list of its own chosen frames, so the vector match is what supports them. The last three columns show the Hugging Face processor, described below.

Hardware Clip FPS Mainline/Bloomery indices Positions / span length Raw relative L2 / band Normalized relative L2 / band HF indices HF positions HF normalized cosine distance / max absolute
RTX 5090 clip_1s24 24 [11] 87 / 81 1.599460971e-02 / 3.762677215e-02 1.546335462e-02 / 3.692642456e-02 [0] 127 2.876060962e-02 / 3.244494461e-02
RTX 5090 clip_7s30 30 [14, 44, 74, 104, 134, 164, 194] 557 / 77 1.210738632e-02 / 2.692416306e-02 1.199236052e-02 / 2.680730121e-02 [0, 30, 60, 90, 120, 150, 180] 900 2.050676818e-02 / 2.312617563e-02
RTX 5090 clip_16s24 24 [11, 35, 59, 83, 107, 131, 155, 179, 203, 227, 251, 275, 299, 323, 347, 371] 1268 / 77 7.857395879e-03 / 1.989552392e-02 7.803860034e-03 / 1.989520397e-02 [0, 24, 48, 72, 96, 120, 144, 168, 192, 216, 240, 264, 288, 312, 336, 360] 2052 2.200098378e-02 / 2.926287614e-02

All six vector comparisons are below the unchanged band.

[derived] Minimum band minus observed relative L2 across six comparisons: 1.203812804100e-02. HF distances are diagnostic only.

Clips 1, 7 and 16 seconds long have 87, 557 and 1268 prompt positions. Within a clip every frame takes the same number of positions (81 for the 1 second clip, 77 for the others). The first frame starts at position 4, and no timestamp or separator sits between frames. The PR makes no speed claim.

The Hugging Face columns are a distance record, not an acceptance criterion. They were measured with the google/embeddinggemma-2 checkpoint at revision 914f7f89142e33e77833254d9c9b90c3cef7303b and transformers 5.21.0.dev0 (source revision 551122ae8e709cc36a4f2b14900fac8964ef22df). The model ran in BF16 with eager attention and the prompt Video:<|video|>, with the real source FPS and duration. The output rows were mean pooled in float32 and L2 normalized. The distance is to the same llama.cpp CUDA vector. The Hugging Face processor picked frames 0, 30, 60 and so on where llama.cpp picked the nearest tick, and it also differs in resize and checkpoint precision, so I do not attribute the gap to one cause. Nothing in the gate depends on it.

Hardware (if the change is for a machine)

RTX 5090: NVIDIA GeForce RTX 5090, 595.99.02, 12.0, 32607 MiB, 400.00 W, compute capability 12.0, CUDA 13.0. The Bloomery gate was built through the pinned cuda-oxide path. No kernel and no device arithmetic changed, so I did not run a DGX Spark.

What I ran into

None of this blocks the PR.

  • The checks cover assembling decoded frames. I did not run HTTP video decoding or an FFmpeg FPS filter. The expected indices follow the FFmpeg n7.1 constant-rate rule that the llama.cpp helper delegates to, and the llama.cpp pin does not fix the decoder version. Variable-rate input, a first timestamp other than zero and other end-of-clip timestamps are not covered.
  • A 40-second clip is refused by Bloomery's 32-frame limit. That is a local refusal test, not a vector comparison with llama.cpp.
  • I did not rerun V1's six-frame end-to-end path in this round. The shared video_pass compiled and ran in the new path.
  • The text gate was not rerun. The current collector and complete clip gate ran on the RTX 5090; the full t0 tier ran on Linux. Clippy and the security scan remain outside these runs.

AI help

AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.

@github-actions github-actions Bot added documentation Improvements or additions to documentation gpu The card engine: crates/gpu*, crates/app host Host crates: qdot, threads, engram, engram-lab, runtime, sampler, levers, decision, vision, refset needs-gpu Changes code a card must check, and carries no gate run on a card tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo labels Oct 16, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: CLEAN: No must-fix defect was found in the sampler, gate, or collector.

Non-blocking

⚠ Verify reference sampling independently: tools/ref/emb2/video_oracle.py:110. The oracle receives PNGs already selected by video_clips.py. Its vector comparison cannot detect a different frame choice by llama.cpp's video helper. Record one run of the helper or its FFmpeg filter on the complete fixtures, with the executable version and selected indices, before these expectations become an established reference.

Checked

Duplicates: 7 new functions checked by purpose; no duplicate owner found. Dryer reported no vision pairs.
Complexity: clips is new at 41, combining fixture parsing/validation and encoding. run rose from 23 to 30 through argument parsing and clip dispatch.
Silent failure: 3 sites followed: the index clamp and two HTTP exception handlers. Sampling stays in bounds; unavailable servers reach startup errors or the readiness timeout.
Tests: Static mutation check: changing media.rs:88 from next - 1 to next would fail the index assertion at mod.rs:39. Removing EOF rounding's + num at media.rs:76 would fail the half-second acceptance assertion at mod.rs:60. The PR reports a GPU FAIL-first for the index mutant. Rust tests and GPU gates were not run during validation.
Gates: no existing band, pin, or test removed or relaxed; the new clip path has reported FAIL-first evidence.
Escape catalog: no C1–C4 pattern matched. No new unsafe block or engine hot-path change.

Notes

Dryer skipped gpu-gates; its changed code was checked manually with Grep.
GPU results are summarized, but the exact gate command and its output are absent. Attach that transcript with both tested commit hashes to complete the hardware evidence.

Card check: needs-gpu. This pull request changes crates/gpu-gates/src/bin/gate_gemma_embedding2_e2e.rs and carries no gate run on a card (CONTRIBUTING's evidence list); a maintainer adds gpu-verified after one.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

@juliankang4

Copy link
Copy Markdown
Collaborator Author

The review is done and the contribution check passed, so I'm merging this.

@juliankang4
juliankang4 merged commit 8171614 into midagedev:main Oct 17, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation gpu The card engine: crates/gpu*, crates/app gpu-verified host Host crates: qdot, threads, engram, engram-lab, runtime, sampler, levers, decision, vision, refset needs-gpu Changes code a card must check, and carries no gate run on a card tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants