Skip to content

[review] Check what a new base-class member means for every subclass - #6431

Merged
tianyu-l merged 1 commit into
mainfrom
review-base-class-members
Nov 29, 2026
Merged

tianyu-l merged 1 commit into
mainfrom
review-base-class-members

Conversation

@tianyu-l

Copy link
Copy Markdown
Contributor

Summary (human-written)

Why

In #6429, the author (an agent) and the @claude review bot both accepted two misplaced members, and the bot approved each version (406039a, 4ceab0a):

  • BaseModel.Config.uses_mrope_positions: a question that only means something for multimodal models, on the config every model implements (Llama3, Flux, DeepSeek, ...). A False default made it type-check everywhere.
  • RoPE.Config.takes_mrope_positions: a RoPE declaring how its model and the data side use it. The model that reads mrope_positions (Qwen35MultimodalModel.preprocess_inputs) is what should declare that.

Each was correct, small and used, so every existing checklist item passed. The checklist also pushed toward the mistake: it bans isinstance(cfg, SomeModel.Config) branches in shared code without saying a check against a family base (MultimodalModel.Config) is fine, and avoiding that isinstance is why the property was hoisted to the root. The fix the maintainer asked for (a class-level declaration on the consuming model, like multimodal_encoder_fqns) is what #6429 now does.

What changed

.claude/skills/pr-review/review-checklist.md, design section:

  • New item: a new member on a base class or shared component must mean something for every subclass (else it goes on the subset's base); a component's config must not answer a question about the model or the data side (the consuming model declares it); a check against a model class's Config misses configs that can't inherit it (slotted dataclasses can't combine two bases that add fields, e.g. Qwen3.8 Flash-Next vs Qwen3.5).
  • Clarified: isinstance against a family base at the call site is fine; the ban is on branching per specific model.

The examples in the new item are analogous (an MoE expert count on the root, an attention-config flag about document masks), not the #6429 case, so the backtest below measures whether the rule transfers.

Backtest

Local /pr-review runs (one each) on #6429's two earlier commits, with each commit's own description, from local files only:

Commit (what it has) Old checklist (main) New checklist, first wording New checklist, this PR
406039a (BaseModel property + RoPE ClassVar) root property endorsed ("the least intrusive option ... the trainer stays free of isinstance checks"); RoPE ClassVar not flagged both flagged both flagged; proposes the model-class declaration
4ceab0a (RoPE ClassVar only) -- (the live bot approved it) missed the RoPE ClassVar flagged ("wrong owner ... the consuming model declares this")

The first wording ("a lower-level piece must not encode how its container uses it") was too abstract to catch the ClassVar; naming the shape (a flag or ClassVar on a component's config that answers a question about the model or the data side) did. One run per cell, so this shows the item can fire, not its rate.

Testing

Docs-only (agent skill); pre-commit passes.

Both the author and the review bot accepted two misplaced members in #6429 (approved at
406039a and 4ceab0a): BaseModel.Config.uses_mrope_positions, a multimodal-only
question on every model's config (a False default made it type-check), and
RoPE.Config.takes_mrope_positions, a RoPE encoding how its model uses it. Each was
correct, small and used, so every existing checklist item passed; and the ban on
isinstance(cfg, SomeModel.Config) in shared code pushed toward hoisting the member to the
root to avoid an isinstance against the family base.

Add a design item: a new member on a base class or shared component must mean something
for every subclass, and a lower-level component must not encode how its container uses
it; checks against a model class's Config miss configs that can't inherit it. Clarify that
isinstance against a family base at the call site is fine.
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 28, 2026
@tianyu-l

Copy link
Copy Markdown
Contributor Author

@claude review

@claude

claude Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @tianyu-l's task in 2m 43s —— View job


Approve -- see the review (three should-consider items, no must-fix).

@claude claude 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: Approve -- the gap is real: on main, the checklist endorsed hoisting uses_mrope_positions to BaseModel.Config, as the backtest shows. The new item names the exact shape that slipped through, and the symbols it cites exist: MultimodalModel is at torchtitan/models/common/multimodal.py:32, and the Flash-Next slotted-config workaround is at torchtitan/models/qwen3_8_flash_next/model.py:411-418.

What this PR does. It adds one design item to the review checklist: a new member on a base class or shared component must mean something for every subclass, and a component's config must not answer questions about the model that contains it or about the data side. It also states that an isinstance check against a family base is allowed, and that only branching per specific model is banned.

Example. For a PR like #6429 at commit 406039a:

+ class BaseModel.Config:  uses_mrope_positions: bool = False   # root, every model
+ class Qwen35RoPE.Config: takes_mrope_positions: ClassVar = True
  • Before: the root property passed. The isinstance ban pushed reviewers toward it ("the trainer stays free of isinstance checks"), and nothing flagged the RoPE ClassVar.
  • After: both get flagged. The fix becomes a class-level declaration on MultimodalModel, read at the consumer through isinstance(cfg, MultimodalModel.Config), which is what #6429 now does.

Should consider

  • review-checklist.md:94-97 -- the slotted-dataclass caveat is about isinstance checks, so it should move into the bullet at lines 80-81. Right now "prefer the family base" appears twice.
  • review-checklist.md:80-81 -- "is fine" reads as unconditional and conflicts on its face with CLAUDE.md principle 5 and the "Intrusiveness" item. Scope it to consumers that already serve that family.
  • review-checklist.md:84 -- consider marking the new item (diff check). The workflow then has the reviewer actually search the added lines for new fields, properties, and ClassVars in models/base/ and models/common/ classes. That search is mechanical, and the miss in #6429 was a reviewer not looking.
Details
  • Overlap search: gh pr list --search "review-checklist" returned only this PR and #5636 (an add_model skill), which doesn't touch this section. direction.md has no related migration.
  • Family-base isinstance in shared code is established practice: torchtitan/rl/controller/controller.py:521,532 (MultimodalModel.Config), torchtitan/distributed/pipeline_parallel.py:112 and torchtitan/config/validation.py:171 (Decoder.Config). So the clarification matches the repo; only its scope needs tightening.
  • The rule's example (an attention-config flag telling the data side to build document masks) doesn't match existing code on main: no reader of mask_type exists outside the attention modules. So the new item won't flag existing code.
  • The existing BaseModel ClassVars (state_dict_adapter_cls and pipeline_*_stage_module_fqns, torchtitan/models/base/model.py:125-127) mean something for every model. The new item is consistent with them.

Before merge: fill in the human-written summary.

Comment on lines +94 to +97
A check against a model class's `Config` also misses configs that can't inherit
it (two slotted bases that add fields can't combine, e.g. Qwen3.8 Flash-Next's
config vs Qwen3.5's): prefer the family base or a class-level declaration on
the model.

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.

This sentence is about isinstance checks, not about new base-class members, so it belongs in the "Shared wrappers stay general" bullet just above. Where it sits now, "prefer the family base" appears in both bullets, and a reviewer working through the isinstance (diff check) won't see the slotted-dataclass caveat, which is the case it was written for (torchtitan/models/qwen3_8_flash_next/model.py:411-418). The fix is to delete lines 94-97 and extend lines 80-81 instead, for example:

  An `isinstance` against a family base (`MultimodalModel.Config`) at the call
  site is fine; the ban is on branching per specific model. A check against a
  specific model's `Config` also misses configs that can't inherit it (two
  slotted bases that add fields can't combine, e.g. Qwen3.8 Flash-Next's config
  vs Qwen3.5's), so check the family base or a class-level declaration instead.

Comment on lines +80 to +81
An `isinstance` against a family base (`MultimodalModel.Config`) at the call
site is fine; the ban is on branching per specific model. An adapter is thin

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.

As written, "is fine" sounds like blanket permission. It also conflicts on its face with CLAUDE.md principle 5 and with the "Intrusiveness" item a few bullets up, which say trainer.py / training_engine.py don't know about features. A bot can read this sentence as clearing any isinstance(cfg, MoE.Config) / MultimodalModel.Config branch in core, even for a feature core has no other reason to know about. That is the same kind of push toward a mistake that this PR describes.

The pattern itself is established: torchtitan/rl/controller/controller.py:521 does it, and #6429 adds it to trainer.py, where the trainer already builds multimodal batches (vision_processor). So the fix is to scope the sentence, not drop it. For example: "...at a consumer that already serves that family (e.g. the trainer building multimodal batches) is fine; the ban is on branching per specific model, and core still doesn't learn about a feature only for this check."

@tianyu-l
tianyu-l merged commit 1a2d68e into main Nov 29, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants