TRF009
No file in a model directory may import implementation code from another model package.
| Default | Enabled |
| Scope | All models |
| Source | mlinter/trf009.py |
| Show in terminal | mlinter --rule TRF009 |
What it does
Flags imports into another model’s package from a model’s shipped implementation files: modeling_*, configuration_*, processing_*, image_processing_*, video_processing_*, feature_extraction_*, tokenization_* and generation_*.py. Three forms count: package path (from transformers.models.other.modeling_other import X), relative path (from ..other.configuration_other import X) and public API (from transformers import OtherModel) – for the last the owning directory is inferred from the class name and confirmed against the classes it defines, so an unresolvable name is left alone. Out of scope: modular_*.py (building on another model is its purpose, and the converter flattens those imports away), convert_*.py, __init__.py and files under auto. Allowed targets: the model’s own directory, auto and timm_wrapper.
Why is this bad?
One model, one definition: model A’s behavior lives in its own files, and a change to model B must not silently change model A – for every file kind, not just modeling. Reach sub-configs through AutoConfig and CONFIG_MAPPING, and use a modular file to build on another model’s code.
Example
-from transformers.models.llama.modeling_llama import LlamaAttention
-from transformers import CLIPTextModelWithProjection
+# Keep implementation local to this model's own files.
+# To build on another model, write modular_acme.py; to reuse a snippet,
+# copy it with a # Copied from comment.
Suppressing this rule
Add a # trf-ignore: TRF009 comment on the flagged line or the line directly above it. See Suppressing rules for whole-file directives and when a suppression is the wrong answer.
Allowlisted models
4 models are exempt from TRF009 in mlinter/rules.toml, because they predate the convention and cannot be changed without breaking backward compatibility.
Show the 4 allowlisted models
dprmaskformersam3_videovision_text_dual_encoder
