Skip to content

tools: set-diff and check-int-twins take a row's file name from manifest.py - #186

Merged
juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-ref-tensor-filename
Oct 14, 2026
Merged

juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-ref-tensor-filename

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

What and why

Closes #136.

A reference set's files are named <stem>.<occurrence>[.input][.logical].<ext>, where the stem is the manifest name with every /, \ and space made _. On the Python side, tools/ref/set-diff.py (stem) and tools/ref/check-int-twins.py (safe_name) each held the stem rule, and three call sites built the rest of the name by hand. This PR adds dump_file_name to tools/bloomery/manifest.py, the Python side's one reader of reference sets, and all three call sites use it. It takes the same arguments in the same order as dump_file_name in crates/refset/src/ik.rs, which forms the same names on the Rust side.

Code shape

  • No second copy. The two stem copies and the three hand-built names are now one function in manifest.py.
  • Model code holds only architecture facts. No model code is touched.
  • Dead code is gone. stem and safe_name are deleted, and nothing else called them.
  • No silent failure. The behavior is unchanged.
  • Comments state what is true now. tools/check-comments.sh is clean.
  • No relaxed gate. No gate, band or tolerance changed.
  • cargo fmt and cargo clippy are clean on what I touched; the lint count did not go up. Not applicable: no Rust file is touched, so I did not run them.

Duplication found or removed (path:line):

  • Removed: the stem rule at tools/ref/set-diff.py:52 and tools/ref/check-int-twins.py:71, and the hand-built names at tools/ref/set-diff.py:79, tools/ref/check-int-twins.py:122 (check_set) and tools/ref/check-int-twins.py:209 (write_set).
  • Found and left as they are, because they are in other languages:
    • Rust: crates/refset/src/ik.rs:90 (dump_stem) and :99 (dump_file_name). These are already the single Rust owner. crates/gpu-gates/src/lib.rs only re-exports dump_stem.
    • C++: safe_name in the four dumpers that write the files, tools/ref/dump_ref.cpp:149, tools/ref/dump_draft.cpp:100, tools/ref/dump_mtp.cpp:121 and tools/ref/clefvis/dump_mtmd.cpp:200. Three of their builds record the sha256 of their one .cpp (build-dump.sh:17, build-dump-mtp.sh:57, clefvis/build-clefvis.sh:42), and dump.sh, dump-mtp.sh and clefvis/clefvis.sh refuse a binary whose record does not match its source. dump_draft's record names its ik build and patch, not the .cpp. A shared header would sit outside that record, so moving safe_name into one means changing those build records and checks as well. That is left for a separate change.

dump_file_name gives the same names as the code it replaces. I compared it with the old check-int-twins and set-diff compositions on about 5,000 names (a/b\c d, an empty string, x// y, attn_norm-0 (view), and random strings of /, \, spaces, tabs, dots, dashes, brackets and non-ASCII characters), with two occurrences, both kinds, both layouts and the three extensions: 120,096 file names, all equal. The C++ copies replace bytes where the Python one replaces code points. Every byte of a multi-byte UTF-8 sequence is 0x80 or above, so none equals /, \ or a space, and both give the same names.

What I ran

On 355fd59:

$ python3 tools/bloomery/manifest.py --self-test
manifest: self-test ok
$ python3 tools/ref/check-int-twins.py --self-test
self-test: ok (20013 rounding probes, 8 sets)
$ python3 tools/ref/set-diff.py --self-test
set-diff self-test: ok
$ python3 -m py_compile tools/bloomery/manifest.py tools/ref/check-int-twins.py tools/ref/set-diff.py
$ bash tools/check-comments.sh
check-comments: ok (865 files, 129494 comment lines; ...)

The manifest self-test pins the rule with fixed expected names: attn_q_k_v-0.(view).0.input.logical.i32 for an input's logical twin whose name has a slash, a backslash and a space, and l_out-3.2.f32 for a tensor's flat f32 file. Before dump_file_name existed, this test failed with a NameError. I then broke the function five ways (no space rule, no backslash rule, no .input, no .logical, .logical before .input), and the manifest self-test failed for each one. The check-int-twins self-test writes and reads its set through the same function, so it shows that the calls resolve, not that the rule is right.

bash tools/check-recipes.sh exited 0 on the commit before the review fixes (e39f5f6e, on 3d750af; check-recipes: 54 tool self-tests ok). Its tool self-test list includes the three Python self-tests above. After the fixes and the rebase onto 15838a4, which changes only docs/contrib/dgx-spark.md, I reran those three self-tests, not the full script.

Hardware (if the change is for a machine)

Not a machine-specific change.

AI help

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

…est.py

manifest.dump_file_name forms `<stem>.<occurrence>[.input][.logical].<ext>`, the name the dumpers
give a row's file, as dump_file_name in crates/refset does; the stem is the manifest name with every
`/`, `\` and space made `_`. set-diff.py's stem and check-int-twins.py's safe_name held the stem rule
each, and three call sites built the rest of the name by hand; all of them now call
manifest.dump_file_name. The manifest self-test pins the full name for an input's logical twin whose
name has all three characters, and for a tensor's flat f32 file.
@github-actions github-actions Bot added the tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo label Oct 14, 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 shared naming function preserves existing file names, and its callers preserve validation.

Checked

Duplicates: 1 new function checked; the Python copies are removed. Rust and C++ use the same naming rule.
Complexity: no Rust functions changed. The caller changes remove local naming logic.
Silent failure: 2 suffix fallbacks followed through all callers. Invalid twin kinds and layouts produce failures before file reads; other callers supply valid values. The helper matches the replaced Python expressions.
Tests: fixed expected names at tools/bloomery/manifest.py:209 would fail if slash, backslash or space replacement were dropped, either suffix were dropped, suffix order were reversed, or occurrence were incremented.
Gates: no existing pin, threshold or test removed or relaxed. The PR reports FAIL-first and naming mutations for the added assertions.
Escape catalog: no matching pattern. Only tools change; no inference hot path is touched.

Notes

Dryer and crapper did not run because no Rust file changed.
The PR reports all three self-tests pass. Validation checked the source; those runs were not independently repeated.

🔨 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 6f87bfb into midagedev:main Oct 14, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ref tools: tensor filename normalization has two owners

1 participant