Skip to content

vision, refset, gpu-gates, tools: EmbeddingGemma 2 ordered decoded video frames through the Gemma4 vision tower - #374

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

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

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

Part of #59 (plan and PR order in #190), item V1: video input for EmbeddingGemma 2 as an ordered list of decoded RGB frames. It builds on E7, which is on main, and has one commit.

What and why

Release notes: internal: the Gemma4 vision tower and the EmbeddingGemma 2 end-to-end gate take 1 to 32 decoded video frames in order. This is the frame interface only; HTTP video input, frame sampling and timestamps are not part of it.

EmbeddingGemma 2 embeds text and images into one vector space, and mainline llama.cpp also accepts video as a series of frames. This PR adds that case without a decoder: the caller hands over frames that are already decoded, and the tower treats each one like an E7 image.

  • Preprocessing (crates/vision/src/arch/gemma4v/{media.rs,mod.rs}). One function prepares 1 to 32 frames in order. Each frame uses E7's aspect-preserving canvas with the dynamic 70 to 140 token budget. An empty list, a 33rd frame and a canvas over the budget are named errors.
  • The gate (crates/gpu-gates/src/bin/gate_gemma_embedding2_e2e.rs). It runs the one tower on every frame and puts all spans into one encoder run. It checks frame digests, order, counts, positions, raw pooling and normalization against the video reference. Image and video vectors share the same pooled-vector comparison.
  • Reference sets (crates/refset/src/arch/gemma_embedding2/{mod.rs,tests.rs,video-frames.txt}). The family owns the video set names and the six-frame sequence, and the existing family validator covers them.
  • Reference tools (tools/ref/emb2/{emb2.sh,server_vectors.py,README.md}, tools/ref/models/gemma-embedding2.sh). They build the ordered video request and its CPU twin with the checkpoint's default video flags, without a decoder.

Memory

Video uses the existing embedding model named reserve, which stays bloomery_gpu_gemma_embedding2::card_bytes(text, ctx) + projector.card.total() bytes. One tower's activation buffers are reused for every frame, and the context figure already covers the combined run. So video adds no device bytes at the same configured limits. That is a statement about how the bytes are counted, not a measured peak. The projected BF16 rows on the host take 2 * text_width * sum(frame_tokens) bytes, at most 8,960 * text_width for 32 frames of 140 tokens. tools/ref/emb2/README.md now states this accounting. No new reserve or placement owner was added.

Code shape

  • No second copy. The frame preparer calls E7's Media::prepare, SizeRule, preprocess and assemble, and its spans go through gpu::media::check_spans. The gate's image and video paths share one pooled comparison, and the shell's share one image_inputs. The ordered fixture list lives in refset::arch::gemma_embedding2, and the shell reads it from there.
  • Model code holds only architecture facts. The frame limit and canvas rule sit in the Gemma4 vision files. No common owner gained a per-model branch.
  • Dead code is gone. The former inline copies in the gate and the shell are removed, and nothing unused was added.
  • No silent failure. The frame count limit, the reference identities, the frame count and the position count 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 fmt and cargo clippy were not run on this head. No Mac static check, comment lint or security scan ran for it either.

Duplication found or removed: none beyond the inline copies of the image comparison and the image inputs, now pooled and image_inputs.

What I ran

The branch is one commit on main c53c26be. Each row names the head it ran on. Evidence logs are kept with the run; the working heads before the final rebase were 2f7127dc and f6d574b8.

Check Head Result
Range-diff of the rebase onto main c53c26be 975a8c72 one commit, unchanged (=)
python3 tools/recipes.py check 2f7127dc passed
bloomery-vision and bloomery-refset tests after restoring the mutations 2f7127dc 2 passed and 6 passed
just gate-gpu-gemma-embedding2-e2e recipe f6d574b8 rc 0; its unit runs passed 6, 1 and 2 tests; 88 text cases, image inputs and both video vectors checked
just affected with --no-box, after the metadata negatives f6d574b8 rc 0; the GPU application list was empty
Fresh cargo oxide build --arch sm_121 -- -p bloomery-gpu-gates --features gemma-embedding2,vision,deepseek41 --release --bin gate_gemma_embedding2_e2e, then the whole e2e binary 975a8c72 rc 0; both video comparisons passed

The first just affected run lacked --no-box and the first metadata check called the GPU wrapper without the local card setup. Both were command errors, fixed and rerun as listed. I did not run the full contrib-check tier here.

FAIL-first: eight edits, each caught by the check that guards it. The task's source edits were restored before the final run.

Protected contract Edit What caught it
Frame order Reverse the frame iterator The per-frame canvas equality assertion failed
Inclusive 32-frame limit Change > to >= The exact-limit success assertion failed
Nonempty list Remove the empty-input guard The empty-input refusal assertion failed
Video token budget Use 1120 instead of 140 The aligned-canvas equality assertion failed
CUDA video family kind Kind::Server to Kind::Text each_family_takes_a_set_of_its_kind failed
CPU video family kind Kind::ServerCpu to Kind::TextCpu The same test failed
Frame identity and order Swap the first two frame paths and digests in a copy of both manifests The e2e binary ended with video frame 0: expected small-200x200's bytes
Reference count Change frames 6 to frames 5 in a copy The e2e binary ended with video frame count or position count differs from reference

Comparison with the reference

The reference is mainline llama.cpp 6868a52cb337450658006ad2f9281c2eb63f1666, llama-server /v1/embeddings. The model is embeddinggemma-2-Q8_0.gguf (SHA256 2188ac1deca4b77dffefd603c2776a9d76d9d74ec01841392982ebb840b09135) with the BF16 projector mmproj-embeddinggemma-2-BF16.gguf (SHA256 d2033b3cd0223cfb2e7a2b50dc80a664c78c816d375f5b017ec3ef80ee0bc766). The input is six decoded frames in video-frames.txt order, 641 assembled prompt positions, with --image-max-tokens 140 --video-fps 1 --video-timestamp-interval 0. Gates and bands are unchanged.

Vector Relative difference to llama.cpp CPU twin distance Allowed difference (2.5 x twin) Result
raw 1.299214041e-2 1.046511665e-2 2.616279163e-2 PASS
embd 1.280530432e-2 9.910905901e-3 2.477726475e-2 PASS

For six ordered frames and 641 prompt positions, the relative differences to llama.cpp were 1.299214041e-2 (raw) and 1.280530432e-2 (normalized). Both were below 2.5 times the CPU twin distance. The PR makes no speed claim, so there is no timing comparison.

Part of the reference data came from E7's data root: the tokenizer, text twins, BF16 tower twins and the CUDA server set. The CPU server set and both video sets were generated fresh with just build-emb2-ref and just dump-ref-emb2 video server.cpu video.cpu against a llama.cpp checkout at 6868a52cb.

Hardware (if the change is for a machine)

DGX Spark: NVIDIA GB10, driver 595.84, dev container with CUDA 13 and --arch sm_121. Only this machine ran the checks. The RTX 5090 was not used because V1 changes no kernel and no device arithmetic.

What I ran into

None of this blocks the PR.

  • A first oracle candidate lacked the source corpus directory and an older reference directory used a Q8_0 projector. I used neither as evidence.
  • Two supplemental commands ended in setup errors: just affected tried SSH from the container, and a direct GPU wrapper call lacked the local card setup. Both were rerun correctly, as listed above.

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 findings remain after validation.

Checked

Duplicates: 13 new definitions checked; no actionable duplicate. Dryer reported 0 pairs in refset/vision; it excluded gpu-gates, whose additions were checked by Grep.
Complexity: video is new at 17. Its separable stages are reference identity/count validation and encoding/comparison; the branches reject invalid references.
Silent failure: 6 refusal paths followed through frame preparation, identities, metadata, tower and encoder errors; callers receive a named error and the gate exits FAIL.
Tests: mutation review of crates/vision/src/arch/gemma4v/media.rs:60: changing > to >= fails the 32-frame assertion; removing the empty guard fails refusal; reversing iteration at line 73 fails canvas/pixel equality; replacing 140 with 1120 at line 71 fails canvas equality. Changing either new family's kind fails each_family_takes_a_set_of_its_kind.
Gates: no bands or pins moved. The PR reports FAIL-first runs for frame order, bounds, budget, family kinds, frame identities and reference counts.
Adversarial checks: malformed RGB, excess context, reordered references and a failed reference writer are blocked by existing checks and propagated exit codes.
Performance: no engine dispatch or kernel changed; added frame work is preprocessing and gate execution.
Escape catalog: no new C1–C4 match.

Notes

GPU evidence is incomplete: the PR gives a GB10/driver description and result tables, but no nvidia-smi line or complete just gate-* command output. Attach those with the tested base/head hashes.
Local verification: changed shell syntax and Python parsing passed. Rust tests and GPU gates were not run during validation.

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.

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