Discussion: Deprecate ModelSpec and migrate its fields
Hi! I noticed the TODO about deprecating ModelSpec in torchtitan/torchtitan/protocols/model_spec.py and wanted to make sure I understand the current architecture before I start working on it. From tracing the codebase, this is my understanding of the current structure:
Current
Trainer
│
└── config (Trainer.Config)
│
└── model_spec (ModelSpec)
│
├── name
├── flavor
├── model ───────────────────────► BaseModel.Config
├── parallelize_fn
├── pipelining_fn
├── post_optimizer_build_fn
├── state_dict_adapter
└── traverse()
│
▼
BaseModel.Config
│
├── hidden_size
├── num_layers
├── vocab_size
├── max_seq_len
├── attention
├── ...
└── traverse() (inherited)
My interpretation of the TODO
Trainer
│
└── config (Trainer.Config)
│
├── model ───────────────────────► BaseModel.Config
├── parallelize_fn
├── pipelining_fn
├── post_optimizer_build_fn
├── state_dict_adapter
├── name
└── flavor
│
▼
BaseModel.Config
│
├── hidden_size
├── num_layers
├── vocab_size
├── max_seq_len
├── attention
├── ...
└── traverse() (inherited)
(ModelSpec wrapper removed)
My understanding is that ModelSpec currently acts as an intermediate wrapper that bundles:
- BaseModel.Config
- metadata (name, flavor)
- runtime callbacks (parallelize_fn, pipelining_fn, post_optimizer_build_fn, state_dict_adapter)
- a custom traverse() that forwards traversal into self.model.
My interpretation of the TODO is that the goal is to remove this intermediate wrapper while preserving the existing behavior. I just wanted to confirm whether my understanding is correct before I start working on it.
I also had a couple of questions regarding the intended migration:
-
Which ModelSpec fields are expected to move into Trainer.Config, and which (if any) should move into BaseModel.Config?
-
Should model_registry() continue returning an object after this refactor, or is its API expected to change as part of removing ModelSpec?
-
Is ModelSpec.traverse() expected to disappear entirely once the wrapper is removed?
If my understanding matches the intended design, I'd be happy to work on the refactor.
@tianyu-l
@wwwjn @fegin @felipemello1
Thanks for your interest. This one is a bit tricky that I might want to work on it by myself.
Makes sense, thanks for the clarification @tianyu-l . If there are any follow-up tasks or parts of the refactor I can help with, I'd love to contribute.