Skip to content

gpu-gemma4a: the audio Conformer tower and its mainline gate - #375

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

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

Conversation

@juliankang4

@juliankang4 juliankang4 commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

Part of #59 (plan and PR order in #190), E10: the Gemma4 audio Conformer tower of EmbeddingGemma 2 on the GPU, checked against mainline llama.cpp. It takes the mel input prepared by E9 (#331) and returns soft embedding rows. E11 will connect it to the embedding seat. Nothing in the server calls this tower yet.

What and why

Release notes: Added: the GPU audio tower and its reference gate for EmbeddingGemma 2.

This adds bloomery-gpu-gemma4a and gate_gemma4a. The gate compares each tower stage with mainline llama.cpp at 6868a52cb337450658006ad2f9281c2eb63f1666, using its GPU output and CPU twin. Audio decoding, resampling, delimiter tokens and pooling with the text encoder stay in E11.

The tower uses two stride-2 convolutions, twelve Conformer blocks and the output projections. Each chunk takes 1 to 2999 mel frames and produces token-major F32 soft rows, with no state between chunks. GEMM and RMSNorm use the existing shared kernels. The new kernels implement convolution, channel normalization, GLU, causal depthwise convolution and local attention; the crate does not depend on gpu-vision.

BF16 matrices widen exactly to F32 and GEMM inputs round to BF16. Convolution operands follow mainline's F16 im2col rule. The GGUF's conv_norm and norm_conv names are swapped as in the reference; missing K gain and soft embedding gain mean unit gain, and a missing bias means zero. A present tensor with the wrong shape is an error.

Non-finite input, weights, clamps and results are named errors. Normalization, attention softcap and GLU raise the existing fault word before an overflow can become a plausible finite output. The caller owns that word; it is not charged to the tower again.

The measured reserve is 1,347,032,320 bytes: 1,222,510,336 for weights and 124,521,984 for scratch. The gate holds it to the existing Beside.image reserve. This PR adds no reserve tag and changes no serving plan.

Code shape

  • No second copy. GEMM, RMSNorm, GGUF dequantization, shaped upload and window helpers retain their existing owners. Vision's LayerNorm writes BF16; this path requires F32.
  • Model code holds only architecture facts. Tensor names, shapes, clamps, block order and attention rules are in src/arch/gemma4a/.
  • Dead code is gone. No unused path is retained.
  • No silent failure. Invalid input is a named error; oracle generation stops before publication on failure.
  • Comments state what is true now. The rebased head's check results are pending.
  • No relaxed gate. The relative and scaled absolute bands use the existing E3 rule, max(0.01, 2.5 * CPU-twin distance).
  • Format, Clippy and lint count: not run on the rebased head yet.

Duplication found or removed: none.

Comparison with the reference

These results were measured on head c8b204de28f6e3af3dd6ffba99ef6b74b410805b, base 402f9abc6e3062ae0de0cc2ac3a86a2cf09c8c90, on DGX Spark. The current head is 240829386cb95182b22b33927108003aa4fe9cfb, based on c14c46115ae487b3472e6c8ce80d2d109fd599bb. The rebase retained an identical contribution patch; only upstream's draft-path resolution in crates/refset/src/arch/draft.rs changed. The results below are retained measurements, not new runs on the rebased head.

The oracle is mainline llama.cpp at 6868a52cb337450658006ad2f9281c2eb63f1666, with the BF16 projector identified below. Each row compares the final soft rows with the GPU dump; the bands use that run's CPU twin.

Case Relative L2 Band Max absolute difference Band
minimum/0 1.782423835e-3 1.000000000e-2 8.975386620e-3 4.690757275e-2
sine/0 3.176343372e-3 1.000000000e-2 2.919623256e-2 1.706565917e-1
silence/0 4.375617328e-2 7.394193322e-2 8.982608318e-1 1.585661471e0
before-30s/0 1.619112157e-2 4.004918707e-2 1.158083558e0 2.297249734e0
after-30s/0 1.619112157e-2 4.004918707e-2 1.158083558e0 2.297249734e0
after-30s/1 1.161049720e-3 1.000000000e-2 5.911648273e-3 4.852302551e-2

On DGX Spark (GB10, sm_121), all six audio cases are inside both bands, clean/tapped outputs are bit-identical, and the gate prints gemma4a tower PASS.

The largest relative L2 is 4.375617328e-2, for silence. This is a numerical comparison within the stated bands, not a throughput or bit-identical-to-mainline claim.

What I ran

All rows here ran on c8b204de and base 402f9abc with BLOOMERY_BOX_LOCAL=1, BLOOMERY_ARCH=sm_121 and the reference sets identified below. Each rc is the recipe's own exit code, not the surrounding collector's status.

Command Result
just gate-gpu-gemma4a rc 0; 4 crate tests passed; gemma4a tower PASS
BLOOMERY_MODEL=deepseek2 just gate-gpu-p4 rc 0; PASSED: elem kernels within their bands
BLOOMERY_MODEL=deepseek2 just gate-gpu-head rc 0; PASSED: gate_head_gpu
BLOOMERY_MODEL=deepseek2 just gate-gpu-hybrid rc 0; gate_hybrid: PASS, at both n_l=32 and n_l=0
BLOOMERY_MODEL=gemma-embedding2 just gate-gpu-gemma-embedding2-e2e rc 0; text, image, video, rerun and input refusal checks passed
bash tools/check-emb2.sh 14 tests, OK (skipped=1); the Linux audio-builder fixture ran
bash tools/ptx-compare.sh 402f9abc6e3062ae0de0cc2ac3a86a2cf09c8c90 gate_e2e expected rc 3; only rms_norm changed among 271 shared entries

The shared RMSNorm comparison has no added or removed entry; the other 270 entries are unchanged. Its instruction count changes from 182 to 208, while JIT registers remain 34, static shared memory remains 32 bytes, local memory remains zero and static blocks per SM remain 6. This replaces the earlier description that all shared kernels were identical.

The audio fixture now skips on non-Linux hosts or without sha256sum. A Linux-hosted fixture with mocked platform and utility discovery checked Darwin with and without the utility, and Linux without it: all three skip before invoking the builder. This is not a native macOS execution.

Not run on the rebased head: full t0, exact-head GPU compilation, Clippy and the changed upstream draft-path tests. No completed result for those checks is claimed here. The full t1 and just affected suite have not been run in this round.

Reference provenance and reproduction

The files came from pinned Hugging Face revisions:

Model file Repository revision SHA256
DeepSeek-V2-Lite-Chat.Q3_K_M.gguf mradermacher/DeepSeek-V2-Lite-Chat-GGUF@9ee9f1f8f39f673e1022e176d586aef4228f630d 642abebcf2f1efdb7a204759425865a1552b3120a9f6d3d82eb1adb8271d43fd
embeddinggemma-2-Q8_0.gguf ggml-org/embeddinggemma-2-GGUF@bfcd298762cc34d0357ece5ebdd31791a3a374d8 2188ac1deca4b77dffefd603c2776a9d76d9d74ec01841392982ebb840b09135
mmproj-embeddinggemma-2-BF16.gguf same EmbeddingGemma revision d2033b3cd0223cfb2e7a2b50dc80a664c78c816d375f5b017ec3ef80ee0bc766

The V2 oracle was built from an unmodified ikawrakow/ik_llama.cpp checkout at cea2d61ffdac38ee2958ba88d120fa07cb67703a, tree df84c06ae0212212d847877e6faf2c4244fbde3e. Its manifests declare build cea2d61f, arch deepseek2 and completion 1155 0. These V2 readers do not impose a separate family build pin.

The ik build used CUDA architecture 121a, GGML_NATIVE=OFF, -march=armv8.2-a+dotprod+fp16, GGML_IQK_MUL_MAT=ON and GGML_IQK_FLASH_ATTENTION=ON. Build tools were CMake 3.31.6 and Ninja 1.11.1.4 from isolated ARM64 wheels. The generated dump_ref binary has SHA256 110ade6ca99c48d3dae1e44e20c690d0c6e5acc89f6068d1d9cf8e502dd7b4b3; its libllama.so has SHA256 98a0c2e0f595c180a6ddbd2e3977747e10012c05740e17a16a51cff785a658cf.

EmbeddingGemma uses the clean mainline llama.cpp pin above. The current tooling rebuilt dump_emb2.cpp with set_writer.h against it; the generated binary has SHA256 6b16ed637cca8cb350b075cc7d3181010f337ecb5a3463c75d0774641d6e5919.

The repository's writers produced the shared-caller reference files. Hashes below identify the manifest bytes and the greedy TSV, not a digest of every payload file.

Reference file, relative to BLOOMERY_DATA SHA256
ref-tokenizer-gemma4/MANIFEST.tsv 4dff7c27cc535fe41b21ee34790f174c93cea35c8e0ca37a557bc04b4947cff4
ref/MANIFEST.tsv 144795fd865a9252385bd8b7278673f1c62e40bb1bd50eaa9a82d546e8cfe749
ref_cuda_v2/MANIFEST.tsv 2b224eac0aa94f9fe1536dd825ab6e99496d4ca2758e5af4be82bf3eab76ddc0
ref_gemma_embedding2_text/MANIFEST.tsv e63331c64a4e8879ad603bad106414d19ac98aced8c885887ed9cff69f7184fa
ref_gemma_embedding2_text.cpu/MANIFEST.tsv d7f20aefa78ceff92f8847b7f1cd31b2218b2aba0fb5824c163299f9fee6743d
ref_gemma_embedding2_tower/MANIFEST.tsv f9e6506ac2bffee336d625a9f40ee05b218e18c82a6dc61d80349c480705254b
ref_gemma_embedding2_tower.cpu/MANIFEST.tsv 1ff33734ddbb65910954d2b25aa5da0b85715cde73bb593c7f15f189c8e5d0fa
ref_gemma_embedding2_server/MANIFEST.tsv 3bc2c99b07233b81eb167102c45e38bd59f07af76b1c425b0cbe1bfce66dc1f7
ref_gemma_embedding2_server.cpu/MANIFEST.tsv 031c1af78e1228f849ef0dc36e89034c207ef7c27e003626b11a4c2386305d87
ref_gemma_embedding2_video/MANIFEST.tsv b0fdb94cc033321db55222f23d02212b57733792390c3437a16fc56f7c34bd72
ref_gemma_embedding2_video.cpu/MANIFEST.tsv 39b20c9f0766b9177a3cf8595440822ecb284c40a0aa2f35bb957e25a302292d
greedy-ik-cuda-32.tsv 056837b21e617e687a5bc892690b8a15fa9cd1b5aec998ef5e770e9428b1536c

Set IK to the pinned ik checkout, LCPP to the pinned mainline checkout, and BLOOMERY_DATA to the reference output directory. The model paths below are those recorded in the manifests.

export BLOOMERY_BOX_LOCAL=1 BLOOMERY_ARCH=sm_121
export BLOOMERY_MODEL=deepseek2
export BLOOMERY_REF_MODEL=/models/small/DeepSeek-V2-Lite-Chat.Q3_K_M.gguf
bash tools/ref/build-dump.sh
BLOOMERY_REF_BACKEND=cuda BLOOMERY_REF_SET=ref_cuda_v2 just dump-ref
just dump-ref
just build-argmax
just greedy-ref-cuda
just gate-gpu-p4
just gate-gpu-head
just gate-gpu-hybrid

export BLOOMERY_REF_MODEL=/models/embeddinggemma-2/embeddinggemma-2-Q8_0.gguf
BLOOMERY_MODEL=deepseek2 bash crates/tokenizer/tools/oracle.sh gemma4 --cases-only
just build-emb2-ref
just dump-ref-emb2 text tower server video text.cpu tower.cpu server.cpu video.cpu
export BLOOMERY_MODEL=gemma-embedding2
just gate-gpu-gemma-embedding2-e2e
just dump-ref-emb2-mel
just dump-ref-emb2-audio
just gate-gpu-gemma4a

What I ran into

None of this blocks the PR.

The first hybrid attempt lacked greedy-ik-cuda-32.tsv; main failed for the same missing file. Generating the CPU references and CUDA greedy file with the upstream recipes resolved it, and the complete hybrid recipe then returned rc 0. The first ik builds also failed because the default ARM target did not define DOTPROD; the explicit supported CPU flags above built without source patches.

I also tried skipping output-clamp launches with default bounds. Four alternating rounds per arm on c8b204de measured a duration change of -0.083245% [derived], below the experiment's 2.0% retention threshold. The trial was discarded; no speed change is included.

Hardware (if the change is for a machine)

DGX Spark, NVIDIA GB10, Linux aarch64, driver 595.84, CUDA 13.3.1 development container. Device gates used sm_121; the shared PTX scanner used sm_86 with GB10 JIT resource columns. The recorded idle nvidia-smi lines were:

| NVIDIA-SMI 595.84                 Driver Version: 595.84         CUDA Version: 13.3     |
|   0  NVIDIA GB10                    On  |   0000000F:01:00.0 Off |                  N/A |
| N/A   52C    P8              4W /  N/A  | Not Supported          |      0%      Default |
|  No running processes found                                                             |

AI help

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

@github-actions github-actions Bot added 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: MUST_FIX: the new audio builder fixture breaks the supported macOS t0 check.

Must fix

1. Skip the Linux audio fixture on unsupported hosts

tools/check-emb2.sh:233 calls self.fail when sha256sum is absent. On macOS without that utility, the fixture fails and check-emb2.sh exits nonzero. tools/contrib-check.sh:173–176 includes it in the any-OS t0 tier. Existing fixtures skip missing Linux utilities. Installing the checksum utility alone still leaves audio.sh dependent on Bash 4's mapfile and GNU mv -Tn.
Fixing the guard avoids imposing Linux tool prerequisites on t0 contributors. Replace lines 233–234:

        if sys.platform != "linux" or not shutil.which("sha256sum"):
            self.skipTest("audio builder fixture requires Linux and sha256sum")

Non-blocking

⚠ Validate existing RMSNorm callers: crates/gpu/src/elem.rs:1023 changes an existing kernel's fault behavior and adds a fault argument. Existing callers include hybrid.rs:447. Attach current-head owning-gate results for those callers and a PTX comparison accounting for the changed entry. The audio-family gate alone does not exercise those paths.

Optimization headroom

  • G, Per-launch and per-sync fixed cost: crates/gpu-gemma4a/src/arch/gemma4a/mod.rs:346, skip the output-clamp launch when both bounds are the defaults, [-f32::MAX, f32::MAX]. The unary kernel preserves non-finite inputs, so this operation is identity. Each affected GEMM saves one launch and 8 bytes of buffer reads/writes per output element [derived].

Checked

Duplicates: diagnostics report zero qualifying dryer pairs; gpu-gates was excluded from that scan.
Complexity: diagnostics flag new run (56), load (37), gate main (24), and two hardware tests (38 each).
Silent failure: clamp preserves non-finite values; the changed RMSNorm raises F32Product on an overflowing sum of squares.
Tests: static inspection confirms assertions for clamps, rounding and arithmetic faults. Removing the RMS finite guard defeats the overflow assertion. Embedded Python and the inline replacement parse; both suggested lines are added by the diff.
Gates: device tests were not executed during validation. The PR reports FAIL-first results.
Escape catalog: no C1–C4 pattern matched the cited paths.

Notes

The supplied device-gate run names 365312fb and lacks the required nvidia-smi output. CI runs t0 on Ubuntu, so it does not cover the macOS failure above.

Card check: needs-gpu. This pull request changes crates/gpu-gates/Cargo.toml, crates/gpu-gates/src/bin/gate_gemma4a.rs, crates/gpu/src/elem.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)

Filed outside this PR: #376

Comment thread tools/check-emb2.sh Outdated
Comment on lines +233 to +234
if not shutil.which("sha256sum"):
self.fail("sha256sum is required for the audio builder fixture")

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.

The any-OS t0 tier must skip this Linux fixture on non-Linux hosts and when sha256sum is missing.

Suggested change
if not shutil.which("sha256sum"):
self.fail("sha256sum is required for the audio builder fixture")
if sys.platform != "linux" or not shutil.which("sha256sum"):
self.skipTest("audio builder fixture requires Linux and sha256sum")

@juliankang4
juliankang4 force-pushed the dgx-spark-emb2-audio-tower branch from 52c3a17 to de8f644 Compare October 17, 2026 00:16
@juliankang4

Copy link
Copy Markdown
Collaborator Author

This addresses the change request in review 5553888281 and its inline suggestion. The fixes are in de8f644f5b7da4de966dfe9aa8f0c88a34131e5c, rebased onto c14c46115ae487b3472e6c8ce80d2d109fd599bb.

1. Linux audio-builder fixture in any-OS t0

Commit de8f644f makes Builders.test_audio_builds_clean_libraries_and_checks_the_mel_family skip before invoking the builder when the platform is not Linux or sha256sum is absent. This covers macOS even when a checksum utility happens to be installed; the fixture still exercises the real builder on supported Linux hosts.

The before/after fixture ran on Linux with platform and utility discovery mocked. On tested head c8b204de, Darwin with and without sha256sum, and Linux without it, each produced one skip with zero failures. The normal Linux run of bash tools/check-emb2.sh reported Ran 14 tests and OK (skipped=1); the audio builder itself ran. The remaining skip belongs to the existing linked-dumper option check. This is not a native macOS test result.

The rebase preserved the contribution's binary patch exactly. The branch is now one commit on 8171614c.

2. Shared RMSNorm callers and PTX comparison

Commit de8f644f retains the shared finite-sum guard and fault argument. The description now includes the owning-gate results for all four requested caller paths, measured on c8b204de against base 402f9abc on DGX Spark:

Command Final recipe rc and result
just gate-gpu-p4 0; PASSED: elem kernels within their bands
just gate-gpu-head 0; PASSED: gate_head_gpu
just gate-gpu-hybrid 0; gate_hybrid: PASS, both n_l=32 and n_l=0
just gate-gpu-gemma-embedding2-e2e 0; text, image, video, rerun and refusal checks passed

The first hybrid attempt lacked its greedy reference TSV. The same missing-file failure occurred on main. After generating the CPU references and the 33-prompt CUDA greedy TSV with the repository's recipes, the full hybrid gate returned rc 0. The description includes the ik source commit, build configuration, model digests and reference-manifest SHA256 values.

bash tools/ptx-compare.sh 402f9abc6e3062ae0de0cc2ac3a86a2cf09c8c90 gate_e2e returned the expected rc 3. Both scans contain 271 entries. Only rms_norm changed; no entry was added or removed, and the other 270 are unchanged. RMSNorm's instruction count moved from 182 to 208, with unchanged JIT registers (34), static shared bytes (32), local bytes (0) and static blocks per SM (6). The description no longer claims that every shared kernel is identical.

The scanner printed c8b204de+uncommitted because it emitted untracked intermediate IR and PTX files in the worktree root. Tracked source was clean before and after the comparison. These are retained earlier-head measurements, not fresh runs on de8f644f.

3. Default output-clamp launch trial

The suggested skip was tried on c8b204de, using the real projector and a 2999-frame mel chunk. Four alternating rounds per arm measured a duration change of -0.083245% [derived], below the experiment's 2.0% retention threshold. The trial was discarded. Commit de8f644f therefore keeps the existing output-clamp launches and makes no speedup claim.

4. Card evidence and tested revision

The description now names the tested head and base separately from the rebased head. It includes the recorded NVIDIA GB10 and driver 595.84 lines, CUDA 13.3.1, the model files and their digests, commands and recipe exit codes. The audio gate on c8b204de passed its four crate tests and all six audio cases, ending with gemma4a tower PASS.

The GB10 compilation check passed on de8f644f before the push.

AI help

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

@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 finding remains after validation.

Non-blocking

⚠ Complete the gate evidence: crates/gpu-gates/src/bin/gate_gemma4a.rs:58. The PR reports runs on c8b204de and provides no FAIL-first transcript for the new gate clauses, including numeric comparisons and overflow refusal.
Attach failing mutations and passing output, then rerun just gate-gpu-gemma4a and the affected shared-kernel gates on de8f644. This supplies the validation evidence required for the added tower and changed shared kernels.

Optimization headroom

  • E. Less work: crates/gpu-gemma4a/src/arch/gemma4a/mod.rs:216. The chunk encoding path projects fixed positions through fixed weights in every block. Replace each block's relative-position matrix with its derived projection at load, preserving BF16 rounding and clamps through the existing kernels. This removes 12 GEMMs and 24 pointwise/clamp launches per chunk: 36/n launches per soft token for n output tokens [derived].

Checked

Both cited lines are additions in the full diff. The gate contains numeric comparisons and malformed-input/overflow assertions. The loader fixes the tower at twelve blocks; each relative projection calls one GEMM and two pointwise kernels. Position inputs are independent of chunk length. Neither item meets the must-fix classification; the optimization remains advisory. The escape catalog and ledger do not alter either item. Validation was static; no GPU tests were run.

Card check: gpu-evidence. This pull request changes crates/gpu-gates/Cargo.toml, crates/gpu-gates/src/bin/gate_gemma4a.rs, crates/gpu/src/elem.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)

@github-actions github-actions Bot added gpu-evidence Verified on the author's card: the pull request carries the gate run and its output and removed needs-gpu Changes code a card must check, and carries no gate run on a card labels Oct 17, 2026
@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 34ce3d6 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

gpu The card engine: crates/gpu*, crates/app gpu-evidence Verified on the author's card: the pull request carries the gate run and its output host Host crates: qdot, threads, engram, engram-lab, runtime, sampler, levers, decision, vision, refset tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant