Skip to content

serve: embed decoded f32 PCM audio with the Gemma4a side tower - #405

Merged
juliankang4 merged 3 commits into
midagedev:mainfrom
juliankang4:dgx-spark-emb2-audio-serve
Oct 17, 2026
Merged

juliankang4 merged 3 commits into
midagedev:mainfrom
juliankang4:dgx-spark-emb2-audio-serve

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

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: 16000 and channels: 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 MediaModel and Tower interfaces 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

  • No second copy. The existing Gemma4a preprocessor and tower own audio preparation and projection. Both media row types use the shared span validator and encoder pass body.
  • Model code holds only architecture facts. Gemma4a owns its delimiters, sample rate and chunking. The common span type gained a row-type parameter.
  • Dead code is gone. The raw sink field left the audio operations, and the image-only path has no intermediate f32 span buffer.
  • No silent failure. Malformed audio and non-string, non-null reference prefixes are refused before they can become accepted results.
  • Comments state what is true now.
  • No relaxed gate. No gate band or tolerance changed. The unsafe ratchet records the additional constructor call.
  • cargo clippy and the security scan remain separate checks.

Duplication found or removed: the BF16 and f32 entry points use one pass_inner body, 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 on fe91abceb. Both device-linked builds used cargo oxide; all four serve modes passed on each card. The final head 66a7cda6 changes the tower documentation and generated gate table and includes an unrelated upstream recipe fix. Its Rust executable code is identical to the tested head.

Check DGX Spark RTX 5090
EmbeddingGemma v1, --v1 122 clauses PASS 122 clauses PASS
EmbeddingGemma 2 text mode 188 clauses PASS 188 clauses PASS
Decoded video, --video-clips 8 clauses PASS 8 clauses PASS
Audio serve mode, --audio, including named reserve and encoded-audio refusal 30 clauses PASS 30 clauses PASS
Image-before-audio and audio-before-image vector replay and prompt counts Both orders PASS Both orders PASS
Changing only image pixels in each mixed-media order Both orders PASS Both orders PASS
Changing only PCM samples, with the same sample count, in each mixed-media order Both orders PASS Both orders PASS

CPU tests on 66a7cda6 passed: 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-serve runs text mode and then audio mode by default. Explicit selectors run one mode; these card runs invoked each selector directly through tools/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. Full just contrib-check --tier t0 was 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 in bloomery-serve-ds41: accumulate, channel_norm, conv2d, depthwise, glu, local_attention, pointwise and unary. 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:

cargo build -p bloomery-serve --bin bloomery-serve
cargo test --release -p bloomery-serve --lib
cargo test --release -p bloomery-vision --lib
cargo test --release -p bloomery-refset --lib
bash tools/check-arch.sh
cargo oxide build --arch sm_121 -- --release -p bloomery-gpu-gates --features glm5next,clef,vision,mimo2,gemma-embedding2 --bin bloomery-serve --bin gate_gemma_embedding2_serve
BLOOMERY_BOX_LOCAL=1 BLOOMERY_BOX_CARD=local BLOOMERY_GATE_CARD=any bash tools/gpu-gate.sh gate_gemma_embedding2_serve --v1
BLOOMERY_BOX_LOCAL=1 BLOOMERY_BOX_CARD=local BLOOMERY_GATE_CARD=any bash tools/gpu-gate.sh gate_gemma_embedding2_serve
BLOOMERY_BOX_LOCAL=1 BLOOMERY_BOX_CARD=local BLOOMERY_GATE_CARD=any bash tools/gpu-gate.sh gate_gemma_embedding2_serve --video-clips clips.json
BLOOMERY_BOX_LOCAL=1 BLOOMERY_BOX_CARD=local BLOOMERY_GATE_CARD=any bash tools/gpu-gate.sh gate_gemma_embedding2_serve --audio

Use sm_121 for the DGX Spark build and sm_120 for the RTX 5090 build. Set BLOOMERY_REF_MODEL to 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, running llama-server with embeddings, mean pooling and context and batch sizes of 8192. The model is embeddinggemma-2-Q8_0.gguf (SHA256 2188ac1deca4b77dffefd603c2776a9d76d9d74ec01841392982ebb840b09135) with mmproj-embeddinggemma-2-BF16.gguf (SHA256 d2033b3cd0223cfb2e7a2b50dc80a664c78c816d375f5b017ec3ef80ee0bc766). 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.

Card Passed comparisons Maximum normalized cosine distance [derived] Maximum normalized absolute difference [derived]
DGX Spark 20/20 1.300920e-03 6.613784e-03
RTX 5090 20/20 1.240758e-03 7.529493e-03

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)

  • DGX Spark: NVIDIA GB10, driver 595.84, sm_121 build.
  • RTX 5090 machine: NVIDIA GeForce RTX 5090, driver 595.99.02, sm_120 build.

What I ran into

None of this blocks the PR.

  • Library tests launch the debug mock-server binary even when the tests use --release; building it first resolved the missing executable. The serve gates also need an explicit chat-model path. The successful runs supplied both prerequisites.
  • The server expects decoded PCM and does not decode WAV, MP3 or other audio containers.
  • Throughput, concurrent audio/chat timing, stereo and resampled input, dimension cuts on audio, and mixed-media oracle distances were not measured.

AI help

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

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.
@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 serve The HTTP server: crates/serve tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo labels Oct 17, 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: 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)

@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 b1eea04 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 serve The HTTP server: crates/serve 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