Repository navigation
refset, tools: EmbeddingGemma 2's mainline oracle sets and their families - #260
Conversation
…fvis/set_writer.h The shared header owns the existing writer and id parsing. The dumper calls the moved parser with the same bytes; validation and messages keep their existing rules.
…d records its header The id files contain one unsigned decimal token per line. Reject signs, whitespace and embedded NUL bytes instead of accepting a numeric prefix. The build records set_writer_sha256, and clefvis refuses a binary whose record does not name this tree's header. Installed dump_mtmd binaries need one relink before the next dump. DUMP_TOOL names the including dumper.
…eir ids and their families The oracle is llama.cpp mainline at 6868a52cb, a pinned commit that holds the model's support (#30054, 4fbc76de) and the three later changes on its path: the no-cache attention KV pad to 256 that keeps the head-512 layers on CUDA flash attention (#30416, 358a420e), the pooled-embedding LM-head skip (#30445, cb55ffe6) and the t_embd expand removal (#30461, 9cf967a0). The tree is built by tools/ref/qvis/build-lcpp-qvis.sh, which now takes the targets, the CUDA architecture and the toolkit by environment and runs as the caller when not root (just build-emb2-lcpp). tools/ref/clefvis/ build-clefvis.sh links the seat's DUMPER (the new gemma-embedding2 row of profile.sh names tools/ref/emb2/dump_emb2.cpp), and every seat's .build record now also names the CUDA architectures, nvcc and its version and the cmake options of the tree's CMakeCache.txt (just build-emb2-ref). The text cases and their ids are the tokenizer oracle's: oracle.sh gains the gemma4 vocabulary (mainline's llama-tokenize with --no-escape, the profile's tree and file) and its own cases after the shared ones, crates/tokenizer/tests/cases-gemma4.txt: the EmbeddingGemma texts and the vocabulary's boundaries (literal U+2581, CRLF, invalid UTF-8, runs past the longest run token, U+00A0, U+3000, special-token edges, byte fallback). tools/ref/emb2/emb2.sh writes five sets (just dump-ref-emb2): the text cases' token rows, pooled vectors and layer taps, the gemma4v tower's taps and rows over the BF16 mmproj, each with a CPU twin, and llama-server's /v1/embeddings vectors. It checks the tree, the build record, the card and both files' sha256 before every step, runs the card steps through tools/gpu-gate.sh and the twins under the same bound, stages every set and replaces the old one only on success. refset::arch::gemma_embedding2 holds the five families, opened through Identity::Emb2, which checks the kind, the device and both files' sha256.
There was a problem hiding this comment.
Verdict: MUST_FIX: the change adds result fields and a profile alias with no consumers.
Must fix
1. Remove the unread result fields
crates/refset/src/emb2.rs:62: Emb2Set.kind and Emb2Set.card have no readers. The only caller, family.rs:378, consumes only man. These are unneeded public elements under R13 and the fewest-elements rule (kind B).
Remove them before callers depend on this unused API.
Keep the existing derive and replace the struct with:
pub struct Emb2Set {
pub man: RefManifest,
}In open, replace the device destructuring line with:
let [device, "threads", _, "card", _] = dev[..] else {Replace its final two statements with:
Ok(Emb2Set { man })2. Remove the unused profile alias
tools/ref/clefvis/profile.sh:137: neither build-clefvis.sh nor emb2.sh reads TEXT. The other sourcing script, clefvis.sh, rejects this seat before reading it. This assignment is an unneeded element (kind B).
Delete TEXT=$MODEL now, before it becomes a second name callers must maintain.
Non-blocking
⚠ Cover malformed token IDs: tools/ref/clefvis/set_writer.h:138. None of the new tests exercises parse_ids. Changing the end-pointer check back to *end != '\0' accepts an embedded NUL without failing those tests. Add assertions for signed, whitespace-prefixed and embedded-NUL IDs, including the file and line error, before these sets become gate inputs.
Checked
Consumers: searched the PR tree for Emb2Set and scripts sourcing the seat profile. The sole reader uses only man; none of the three profile consumers reads the emb2 TEXT assignment.
Tests: the five added Rust tests read manifests. The shell fixtures stub the dumper; the linked-dumper test checks only thread options. None exercises parse_ids. Suites were not rerun.
Validation: checked cited source lines, the mechanical fixes, the inline deletion's added-line placement, and unchanged base evidence for the issue candidate. The failed-status behavior was reproduced with shell stubs.
Escape catalog: C1–C4 consulted. No optimization headroom item was proposed.
Notes
The PR supplies the card line and gate summaries, but no explicit just gate-* command with its output. GPU evidence is marked false.
🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)
Filed outside this PR: #262
| # the model profile (models/gemma-embedding2.sh) names the files, their digests and the tree; the sets and their steps are | ||
| # emb2.sh's | ||
| FAMILY=emb2 SETPFX=ref_gemma_embedding2 ORACLE=$LCPP BIN=$BINDIR/dump_emb2 DUMPER=tools/ref/emb2/dump_emb2.cpp | ||
| TEXT=$MODEL |
There was a problem hiding this comment.
The emb2 build and dump paths never read TEXT; remove the unused alias.
| TEXT=$MODEL |
… names no TEXT, and the id reader has its own checks Emb2Set's kind and card had no reader, and nothing read the emb2 seat's TEXT. check-emb2.sh now builds set_writer.h's parse_ids alone and checks that signed, space-padded, NUL-holding, empty, out-of-range and hex lines die naming the file and line, and that digit lines are read.
|
Fixed in f81da60:
The non-blocking item is in the same commit: AI helpAI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다. |
There was a problem hiding this comment.
Since the last review:
- Fixed: unread
Emb2Set.kindandcardfields are removed from emb2.rs:60. - Fixed: the unused
TEXTalias is removed from profile.sh:136. - Fixed: check-emb2.sh:273 checks malformed IDs, including signs, whitespace and embedded NUL, with file and line diagnostics.
Verdict: CLEAN: the previous findings are resolved, and the increment preserves runtime validation.
Checked
Duplicates: the new C++ fixture calls the existing parse_ids owner and stubs four GGUF calls.
Complexity: this increment adds no production branches; kind and device validation remain in Emb2Set::open.
Silent failure: a missing compiler produces a named skip; an input file that cannot be opened returns 2 and fails the assertions.
Tests: by inspection, at set_writer.h:138, restoring *end != '\0' would fail the malformed-NUL assertion; changing v > INT32_MAX to v >= INT32_MAX would fail the valid-boundary assertion. Changed shell files and embedded Python pass syntax checks. Runtime suites were not rerun.
Gates: this increment changes no pins or gate clauses. The PR reports FAIL-first for the NUL regression.
Adversarial: malformed IDs fail before any IDs are printed. Kind/device rejection remains intact. The emb2 guard exits clefvis.sh before its first TEXT read.
Escape catalog: C1–C4 checked; no new matches. This increment touches tools and reference validation, with no inference hot path.
Notes
The PR supplies the card line and hashes, but omits explicit just gate-* commands with their output required for GPU evidence.
🔨 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), E3: the llama.cpp mainline reference sets that the encoder body, the image tower and the
/v1/embeddingsseat will be checked against, with the five refset families that open them.What and why
This is step 3 of
docs/contrib/new-model.md(refset family and its dump) for EmbeddingGemma 2. Nothing reads the sets yet: every family hasconsumers: &[](crates/refset/src/arch/gemma_embedding2/mod.rs:104), and the gates that read them come with the body, tower and seat PRs.Release notes: Added: the llama.cpp mainline reference sets for EmbeddingGemma 2 and the five refset families that open them; nothing reads them yet.
The oracle is llama.cpp mainline at
6868a52cb. It holds the model's support (#30054) and three later mainline changes on its path (#30416, #30445, #30461).The PR has five commits:
dump_mtmd.cpp's sha256, set writer and id reader move, unchanged, intotools/ref/clefvis/set_writer.h, so the new dumper shares them instead of copying them.strtolused to accept the numeric prefix. Each.buildrecord now names the sha256 ofset_writer.h, andclefvis.shrefuses adump_mtmdwhose record does not name this tree's header. So an installeddump_mtmdneeds one relink (build-clefvis.sh) before its next dump.tools/gate-paths.tsv's row forcrates/refset/src/emb2.rsalso namesgate-gpu-qwen35moe-mtp, a gate that main gained after the PR's first base, so the row covers every gate in the rebased tree.Emb2Setkeeps only its manifest (itskindandcardhad no reader), the emb2 seat inprofile.shno longer setsTEXT(nothing read it), andtools/check-emb2.shchecks the id reader on its own.This PR makes the ids of a gemma4 row in
gate-tokenizerand of a gemma4 tokenizer family, but adds neither. The row runs the gemma4 tokenizer of the E2 PR, so it waits for that PR. The family pins the md5 of the referencellama-tokenizeandlibllama.so, which depend on the machine that builds them, so it waits for the box's own build. Both come in a follow-up PR; the maintainer may choose otherwise.What the PR adds
tools/ref/models/gemma-embedding2.sh: the Q8_0 text file and the BF16 mmproj with their sha256, the mainline tree and its pin, and the image cases.tools/ref/qvis/build-lcpp-qvis.shbuilds every mainline oracle tree; it now takes the targets, the CUDA architecture and the toolkit by environment.tools/ref/clefvis/build-clefvis.shlinks the seat's dumper: the newgemma-embedding2row oftools/ref/clefvis/profile.shnamestools/ref/emb2/dump_emb2.cppas itsDUMPER. Every seat's.buildrecord now also carries the sha256 ofset_writer.h(build-clefvis.sh:72), the CUDA architectures, the nvcc path and version, and the cmake options of the tree'sCMakeCache.txt. So the existing seats'build-*-refrecipes now need the tree'sbuild/CMakeCache.txtand stop with a named error without it (build-clefvis.sh:38).tools/ref/clefvis/set_writer.h: the sha256, the f32 row writer and the id readerparse_ids(set_writer.h:128) of both dumpers.tools/ref/emb2/dump_emb2.cppwrites sets indump_ref's format.text: per case, onellama_decodeof all ids in one ubatch, in three contexts (every position's output projection, mean pooling before normalization, and taps of the scaled input, the output of every layer and the result).tower: per image, mtmd's encode with no callback (what llama-server hands the text model) and with taps.# tap_effectrecords whether the tap pass changes the output.just dump-ref-tokenizer gemma4runs mainline'sllama-tokenizeover the sharedcrates/tokenizer/tests/cases.txtand then the newcrates/tokenizer/tests/cases-gemma4.txt(46 cases: the EmbeddingGemma texts and this vocabulary's boundaries, such as literal▁, CRLF, invalid UTF-8, special-token edges and byte fallback). The sharedcases.txtdoes not change.tools/ref/emb2/server_vectors.pyposts every text case that is valid UTF-8, and every image tollama-server --embeddings --pooling meanand stores the server's own f32 vectors. Themrl<k>rows are derived fromrawand markedDERIVED, because llama-server has nodimensionsfield. A text case that is not valid UTF-8 gets a# skippedline (server_vectors.py:164).tools/ref/emb2/emb2.sh(just dump-ref-emb2) writes the five sets:text,towerandserveron the card,text.cpuandtower.cpuwith no card in view.tools/check-emb2.shchecks the writer's contracts with shell fixtures and no model or card: the set lock, a failed writer, a build record from another tree, the non-root build recipe,set_writer.h'sparse_idsbuilt alone with a C++ compiler (a signed, space-padded, NUL-holding, empty, out-of-range or hex line dies naming the file and line; digit lines are read), and, with--dumper <path>, the dumper's thread option.crates/refset/src/arch/gemma_embedding2/: five families (text-gemma-embedding2and its CPU twin,tower-gemma4vand its CPU twin,server-gemma-embedding2) pinned toLCPP_BUILD = "6868a52cb". They open a set throughIdentity::Emb2(crates/refset/src/family.rs:59) andEmb2Set::open(crates/refset/src/emb2.rs:71), which check the kind, the device and the files' sha256, and refuse a tower set with no first block tap (emb2.rs:173).Code shape
build-lcpp-qvis.sh,build-clefvis.sh), the set writer and id reader (set_writer.h), the token ids (oracle.sh) or the test scratch directory (clefvis::testkit::scratch). The families share oneconst fnrow builder (mod.rs:87).family.rsgains oneIdentityvariant for the emb2 set format, asClefvisdid for its dumper. The shared scripts gained variables (build-lcpp-qvis.sh's targets, architecture and toolkit;profile.sh'sDUMPER), not a per-model branch. One guard is per model:clefvis.sh:66refuses theemb2seat by name and points atjust dump-ref-emb2, because that seat's sets are notclefvis.sh's kinds.emb2.shchecks the tree before every step: HEAD at the pin and no tracked change (emb2.sh:108-111), and the commit inllama-server's version line as a prefix of the pin (emb2.sh:112-116).emb2.sh:216-217).<set>.staging(emb2.sh:218) and replaces the old one only when its writer exits 0. The old set waits as<set>.oldmeanwhile (emb2.sh:171).EMB2_BOUNDgoes through the same parser asBLOOMERY_GATE_BOUND, so0is refused (emb2.sh:49).emb2.sh:188-189) and stops and reaps itsllama-serveron every exit (emb2.sh:90).dump_emb2stops by name on a model of another arch (dump_emb2.cpp:391),--cpuwith a card in view (dump_emb2.cpp:384), a card run with no card (dump_emb2.cpp:385) and a tap whose size differs from the clean rows (dump_emb2.cpp:234,dump_emb2.cpp:312).parse_idsstops on any line that is not a decimal id from 0 toINT32_MAX(set_writer.h:126-127).cargo fmtand clippy are clean: seemac-staticbelow.Duplication found or removed:
dump_mtmd.cpp's sha256, set writer and id reader moved totools/ref/clefvis/set_writer.h(included atdump_mtmd.cpp:125anddump_emb2.cpp:64), andparse_idsis called from both dumpers (dump_mtmd.cpp:1146,dump_emb2.cpp:123). The new tests take their scratch directory fromclefvis::testkit::scratch(crates/refset/src/arch/gemma_embedding2/tests.rs:16). One part stays parallel:dump_emb2's tower pass followsdump_mtmd's tower mode, which is keyed by its own seat table and header, and gemma4v would be a fourth seat with its own taps.What I ran
The checks ran at 0c6bf2af, which holds the first three commits before the rebase onto d0cbd4b, and compare against that base, ade317e. The rebase did not change any line of this PR.
At the head f81da60 (the fifth commit removes two unread fields and one unread assignment and adds the id reader checks; no set-generation code changed) I reran the Mac checks.
cargo fmt --checkis rc 0.cargo test -p bloomery-refset --libgives 212 passed and 1 failed; the failure isarch::draft::tests::a_plain_target_with_no_draft_beside_is_the_family_path, which compares/var/...with/private/var/...on macOS, and main at d0cbd4b fails the same test on the same Mac.bash tools/check-emb2.shis rc 0, with the two id reader tests passing; with the reader's end check changed back to*end != '\0', the NUL case fails.just mac-staticis red only in lint,mac-check: lint ^warning: 44, above the ratchet 41 in tools/lint-ratchet.txt, and main at d0cbd4b gives the same line on the same Mac.On a Mac (
upstream/mainwas 803d47d for its scoped steps):shellcheck -x -S warning(ShellCheck 0.11.0) ontools/ref/emb2/emb2.shandtools/check-emb2.shhas no warnings. Oncrates/tokenizer/tools/oracle.shit reports SC1007 (twice) and SC2088 at lines 159 and 201. The base has the same warnings on the same lines, at 136 and 178, and this PR does not change them.On a DGX Spark, in the project's dev container:
cargo fmt --checkis rc 0, andcargo test -p bloomery-refset --libgivestest result: ok. 202 passed; 0 failed; 3 ignored. The fivegemma_embedding2tests are among them.The sets, on the same DGX Spark. The mainline tree was already built at the pin, so the run starts at the dumper:
refset-checkreports PASS for build6868a52cbon each of the five sets (1 set(s), 0 failedeach).The sets compared with each other (differences only, not a gate), worst over the cases:
rawagainstdump_emb2'spooledpooledagainst the mean of the case'sembdrowspooled(max abs, cosine)embd(max abs, cosine)l_out-23(max abs)embd(max abs, cosine)The server set skips four cases (
cases/23,cases/24,cases/70,cases/71), the ones that are not valid UTF-8.FAIL-first for the writer and family checks, each a temporary edit reverted after its run, on the same DGX Spark:
The set lock. With the
flockline attools/ref/emb2/emb2.sh:217replaced by:,bash tools/check-emb2.shfails three tests (test_contended_lock_names_the_set_and_returns_75,test_lock_precedes_recovery_and_staging,test_two_writers_generate_and_publish_in_order) and endsFAILED (failures=3, skipped=1), rc 1. With the line restored, the same command endsOK (skipped=1), rc 0. The skipped test is the dumper's thread option, which needs--dumper; it runs in the next item.With
bash tools/check-emb2.sh --dumper <built dump_emb2>, the head is green, and each edit below fails the named test:test_contended_lock_names_the_set_and_returns_75test_failed_writer_keeps_the_set_and_releases_the_locktest_build_record_from_another_tree_is_refusedbuild-emb2-lcpptest_nonroot_build_recipe_names_the_failure_before_detachingatoitest_thread_counts_are_checked_before_model_loadingWith
cargo test -p bloomery-refset --lib arch::gemma_embedding2::tests::: dropping the mmproj path from the identity check failsa_set_of_another_file_is_stale, rc 101. Dropping the first block tap check failsa_tower_without_block_taps_is_refused, rc 101. Restored, all five pass.The gates that
just affected ade317edselects, on the same DGX Spark, at 0c6bf2af and at ade317e: 156 gates. 20 pass at the head, and 135 fail at the head with the same result as at the base. The last one,gate-refset, fails the same three tests at both commits:arch::minicpmv4_7::prompt_tests::hw_the_prompt_sets_in_place_are_read,arch::minicpmv4_7::vis_tests::hw_the_sets_in_place_are_readandarch::tests::hw_every_set_in_place_is_its_familys, thehw_tests that read the sets installed on the machine. Its pass count goes from 197 at the base to 202 at the head, the five tests this PR adds. So every one of the 156 gates passes or fails as it does on main.What I ran into
None of this blocks this pull request.
just contrib-check(t1) is red oncheck-recipeson the DGX Spark. The head givesDONE tier=t1 total=102 red=1 wall=402s red: check-recipes. The red unit is three cases oftools/ref/lease.sh --self-test:trace-write-fail-rc,trace-write-fail-lineandtrace-write-fail-no-id. This PR does not change that script, and the base ade317e, run in the same job, givesDONE tier=t1 total=101 red=0 wall=404s. To reproduce:bash tools/ref/lease.sh --self-testat both commits.The pinned tree's
llama-serverbuild downloads its web UI from Hugging Face. At6868a52cbthe build fetches adist.tar.gzfrom theggml-org/llama-uibucket. In the build at e7072ae9 the tree was a depth-1 clone with build number 1. The download from the tagb1failed and the build fell back tolatest(excerpt of the build output):build-lcpp-qvis.shhas not changed since then. Sojust build-emb2-lcppneeds network access, and the embedded UI is whateverlatestholds that day. The sets do not depend on it, because the oracle calls only/health,/props,/tokenizeand/v1/embeddings.A shallow tree reports build number 1. At e7072ae9 the server set recorded
# server_build b1-6868a52, andllama-server --versionprintedversion: 0.6.0-dev (build 1, commit 6868a52). A clone with more history may report another number at the same commit. Nothing compares that number: no family readsserver_build, andemb2.shchecks only the commit in the version line.Hardware (if the change is for a machine)
NVIDIA GB10, 595.84, 12.1from nvidia-smi, the project's dev containerbloomery-dev:cuda13.3.1(imagesha256:853c20d59e68), CUDA 13.3.1.embeddinggemma-2-Q8_0.gguf(sha2562188ac1d...) andmmproj-embeddinggemma-2-BF16.gguf(sha256d2033b3c...).AI help
AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.