Repository navigation
serve: embed decoded f32 PCM audio with the Gemma4a side tower - #405
Conversation
The audio tower sits behind Embed: Send, but storing FaultSink keeps a raw pointer in its persistent state. Keep only the owned fault allocation and derive a sink at each launch, as ElemKernels does. Reuse the existing checked sink_over constructor across the crate boundary without adding an unsafe Send implementation.
There was a problem hiding this comment.
Verdict: CLEAN: The checked failure paths are blocked by request validation, span checks and fault propagation.
Optimization headroom
- E. Less work: crates/gpu-gemma4a/src/arch/gemma4a/mod.rs:323, format block labels only when taps are enabled. With taps disabled, this removes 12 String allocations per chunk, or 12/n per audio position for n positions [derived], without adding an abstraction.
Checked
Duplicates: 35 new or relocated declarations grepped, plus changed generic APIs; no duplicated owner. Dryer reported 0 pairs; gpu-gates was excluded and checked manually.
Complexity: audio_run 72 is a new multi-stage gate; embeddings::input 17→30 adds PCM validation; Model::embed_media 3→13 adds audio assembly; gate::run 87→94 adds selectors; Model::open 15→21 adds tower loading; Flags::read 23→27 adds sizing; image assembly test 12→17 adds mixed orders. Encoder::run 56→57 and Weights::load 37→38 add validation branches.
Silent failure: 3 default/skip sites followed. Empty optional spans produce a text pass; the feature-disabled byte stub reaches the encoder refusal; skipped non-audio headers still require audio cases.
Tests: static mutation checks only for Rust. At crates/serve/src/embeddings.rs:323, accepting the wrong rate fails audio refusal assertions; swapping span destinations fails the mixed-order assertions.
At crates/gpu-gemma-embedding2/src/pass.rs:469, narrowing f32 rows to bf16 fails the exact input-row assertion.
At crates/gpu-gemma4a/src/arch/gemma4a/mod.rs:196, deleting the span guard fails gate_gemma4a's malformed-mel assertion.
At crates/vision/src/arch/mod.rs:100, dropping audio dispatch fails the projector assertions.
At crates/gpu-gemma4a/src/ops.rs:239, directing faults to another allocation fails both hardware fault assertions.
At crates/gpu-gates/src/side_seat/gemma_embedding2.rs:216, dropping media replacement fails audio oracle and content-change checks. Image/video assembly retains vector and prompt-count checks. In-memory Python checks passed for WAV headers, exact PCM transport and text ordering.
Gates: no band moved or case removed; the unsafe-count increase has a dated PIN and reason.
Escape catalog: C1–C4 do not match.
Notes
Rust tests and hardware gates were not run here. The PR supplies hardware summaries, but no required nvidia-smi line or gate command transcript; GPU evidence is incomplete.
Card check: needs-gpu. This pull request changes crates/gpu-gates/Cargo.toml, crates/gpu-gates/src/arch/embedding.rs, crates/gpu-gates/src/bin/gate_gemma4a.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)
|
The review is done and the contribution check passed, so I'm merging this. |
Part of #59 (plan and PR order in #190), E11: the EmbeddingGemma 2 side seat embeds decoded audio through the Gemma4a tower from #375. Each input can contain audio and text parts; images and audio retain their order in the same prompt.
What and why
The embeddings endpoints accept base64 little-endian f32 PCM with
format: "f32",sample_rate: 16000andchannels: 1. The server preprocesses it with the existing Gemma4a mel frontend, inserts its delimiters and pooled positions, and keeps the tower's f32 rows through the shared embedding encoder. Encoded audio, other rates and channel counts, invalid sample bytes and non-finite samples receive named request errors.The audio tower shares the side seat's named reserve with the text encoder and image projector. BF16 image rows still widen directly into the final input buffer. The loaded audio input rule shares one preprocessor across requests. The existing
MediaModelandTowerinterfaces carry audio preparation and encoding, while the architecture dispatch owns the concrete types and reserve sizing. The EmbeddingGemma v1 selector, decoded-video preparation and layer-replay path from the base are preserved.The audio operations retain the runtime's fault allocation and construct each launch sink through the existing unsafe constructor. Its lifetime, context and layer requirements remain explicit at the call site; the raw sink is not stored or made
Send.The serving guide now describes the loaded Gemma4a audio tower and its contribution to the side seat byte count and reserve. The shared input assembler takes caller-selected media delimiters, position counts and an error label. Image, audio and the end-to-end gate's video frames use that representation.
Release notes: Added: EmbeddingGemma 2 embeddings from decoded mono 16 kHz f32 PCM audio.
Code shape
cargo clippyand the security scan remain separate checks.Duplication found or removed: the BF16 and f32 entry points use one
pass_innerbody, including the base's replay validation. Media constructors supply their delimiters and prepared position counts to one assembly arm. Audio and video selectors share the projector digest check before either launches a server. Text fixtures use the existing tokenizer-set identity reader.What I ran
The card checks ran on head
d83144dc79b7fa24623513985dea7ec68b7b8f10, based onfe91abceb. Both device-linked builds usedcargo oxide; all four serve modes passed on each card. The final head66a7cda6changes the tower documentation and generated gate table and includes an unrelated upstream recipe fix. Its Rust executable code is identical to the tested head.--v1PASSPASSPASSPASS--video-clipsPASSPASS--audio, including named reserve and encoded-audio refusalPASSPASSPASSPASSPASSPASSPASSPASSCPU tests on
66a7cda6passed:bloomery-serve --lib, 235 passed;bloomery-vision --lib, 152 passed;bloomery-refset --lib, 224 passed and 3 ignored.The fault API and prefix-validation code are unchanged. Host probes rejected a wrong audio dispatcher and an empty-PCM substitution; the restored tests passed. Prefix assembly rejected all six malformed non-null types.
just gate-gpu-gemma-embedding2-serveruns text mode and then audio mode by default. Explicit selectors run one mode; these card runs invoked each selector directly throughtools/gpu-gate.sh. The mixed-media clauses check full-width vectors, deterministic replay and the sum of the single-part prompt counts with the duplicated input boundary removed. Changing only image pixels or only PCM samples must change the vector without changing the prompt count. These checks do not claim mixed-media closeness to llama.cpp.bash tools/check-arch.sh:check-arch: ok.python3 tools/recipes.py check: 134 gate rows held to the derivation. Fulljust contrib-check --tier t0was not run in this round.just canon-check 6eee0497(no-JIT PTX scans of the three serve binaries): 891 of 899 kernel entries are identical and none differ. The eight head-only entries are inbloomery-serve-ds41:accumulate,channel_norm,conv2d,depthwise,glu,local_attention,pointwiseandunary. They are the existing Gemma4a audio tower kernels, linked now because the embedding side seat can load the audio tower, so the recipe returns 1 by design.Reproduction commands:
Use
sm_121for the DGX Spark build andsm_120for the RTX 5090 build. SetBLOOMERY_REF_MODELto the existing Qwen3-30B-A3B-Instruct-2507 Q4_K_M chat model. The serve gate also needs the pinned embedding model and projector, the mainline GPU and CPU reference sets, and the video mode's selected-frame manifest.Comparison with the reference
The oracle is mainline llama.cpp
6868a52cb337450658006ad2f9281c2eb63f1666, runningllama-serverwith embeddings, mean pooling and context and batch sizes of 8192. The model isembeddinggemma-2-Q8_0.gguf(SHA2562188ac1deca4b77dffefd603c2776a9d76d9d74ec01841392982ebb840b09135) withmmproj-embeddinggemma-2-BF16.gguf(SHA256d2033b3cd0223cfb2e7a2b50dc80a664c78c816d375f5b017ec3ef80ee0bc766). The reference sets retain this pin; the comparisons below rerun the branch against those saved vectors.The five synthetic PCM inputs cover the two-sample minimum, a one-second sine, two seconds of silence, and sample counts on either side of the 30-second chunk boundary. Each runs alone and with text, with raw and normalized vectors, giving 20 comparisons per card. Each card's existing CPU twin determines the unchanged serving error band.
All 40 comparisons passed with matching prompt counts. Both mixed-media orders passed replay, prompt-count, image-content and audio-content checks on both cards; their oracle distances were not measured. No tolerance changed.
Hardware (if the change is for a machine)
sm_121build.sm_120build.What I ran into
None of this blocks the PR.
--release; building it first resolved the missing executable. The serve gates also need an explicit chat-model path. The successful runs supplied both prerequisites.AI help
AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.