Repository navigation
Conversation
|
@claude review |
There was a problem hiding this comment.
Verdict: Approve -- please address the items below before merging. The model now decides whether image tokens get M-RoPE positions, which deletes two hand-set flags and fixes a real silent case in SFT. What's left are small local edits. A maintainer still needs to review, since this touches trainer.py and BaseModel.Config.
What this PR does. BaseModel.Config.uses_mrope_positions (default False) is set to True by MultimodalModel.Config when its full-attention RoPE config has takes_mrope_positions (MRoPE.Config). The SFT trainer passes it to the dataloader and validator through DatasetBuildContext. The RL controller passes it to TrainingBatchBuilder. Both config flags, every recipe's setting of them, and the controller's mismatch check are deleted.
Example.
# Qwen3.5 SFT recipe that forgets the flag
collator=MultiModalCollator.Config()
before: no mrope_positions in the batch -> Qwen35MultimodalModel.preprocess_inputs
falls back to 1D `positions` for image tokens; no error
after: config.model.uses_mrope_positions == True -> collator builds (T, 3) mrope_positions
# Kimi / Muse: uses_mrope_positions == False -> 1D positions, unchanged
Must fix
- The PR body's "Summary (human-written)" section is empty. It needs to be filled in before merge.
torchtitan/models/common/multimodal.py:58-64: this duplicatesget_mrope_config(qwen3_5/rope.py:115), which the vLLM generator still uses. With the controller check gone, the trainer and the generator now decide the same question with two different predicates. Haveregistry.pyusecfg.uses_mrope_positionsand deleteget_mrope_config(see inline comment).
Should consider
torchtitan/components/data/loader.py:125(andvalidator.py:141,training_batch_builder.py:422, the Monarch actor): the= Falsedefaults let a new caller that forgets the argument silently get 1D positions again. Make the argument required.tests/rl/unit_tests/cpu/test_geometry3k.py:143-148: this test repeats the Qwen3.5 recipe asserts and has a misleading docstring. The Flash-Next case the description highlights isn't covered. Swap this test for a Flash-Next entry in the existing parametrize list.
Details
- Gate: the problem is real on the base branch.
Qwen35MultimodalModel.preprocess_inputs(qwen3_5/model.py:463-467) uses 1Dpositionswhenevermrope_positionsis absent, and nothing on the SFT side checked the flag. Deriving it from the model is the right layer and removes a knob nobody would set differently. - Callsite audit:
GrainDataLoaderandValidatorare built only intrainer.pyandexperiments/torchft/trainer.py, and both are updated.TrainingBatchBuilderis built through the Monarch actor and in tests, all updated. No otherDatasetBuildContextconstruction in source needs the value. ClassVaron aslots=Truedataclass is excluded from fields and is fine. Subclasses ofMRoPE.Configinherit True.- A model-side guard (raise in
preprocess_inputswhen the model uses M-RoPE andpixel_valuesare present butmrope_positionsis missing) would also catch the failure. This PR removes the cause, so that guard isn't needed here.
Not verified: the bitwise loss/grad_norm equality in the description (needs a GPU run).
| @property | ||
| def uses_mrope_positions(self) -> bool: | ||
| """True when the full-attention RoPE is M-RoPE (e.g. Qwen3.5's); else image tokens | ||
| take 1D positions, like text.""" | ||
| # MLA attention configs (e.g. DeepSeek V3, Kimi K3) have no ``rope`` field. | ||
| rope = getattr(self.first_full_attention, "rope", None) | ||
| return isinstance(rope, RoPE.Config) and rope.takes_mrope_positions |
There was a problem hiding this comment.
This is the same predicate as get_mrope_config (torchtitan/models/qwen3_5/rope.py:115), which isn't touched here: the same getattr(self.first_full_attention, "rope", None), even the same MLA comment. But the two tests differ. This one reads RoPE.Config.takes_mrope_positions; that one uses isinstance(rope, MRoPE.Config). The vLLM generator decides on 3D positions through get_mrope_config (rl/generator/vllm/registry.py:204), and the trainer/data side now goes through this property. The controller check that kept those two in agreement is deleted in this PR, so the two predicates are now the only thing that has to stay in sync.
The smallest fix is one predicate. In registry.py, gate on cfg.uses_mrope_positions and read theta/mrope_section from cast(MRoPE.Config, cfg.first_full_attention.rope), then delete get_mrope_config. That's about -7 lines, and generator and trainer can't disagree.
| max_context_length: int, | ||
| num_tokens_per_microbatch: int, | ||
| vision_processor: VisionProcessor | None = None, | ||
| build_mrope_positions: bool = False, |
There was a problem hiding this comment.
The = False default here brings back the failure this PR removes. A new entry point that builds the dataloader (or the validator, validator.py:141, or TrainingBatchBuilder, training_batch_builder.py:422) and forgets to pass the value gets 1D image positions again, with no error. Every in-repo caller already passes it explicitly. Making it a required keyword argument at these three pass-through points (and on the Monarch actor) turns a forgotten pass into a TypeError. It also follows CLAUDE.md: "Don't give internal functions defaults that duplicate a config default."
| def test_recipe_gives_image_tokens_the_positions_its_model_takes() -> None: | ||
| """The training batch builder gives the trainer M-RoPE positions exactly when the model takes them, as | ||
| the generator does; Controller.Config rejects a mismatch.""" | ||
| """The training batch builder gives the trainer M-RoPE positions exactly when the model | ||
| takes them, as the generator does.""" | ||
| from torchtitan_recipes.rl.geometry3k import rl_grpo_qwen3_5_0_8b_geometry3k | ||
|
|
||
| config = rl_grpo_qwen3_5_0_8b_geometry3k() | ||
| training_batch_builder = config.async_loop.training_batch_builder | ||
|
|
||
| assert training_batch_builder.build_mrope_positions | ||
| with pytest.raises(ValueError, match="build_mrope_positions=False.*M-RoPE"): | ||
| dataclasses.replace( | ||
| config, | ||
| async_loop=dataclasses.replace( | ||
| config.async_loop, | ||
| training_batch_builder=dataclasses.replace( | ||
| training_batch_builder, build_mrope_positions=False | ||
| ), | ||
| ), | ||
| ) | ||
| assert rl_grpo_qwen3_5_0_8b_geometry3k().trainer.model.uses_mrope_positions |
There was a problem hiding this comment.
The docstring says this checks what the training batch builder does "as the generator does". It now only reads uses_mrope_positions off a Qwen3.5 model config. The new asserts in test_qwen_multimodal_data.py already cover that same derivation for Qwen3.5. Meanwhile the case the PR description calls out, Flash-Next (whose config isn't a Qwen35MultimodalModel.Config), isn't asserted anywhere. I suggest deleting this test and adding qwen38_flash_next_debugmodel_mm to the test_qwen_recipe_vision_processor_matches_vision_encoder parametrize list (or a one-line assert next to it).
406039a to
4ceab0a
Compare
|
@claude review again |
|
Claude finished @tianyu-l's task in 1m 21s —— View job Approve -- please address the items before merging. None of the four earlier items are fixed at HEAD: the human-written summary is empty, |
There was a problem hiding this comment.
Verdict: Approve -- please address the items below before merging. None of the items from the previous review are fixed at HEAD (4ceab0a, amended 08:58), and the amend adds no new problems. A maintainer still needs to review, since this touches trainer.py.
Correction to the previous review. It said the property lives on BaseModel.Config. That was wrong: uses_mrope_positions is defined only on MultimodalModel.Config (torchtitan/models/common/multimodal.py:58). Each caller (trainer.py:221, experiments/torchft/trainer.py:210, rl/controller/controller.py:907) guards it with isinstance(config.model, MultimodalModel.Config). I checked Flash-Next: its config subclasses MultimodalModel.Config (qwen3_8_flash_next/model.py:414), and its RoPE config subclasses Qwen35MRoPE.Config (qwen3_8_flash_next/attention.py:106). So it does derive True.
Must fix (still open)
- The PR body's "Summary (human-written)" section is still empty.
torchtitan/models/common/multimodal.py:58-65vstorchtitan/models/qwen3_5/rope.py:115: there are still two predicates for the same question. The trainer and data side useuses_mrope_positions(RoPE.Config.takes_mrope_positions). The vLLM generator usesget_mrope_config(isinstance(rope, MRoPE.Config),rl/generator/vllm/registry.py:204). The controller check that kept them in agreement is deleted. Fix: inregistry.py, gate oncfg.uses_mrope_positions, readthetaandmrope_sectionfromcast(MRoPE.Config, cfg.first_full_attention.rope), and deleteget_mrope_config.
Should consider (still open)
torchtitan/components/data/loader.py:125,components/validator.py:141,rl/trainer/training_batch_builder.py:422,rl/actors/monarch/training_batch_builder.py:39(andDatasetBuildContext.build_mrope_positionsatcomponents/data/types.py:102): the= Falsedefaults are still there. A new caller that forgets the argument silently gets 1D image positions again. Make it a required keyword.tests/rl/unit_tests/cpu/test_geometry3k.py:143-148: this test still repeats the Qwen3.5 assert intest_qwen_multimodal_data.py, and its docstring describes behavior it no longer checks. Flash-Next, the case the description highlights, is still not in thetest_qwen_recipe_vision_processor_matches_vision_encoderparametrize list (test_qwen_multimodal_data.py:251-261). Replace this test with a(qwen38_flash_next_configs, "qwen38_flash_next_debugmodel_mm")entry there.
Details
- Re-checked at HEAD: the callsites of
GrainDataLoader,Validator,TrainingBatchBuilder, andMultiModalCollatorall pass the derived value. No recipe still sets either deleted field.ClassVaron theslots=TrueRoPE configs stays out of the dataclass fields, and subclasses inherit it. - The
isinstance(..., MultimodalModel.Config) and ...uses_mrope_positionsexpression is repeated in three places (one of them in experiments). That is acceptable at this size. Fixing must-fix 2 doesn't change it.
Not verified: the bitwise loss/grad_norm equality in the description (needs a GPU run).
4ceab0a to
9059e3d
Compare
|
@claude review again |
|
Claude finished @tianyu-l's task in 1m 53s —— View job Approve -- please address the items before merging. The new class-attribute derivation is fine, but all four earlier items are still open. The two-predicate item now has a different shape: the trainer reads |
There was a problem hiding this comment.
Verdict: Approve -- please address the items below before merging. HEAD 9059e3d changes how the value is derived, and that change is fine. All four earlier items are still open, though, and the two-predicate one now has a different shape. A maintainer still needs to review, since this touches trainer.py.
What changed since the last review. uses_mrope_positions is now a class attribute on the model: MultimodalModel.uses_mrope_positions = False (torchtitan/models/common/multimodal.py:43), set to True on Qwen35MultimodalModel (qwen3_5/model.py:386). MultimodalModel.Config.uses_mrope_positions reads it from type(self)._owner (multimodal.py:60-64). This follows the existing multimodal_encoder_fqns precedent in the same __post_init__. Flash-Next gets True through the MRO: Qwen38FlashNextMultimodalModel(Qwen38FlashNextModel, Qwen35MultimodalModel) puts Qwen35MultimodalModel ahead of MultimodalModel. Kimi, Muse Glimmer and Muse Spark inherit False.
Example.
Qwen3.5 SFT, collator=MultiModalCollator.Config()
Qwen35MultimodalModel.Config._owner.uses_mrope_positions == True
-> trainer passes build_mrope_positions=True -> collator builds (T, 3) mrope_positions
RL generator for the same model: get_mrope_config(cfg) -> isinstance(rope, MRoPE.Config)
-> a different question, and nothing checks the two answers agree any more
Must fix (still open)
- The PR body's "Summary (human-written)" section is still empty.
torchtitan/rl/generator/vllm/registry.py:204vstorchtitan/models/common/multimodal.py:43: two predicates still answer the same question, and now they read different sources. The trainer and data side use a hand-set class attribute. The vLLM generator still usesget_mrope_config(qwen3_5/rope.py:113,isinstance(rope, MRoPE.Config)). The controller check that kept them in agreement is gone. Take a new multimodal model whose RoPE isMRoPE.Configbut whose class doesn't set the attribute: the generator serves 3D positions, the trainer trains on 1D, and nothing raises. That is the same silent failure this PR removes from SFT. Fix: inregistry.py, gate onisinstance(cfg, MultimodalModel.Config) and cfg.uses_mrope_positions(serves_imagesalready implies a multimodal config), readtheta/mrope_sectionfromcast(MRoPE.Config, cfg.first_full_attention.rope), and deleteget_mrope_config. That's about -7 lines.
Should consider (still open)
components/data/loader.py:125,components/validator.py:141,rl/trainer/training_batch_builder.py:422,rl/actors/monarch/training_batch_builder.py:39,components/data/types.py:102: the= Falsedefaults are unchanged. A new caller that forgets to pass the value silently gets 1D image positions again. Make the argument required. Thetest_packed_vision.pycontexts already pass it explicitly.tests/rl/unit_tests/cpu/test_geometry3k.py:143-148: this test still repeats the Qwen3.5 assert intest_qwen_multimodal_data.py:276, and its docstring describes training-batch-builder behavior it doesn't check. Flash-Next is still missing from the parametrize list attest_qwen_multimodal_data.py:251-261. It's the one family where the value arrives only through MRO, so it's the case most worth guarding. Replace this test with a(qwen38_flash_next_configs, "qwen38_flash_next_debugmodel_mm")entry there.
Details
_owneris set perConfigclass byConfigurable.__init_subclass__(config/configurable.py:190). Every multimodal model class defines its ownConfig, so the property resolves to the right class for all five families. Reading_ownerfrom a config's__post_init__or a property already has precedent inmultimodal.py:49.- Callsites re-checked at HEAD:
GrainDataLoaderandValidator(trainer.py,experiments/torchft/trainer.py), andTrainingBatchBuilder(the Monarch actor viacontroller.py:907, plus tests) all pass the derived value. No recipe still sets either deleted field.
Not verified: the description's claim that the attribute equals "full-attention RoPE is MRoPE" for all 21 multimodal flavors (I couldn't run Python in this job), and the bitwise loss/grad_norm equality (needs a GPU run).
SFT (MultiModalCollator.Config) and RL (TrainingBatchBuilder.Config) each had a build_mrope_positions flag that recipes set by hand to whether the model's image tokens take 3D M-RoPE positions. RL's controller rejected a mismatch; SFT didn't check, and a Qwen3.5-family SFT recipe without the flag silently gave image tokens 1D positions (Qwen3.5's preprocess_inputs falls back to positions when mrope_positions is absent). The model now declares it, like multimodal_encoder_fqns: MultimodalModel.uses_mrope_positions (False), True on Qwen35MultimodalModel, whose preprocess_inputs reads mrope_positions; Qwen3.8 Flash-Next's model inherits it (its config can't inherit Qwen35MultimodalModel.Config: two slotted bases that add fields can't combine). MultimodalModel.Config.uses_mrope_positions reads it from the owner model class. One declaration feeds every consumer: the trainer passes it to the dataloader and validator (DatasetBuildContext.build_mrope_positions), the RL controller to the training batch builder, and the vLLM registry gates M-RoPE on it (asserting the RoPE is MRoPE) instead of get_mrope_config, which is deleted. Both flags, RL's mismatch check and the recipes' settings are deleted; every recipe that set the flag derives the same value.
9059e3d to
b70d79a
Compare
|
@claude review again |
|
Claude finished @tianyu-l's task in 56s —— View job Approve -- please address the items before merging. The two-predicate issue is fixed: the trainer and the vLLM generator now both read |
There was a problem hiding this comment.
Verdict: Approve -- please address the items below before merging. HEAD b70d79a fixes the two-predicate problem: the generator and the trainer now read the same declaration. The other three earlier items are still open, and all three are small local edits. A maintainer still needs to review, since this touches trainer.py.
What changed since the last review. registry.py:205-215 now gates vLLM's M-RoPE on isinstance(cfg, MultimodalModel.Config) and cfg.uses_mrope_positions. It asserts that the full-attention RoPE is MRoPE.Config and reads theta/mrope_section from it. get_mrope_config is deleted (qwen3_5/rope.py), and no references to it remain in the repo.
Example.
Qwen3.5 RL, image prompts
trainer: Qwen35MultimodalModel.uses_mrope_positions == True -> training batch builder builds (T, 3) mrope_positions
generator: same attribute -> rope_parameters["mrope_section"] set -> vLLM uses 3D positions
New multimodal model with MRoPE.Config but no class attribute:
before this commit: generator 3D, trainer 1D, nothing raised
now: both 1D (consistent)
Class attribute True but non-MRoPE RoPE: the registry assert fires
Resolved
- Two predicates for the same question (
registry.pyvsmultimodal.py): fixed. There is one source now.
Must fix (still open)
- The PR body's "Summary (human-written)" section is still empty.
Should consider (still open)
components/data/loader.py:125,components/validator.py:141,components/data/types.py:102,rl/trainer/training_batch_builder.py:422,rl/actors/monarch/training_batch_builder.py:39: thebuild_mrope_positions: bool = Falsedefaults are still there. A new caller that forgets the argument silently gets 1D image positions, which is the failure this PR removes. Every caller in the repo already passes the value explicitly;test_packed_vision.pynow does too. Drop the defaults so a missed pass raisesTypeError.tests/rl/unit_tests/cpu/test_geometry3k.py:143-148: this test repeats the Qwen3.5 assert attest_qwen_multimodal_data.py:276(same model class). Flash-Next is still missing from the parametrize list attest_qwen_multimodal_data.py:250-262. It's the one family that gets True only through the MRO (Qwen38FlashNextMultimodalModel(..., Qwen35MultimodalModel)). Replace this test with a(qwen38_flash_next_configs, "qwen38_flash_next_debugmodel_mm")entry there.
Details
- The new registry
assertis the right tool. A class that declares M-RoPE but has a non-M-RoPE RoPE is a programmer error, not a user config error. serves_imagesalone doesn't implyMultimodalModel.Configat this call site, so theisinstanceguard is needed. With it, a text-onlyDecoder.Configskips M-RoPE correctly.- Callsites re-checked at HEAD.
GrainDataLoader/Validatorare built intrainer.pyandexperiments/torchft/trainer.py.TrainingBatchBuilderis built throughcontroller.py:907-> the Monarch actor, plus tests. All of them pass the derived value. No recipe sets either deleted field.
Not verified: the bitwise loss/grad_norm equality in the description (needs a GPU run).
…6431) ## Summary (human-written) <!-- Write this yourself, not with an AI tool. 2-5 sentences: the problem, why this approach, and what you checked yourself. --> ## 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.
Summary (human-written)
Why
Whether image tokens take 3D M-RoPE positions is a property of the model (its full-attention RoPE is
MRoPE, as in Qwen3.5), but SFT and RL each make recipes set it by hand:MultiModalCollator.Config.build_mrope_positionsandTrainingBatchBuilder.Config.build_mrope_positions. RL's controller rejects a mismatch with the trainer model; SFT doesn't check. Qwen3.5'spreprocess_inputsfalls back to the 1Dpositionswhenmrope_positionsis absent, so a Qwen3.5-family SFT recipe that leaves the flag out trains image tokens with the wrong rotary positions, silently.Example (Qwen3.5 SFT on images):
What changed
multimodal_encoder_fqns:MultimodalModel.uses_mrope_positions(False), set True onQwen35MultimodalModel, whosepreprocess_inputsreadsmrope_positions;MultimodalModel.Config.uses_mrope_positionsreads it from the owner model class. Qwen3.8 Flash-Next's model class inherits it (its config can't inheritQwen35MultimodalModel.Config: two slotted bases that both add fields can't combine). Models that aren't multimodal have no image tokens, so callers give them False. Checked: for all 21 multimodal flavors it equals whether the full-attention RoPE isMRoPE.DatasetBuildContext.build_mrope_positions, whichMultiModalCollatorreads.max_kept_set_size); its mismatch check is deleted. The vLLM registry gates M-RoPE on the same declaration (asserting the full-attention RoPE isMRoPE) instead ofget_mrope_config, which is deleted, so the generator and the trainer can't disagree.Net +4 lines: recipes -13, tests -5, docs +4, source +18 (passing the value from the trainer to the dataloader, validator and the torchft trainer). The point is the removed knob and the silent SFT case, not line count.
User-facing changes
MultiModalCollator.Config(build_mrope_positions=...)TrainingBatchBuilder.Config(build_mrope_positions=...)Numerics
Every recipe that set the flag derives the same value (checked for all 29: True for the Qwen3.5/3.6/3.8 and Flash-Next ones, False for Kimi, Muse and SFT Slake), so their numerics are unchanged. Bitwise equal
lossandgrad_normvs #6427, 10 steps, seed 42, deterministic, 1 GB300 (scripts/loss_compare.py --assert-equal, grad_norm from TensorBoard):qwen35_debugmodel(CC12M images), accelerator graphs offqwen35_debugmodel_videomuse_glimmer_debugmodel_mm, flex attentionTesting
test_qwen_multimodal_data.pynow also assertuses_mrope_positionsper family (True for the Qwen recipes, False for Kimi and Muse): a family that loses it would silently train 1D image positions.test_geometry3k.pychecks the RL recipe's model.pytest tests/rl/unit_tests/cpu tests/unit_tests/cpu/components tests/unit_tests/cpu/test_trainer.py tests/unit_tests/cpu/models(aarch64 GB300 host): 2,248 passed; the 5 failures also fail on main on aarch64 (compiled flex attention on CPU, fixed by [tests] Keep compiled flex attention out of CPU unit tests #6422).Known issues / follow-ups
qwen35_debugmodelwith accelerator graphs on fails at step 2 underscripts/loss_compare.pyon main as well (pixel_valueschanges shape between microbatches: 1344 vs 988 patches); unrelated to this PR.