Repository navigation
chore(ci): enforce the // Used by: convention, staleness included - #3167
Merged
Merged
Conversation
docs/code-guidelines.md opens with the shared-function rule: a helper that several models depend on records which of them call it. Nothing checked it, and the failure that matters is a wrong annotation, not a missing one. Issue lablup#1110 was filed against a `create_causal_mask` roster naming Llama, Mixtral, Cohere, Phi, GLM4 and StarCoder2, none of which had called it for several releases. A check for absence passes that file. scripts/ci/check_used_by.py reads every top-level `pub fn` in mlxcel-core's utils.rs and layers.rs and resolves the files that really call each one through their `use` declarations, so a private `fn softcap`, a `softcap_logits`, a `softcap: f32` parameter and the crate-root FFI re-exports of the same name are not counted. It then enforces five rules: 1. More than 5 caller files needs a `Used by:` annotation. 2. The annotation is a `///` line that starts with `Used by:`. 3. Above 12 caller files, every caller is accounted for: named in the roster (by path, or by a family name that matches the file stem), or listed by the regenerating grep the annotation carries, which the check re-runs. 4. A count recorded next to that grep is the number of files it lists. 5. A `Not used by` paragraph names no file that calls the function. Run against the tree before lablup#1121 (33322d6), rule 3 reports 41 of `create_causal_mask`'s 48 caller files as unaccounted for. The module docstring records why this combination was chosen over the three options the issue listed, and what it does not catch. On main the check failed seven annotations, fixed here as comment-only edits: - utils.rs `create_causal_mask`: handoff_impl.rs and the SAM 3 text encoder were missing from the callers outside src/models, and Gemma3 was listed as a production caller although its only calls are in a test module. - utils.rs `array_to_vec_f32`: named the embeddings engine only; 32 files call it. - layers.rs `attention`: named Llama3, Qwen3, Gemma2 and Gemma3, none of which calls it directly; 33 other files do. - layers.rs `attention_from_ptr`, `validate_quantization_params`, `infer_quantization_mode`, `validate_quantized_packing`: 134, 12, 8 and 13 caller files unrecorded. Each now closes with its regenerating grep. `slice_axis`, `silu` and `stack_arrays` are unannotated with 71, 25 and 18 callers and are grandfathered in the script's UNANNOTATED_DEBT, which fails on an entry that no longer applies. Below the threshold of 12, 21 annotations leave 39 callers unnamed; they are reported by --report and counted in the summary line, not gated. Wired as `make verify-used-by` (in `verify` and `verify-rocm`) and as the `used-by` CI job, next to `kernel-dtype-keys`. The checker runs in 2.9 s on an M4 against 0.3 s for the dtype checker; with their test scripts the two targets take 4.5 s and 5.0 s. check_used_by_test.sh builds a synthetic workspace and asserts the verdict on 23 cases, including the pre-lablup#1121 roster verbatim.
This was referenced Nov 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
scripts/ci/check_used_by.py, which holds theUsed by:annotations on the top-levelpub fns ofmlxcel-core'sutils.rsandlayers.rsto the files that really call them, and wires it asmake verify-used-byand aused-byCI job. It fails on the pre-#1121create_causal_maskannotation (41 of 48 caller files unaccounted for) and it found seven incomplete annotations onmain, which this PR fixes.Related issues
Closes #1141
Type of change
feat— new user-visible featurefix— bug fixperf— performance improvement (include before/after numbers in the PR body)refactor— internal restructuring without behavior changechore— build, CI, dependencies, release infrastructuredocs— documentation only (thedocs/code-guidelines.mdsection, and comment-only edits to seven annotations)test— tests onlyWhat the check does
Callers are resolved, not grepped. A file is a caller of
utils.rs::softcapwhen, outside test code, it imports the function by name, names it by a path that resolves to it through the file's ownuseandmoddeclarations, or calls it bare under a glob import of its module. Test code is a#[cfg(test)]item or a file declared by a#[cfg(test)] mod, never a file name pattern.Five rules.
Used by:annotation fails.///line starting withUsed by:(a//comment on a public item fails).Qwen 3.5namesqwen3_5.rs), or listed by the regeneratinggrep -rln '\bNAME(' DIR --include='*.rs'one-liner the annotation carries, which the check re-runs.N non-test files), it must equal the number of files the grep lists.Not used bymust not name a file that calls the function.--reportprints every function with its caller files and how each one is accounted for.Staleness strategy
The issue asked for the options to be weighed and the choice recorded. The full reasoning is in the script's module docstring; in short:
maincarry rosters for 14, 17 and 33 caller files (prefill_sliding_window_mask,materialized_state_tail,prefill_causal_mask) and all 64 files are named. A mandatory trailer fails them for length alone.softplusannotation names eight families in itsUsed by:paragraph to say they call the raw FFI function instead. That reads as a stale roster to this heuristic and is not one.The cost of this choice is stated under "Limits" below.
The check fails on the pre-#1121 annotation
Run against the real tree at
f0bf3a2c^(33322d66e), extracted withgit archive f0bf3a2c^ Cargo.toml src:The roster's seven hits are
DeepSeek(2 files),GLM4(2),Exaone,HunyuanandLlama(the tensor-parallelllama_runtime.rs). The 48 reconciles exactly with the issue's figures: the same grep lists 55 files on that tree, 51 oncetests.rsnames are dropped, and the three the check does not count areutils.rsitself,cache.rs(calls only inside its#[cfg(test)]module) andgemma4_mtp_target.rs(a comment mention). Therepeat_kvline is an independent cross-check: PR #1121's description counted "all 14 callers" by hand.The same text put back on today's tree (only that doc block reverted) also fails:
create_causal_mask: 10 of 14 caller files are not accounted for. The test script carries the text verbatim as itsstale-rostercase.softcapis not miscountedOn this branch 74 files contain the string
softcapandgrep -rln '\bsoftcap('lists four. The check resolves one caller ofutils.rs::softcap,src/models/recurrent_gemma.rs. The privatefn softcapinsrc/lib/mlxcel-xla/src/emitter/model.rs, the threesoftcap_logitsdefinitions and thesoftcap: f32parameters do not resolve to it. The same mechanism separatesutils.rs::silu(25 caller files) frommlxcel_core::silu, the FFI function re-exported at the crate root (grep '\bsilu('lists 112 files), andutils.rs::stack_arraysfrom thestack_arraysingemma3n_helpers.rsand the private one insam3/geometry.rs.Annotations fixed on
mainThe check failed seven annotations on
main(5288442b3). All edits are comment-only (///lines inutils.rsandlayers.rs); each caller list was read from--reportand spot-checked in the source.utils.rs::create_causal_masksrc/modelswere not named:src/distributed/disaggregated/handoff_impl.rs(named in prose only as "disaggregated handoff", now given as a path) andsrc/vision/dense/sam3/text_encoder.rs(missing). Also, found by reading the report and not by a failure: Gemma3 was listed as a production caller, but its only calls are in#[cfg(test)] mod gemma3_mask_tests. It moved to the test-only list. The count sentence (13) is unchanged and still matches.utils.rs::array_to_vec_f32/v1/embeddingsengine andmlxcel embed. 32 files call it (rerank, token classification, Flux2, dense vision and detection predictors, three model files). Rewritten as groups plus the regenerating grep.layers.rs::attentioncache.attend, Gemma2 callsattention_from_ptrandcausal_attention. 33 other files call it. This is the #1110 shape. Rewritten with the indirect routes, the direct groups, aNot used by ... directlyparagraph and the grep.layers.rs::attention_from_ptrlayers.rs::validate_quantization_paramslayers.rs::infer_quantization_modelayers.rs::validate_quantized_packingThe new annotations record no counts, so a new caller does not force an edit to them.
Test plan
Run on macOS (Apple M4, Python 3.14.3; the checker was also run under the system Python 3.9.6), and again on Linux (DGX Spark, aarch64, Python 3.12.3, Rust 1.97.1) on this PR's commit (tree
051017a830f1). Thecargoitems were run on the Linux host only.python3 scripts/ci/check_used_by.pyon this branch: exit 0.main'sutils.rsandlayers.rs(before the annotation fixes): exit 1, the seven failures above.f0bf3a2c^: exit 1, output above.bash scripts/ci/check_used_by_test.sh: 23 cases pass. They cover an absent annotation above the threshold, the pre-docs(core): annotate the three tracked shared functions in utils.rs #1121 roster verbatim, a complete roster and one that then gains an unnamed caller, the rule form with its grep, a drifted count, a contradictedNot used by, a//annotation, malformed commands, a staleUNANNOTATED_DEBTentry, a missing scoped file, and thesoftcaplook-alikes.make verify-used-by(andmake -n verifyto confirm the ordering).python3 scripts/insert_apache_header.py --check: clean.python3 -m unittest discover -s tests -p 'test_*.py': 240 tests, OK, 30 skipped (includestest_script_executable_modes, which covers the new script's mode).check_crate_versions,check_kernel_dtype_keysand its test,check_env_var_docs,check_native_env_writes,check_kernel_port_dispatchand its test,check_binary_assets,check_benchmark_raw_logs,check_benchmark_csv_schema,check_windows_reserved_paths,check_cuda_arch_lists,check_llama_compat_manifest,check_cross_repo_refs..github/workflows/ci.ymlparses with PyYAML and theused-byjob has the expected steps.python3 scripts/ci/check_used_by.pyexit 0 (3.0 s),bash scripts/ci/check_used_by_test.sh23 cases,make verify-used-by,python3 scripts/insert_apache_header.py --check, andpython3 -m unittest discover -s tests -p 'test_*.py'(240 tests, OK).cargo fmt --all -- --check: clean (Linux).cargo test -p mlxcel-core --profile test-fast --features cuda --lib -- --test-threads=1 create_causal_mask: 4 passed,create_causal_mask_roster_count_matches_repoamong them. It reads the count sentence this PR leaves at 13; rule 4 computes the same 13.cargo clippy -p mlxcel-core --features cuda --all-targets -- -D warnings: clean (Linux).mlxcel-coreis the only crate with a Rust diff, and that diff is///lines.cargo clippyandcargo test --workspace— not run: the Rust diff is comment-only.cargo deny check— not run (no dependency change).used-byCI job itself andactionlint— not run (not installed locally; the job will first run on this PR).Runtime
Three runs each on the M4,
realseconds:check_used_by.pycheck_kernel_dtype_keys.pycheck_used_by_test.shcheck_kernel_dtype_keys_test.shThe checker reads all 2,815 Rust files (50 MB) and lexes the few hundred that mention a scoped function, so it is about ten times the dtype checker. With their test scripts the two
maketargets take 4.5 s and 5.0 s. For scale,check_native_env_writes.py, already a step in theenv-var-docsjob, takes 27 s on the same machine.Notes for reviewers
Limits, so a green check is not read as more than it is.
Not used byparagraph. Only additions are caught mechanically. The Gemma3 entry above is an example of what it does not catch.main; the 21 below the threshold are a mix of real omissions (pipeline_hintdoes not mention Nanochat) and accurate prose that names a caller by what it does (materialized_axis_tailsays "RotatingKVCache's first fill" forcache/first_fill.rs). Gating those would have meant rewording correct annotations to suit the matcher, so they are counted in the summary line and listed by--reportinstead. I left them untouched, including the Nanochat one, to keep this PR to what the gate requires.ENUMERATION_THRESHOLDis the knob.DeepSeekaccounts for everydeepseek_*.rscaller, a directory path accounts for everything under it, and a capitalised word equal to a file stem accounts for that file. It can hide a missing name. It cannot fail a correct annotation.create_causal_maskhas 14 callers today, two above the threshold. The pre-docs(core): annotate the three tracked shared functions in utils.rs #1121 text is caught on today's tree only because of that margin; on the tree it was written for the count was 48.Decisions I would like checked.
UNANNOTATED_DEBTinstead of one N. The issue says to pick N against the tree so the check starts green.slice_axis,siluandstack_arraysare unannotated with 71, 25 and 18 callers, so a single N would be 71 and the absence rule would apply to almost nothing. I set N to 5 (the next unannotated maximum,relu_squared) and grandfathered those three by name in a list that fails on an entry that no longer applies. That is a hand-kept list of functions, which the issue advises against for scoping. If you prefer the single N, it is a five-line change. I did not annotate the three here because that is new documentation, not a stale-annotation fix.SCOPED_FILESis the two files the issue names.batched_decode.rs, also listed in the guidelines, has one top-levelpub fnand is not included.create_causal_mask_roster_count_matches_repoinutils.rs(chore(core): the create_causal_mask caller roster is stale and has no guard #1767) checks the same count as rule 4, for that one function. I left it in place (it passes); it can be retired in a follow-up.CONTRIBUTING.md. I addedverify-used-byto the list ofmake verifyprerequisites and bumped "ten" to "eleven". The list already omittedverify-cuda-runtime-dirbefore this PR, so the true count is twelve. I did not touch that.An observation outside the gate. The
gelu_approxannotation says "about 80 non-test call sites" and givesgrep -rn 'gelu_approx('. Two files callutils.rs::gelu_approx; the rest callmlxcel_core::gelu_approx, the FFI function. The annotation is about the formula, so I left it, but it is thesoftcapkind of count.Checklist
feat:,fix:, etc.)docs/if user-facing behavior or supported models changed (docs/code-guidelines.mdgains an Enforcement section;CONTRIBUTING.mdlists the new target and job)// Used by: ...comments on any shared function I modified (seedocs/code-guidelines.md).envfiles committed