Refactor model configuration and parallelization ownership - #4810
Conversation
fe8f3c1 to
4cf26f9
Compare
| f"{type(self).__name__} must implement preprocess_inputs()." | ||
| ) | ||
|
|
||
| def verify_module_protocol(self) -> None: |
There was a problem hiding this comment.
capability merged into _parallelize() as it's executed recursively for every module already
cec4607 to
10d0fe9
Compare
|
GraphTrainer is the same on main |
| ) | ||
| from torchtitan.models.common.param_init import depth_scaled_std | ||
| from torchtitan.models.deepseek_v3.parallelize import ( | ||
| parallelize_deepseekv3 as parallelize_deepseek_v4, |
There was a problem hiding this comment.
It seems like removing this got rid of apply_fsdp_to_mtp_decoder used in parallelize_deepseekv3. And DSv4 just inherits from Decoder not MTPDecoder, so the specific fsdp behavior is lost.
There was a problem hiding this comment.
Good catch. DeepSeek V4 was falling back to Decoder._apply_fsdp(), which does not treat its separate mtp_layers as decoder-layer FSDP units. I added a DeepSeekV4Model._apply_fsdp() override that follows MTPDecoder and calls apply_fsdp_to_mtp_decoder(), plus a regression test. Updated in 4c7729c.
wwwjn
left a comment
There was a problem hiding this comment.
This refactor looks great to me
|
|
||
| multimodal_encoder_fqns: tuple[str, ...] = () | ||
|
|
||
| def parallelize( |
There was a problem hiding this comment.
nit: in human note part, you note that this fuction should be named as _parallelize() ?
There was a problem hiding this comment.
Model.parallelize() still exist as public entry point
Module.parallelize() becomes Module._parallelize()
10d0fe9 to
4c7729c
Compare
4c7729c to
22b7a4c
Compare
…4829) ## Summary #4810 deleted `ModelSpec` and per-model `parallelize.py`. `Trainer.Config.model` (and `Controller.Config.model`) is the Suppress-annotated field. Four docs still used the old names, so copy-paste snippets fail with `TypeError: unexpected keyword argument 'model_spec'` or point at a file that no longer exists. Same class of stale-path cleanup as #4805. - `torchtitan/config/README.md`: `Trainer.Config(model=...)` and `Trainer.Config.model` in the CLI-freeze paragraph - `torchtitan/rl/README.md`: `Controller.Config(model=...)` - `torchtitan/overrides/README.md`: FQN example `model.layers.0.feed_forward` - `torchtitan/models/llama3/README.md`: point at `sharding.py` and `BaseModel.parallelize()` instead of `parallelize.py` Docs only. No behavior change. Fixes #4827. ## Test plan - [ ] Confirmed each replacement path exists on this branch (`Trainer.Config.model`, `Controller.Config.model`, `llama3/sharding.py`, `BaseModel.parallelize`) - [ ] Grepped the four files for leftover `model_spec=` Config keywords and `parallelize.py`
Human's note
ModelSpecand refactor fields intoModelorModel.ConfigModel/Decoder/MultimodalModel/FluxModelto hold the logic, shared with model subclassesModel._apply_fsdp()for the above reasontrain_contextas it only calls intoget_spmd_contextModule.parallelize()->Module._parallelize()as it's not supposed to be overriddenSummary
ModelSpecand make each model class own its config, checkpoint adapter, optimizer hooks, and high-level parallelization behaviorBaseModel,Decoder, andMultimodalModel, while keepingModule._parallelize()as the low-level primitiveparallelize.pyfilesmax_context_lengthon decoder configs and set it in concrete model presetsWhy
ModelSpecduplicated model identity outside the model class and allowed invalid combinations such as one model with another model checkpoint adapter or optimizer hooks. Per-model parallelization files also repeated behavior that belongs to shared model families. This change makes those relationships structural: selecting a model class determines its configuration and associated behavior, while model subclasses retain focused override points.Backward compatibility is intentionally not preserved for the removed
ModelSpecAPIs.Testing
pre-commit run --all-filespytest tests/unit_tests/cpu -x -q(1169 passed, 2 skipped)The branch is rebased onto current
main. This is a regular PR so the full upstream CI suite will run.