Repository navigation
feat(m3): add base ModelConfig, registry, and TrainingConfig - #6539
SurbhiJainUSC wants to merge 1 commit into
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
df08879 to
97c56c0
Compare
|
🤖 Hi @SurbhiJainUSC, I'm running an automatic MaxText review of this pull request. You can track my progress in the logs. To request another review later, add the |
97c56c0 to
8801dc5
Compare
|
🤖 I'm sorry @SurbhiJainUSC, but I was unable to process your request. Please see the logs for more details. |
bvandermoon
left a comment
There was a problem hiding this comment.
The components.py split and ModelConfig/TrainingConfig structure look really clean. A few things to sort out before merging:
129c56f to
5190505
Compare
5190505 to
9ef85b8
Compare
|
🤖 Hi @SurbhiJainUSC, I've received your request, and I'm working on it now! You can track my progress in the logs for more details. |
There was a problem hiding this comment.
📋 Review Summary
Verdict: No significant issues found. The new pydantic schemas cleanly resolve the monolithic config coupling with comprehensive validation and tests.
Inferred spec & validation
- Sources: PR description, code before/after.
- Problem:
m3model configuration is currently coupled tobase.ymland the monolithicMaxTextConfig.
| Spec item | Implementation | Validating test |
|---|---|---|
R1 (stated): Add standalone base schemas ModelConfig and TrainingConfig for m3 pre-training. |
✅ | tests/unit/m3/training_config_test.py ✅ |
R2 (stated): Extract shared config components into a dependency-free components.py. |
✅ | tests/unit/m3/model_config_test.py ✅ |
C1 (stated): Re-validate overrides in registry.py instead of naive copying. |
✅ preserved | tests/unit/m3/model_config_test.py::test_registry_lookup_overrides_and_type_check ✅ |
C2 (stated): Do not change the JSON schema for MaxTextConfig. |
✅ preserved | tests/unit/m3/training_config_test.py::test_defaults_match_base_yml ✅ |
bvandermoon
left a comment
There was a problem hiding this comment.
Thanks for addressing all of those, looks good to merge! Left a couple of small nits below (fine here or in a follow-up), and please update the PR description before merging since it still mentions 4 mesh axes / rejecting context and steps=-1.
| Partial dicts merge onto the per-mesh defaults, so `ici={"tensor": 4}` keeps `fsdp=-1` like `base.yml`. | ||
| """ | ||
|
|
||
| ici: IciMeshAxes = Field( |
There was a problem hiding this comment.
Small nit: passing a MeshAxes instance directly (e.g. MeshConfig(ici=MeshAxes(data=-1))) currently raises a ValidationError because ici/dcn are typed as the subclasses. A mode="before" validator on ("ici", "dcn") that dumps MeshAxes instances via value.model_dump() would accept it cleanly while keeping partial-dict merging onto the IciMeshAxes/DcnMeshAxes defaults.
| raise ValueError( | ||
| "`source_checkpoint_layout='safetensors_dynamic'` only supports weights-only `load_parameters_path`." | ||
| ) | ||
| return self |
There was a problem hiding this comment.
Should we also reject load_full_state_path when enable_checkpointing=False, matching types.py? (Unless the m3 checkpointer plans to support full-state restore with saving disabled.)
| class TrainingConfigTest(absltest.TestCase): | ||
| """Tests `TrainingConfig` sub-configs, validation, serialization, and `base.yml` parity.""" | ||
|
|
||
| def test_mesh_config_rejects_context_and_invalid_sizes(self): |
There was a problem hiding this comment.
Nit: context is valid now, so this test name is a bit stale (e.g. test_mesh_config_rejects_unknown_axes_and_invalid_sizes).
Description
Adds the base pure-Python, frozen Pydantic v2 configuration schemas for
m3pre-training, and extracts the shared config enums and leaf models out oftypes.pyso that bothMaxTextConfigand the newm3schemas can use them.Today, configuring
m3models is coupled tobase.yml, per-model.ymlfiles, and the monolithicMaxTextConfigschema. This PR adds the standalone base schemas as the first step in a small stacked sequence.Shared config components (
types.pyrefactor, no behavior change)src/maxtext/configs/components.py(new): dependency-free module (only the standard library andpydantic; nojaxormaxtext.utils) holding the enums and leaf sections that both config systems reuse:DType,MatmulPrecision,QuantizationType,RematPolicy,LearningRateScheduleType,WsdDecayStyle,DatasetType,ProfilerType,XProfTPUPowerTraceMode,PathStr,OrbaxStorage,AdamW,AOT,ProfilingCore,Profiling.src/maxtext/configs/types.py: these definitions are moved verbatim.types.pyimports fromcomponentsthe 13 names it uses, sofrom maxtext.configs.types import DType(etc.) keeps working. TheMaxTextConfigJSON schema is unchanged (same fields and defaults).tests/unit/profiler_test.py: importsXProfTPUPowerTraceModefromcomponents. It was the only caller reading it throughtypes.m3 model config + registry
src/maxtext/m3/models/model_config.py(ModelConfig): frozen base model (extra="forbid") using native HuggingFace field names (model_type,vocab_size,hidden_size,num_hidden_layers,param_dtype,compute_dtype). It also has:param_scan_axis: the family default for the scanned-layer axis (1 matchestrain.pycheckpoints; m3-native families use 0).mesh_divisibility_constraints()hook, so each family declares which of its dimensions must divide which mesh axis.from_model_name(name, **overrides).to_pyconfig_dict()hook.src/maxtext/m3/models/registry.py: staticMODEL_GARDEN_REGISTRYof zero-argument preset factories, plusnormalize_model_name(),get_model_config()andget_pyconfig_model_dict()(for the transitionalpyconfig.pyfallback).extra="forbid", field bounds and family validators all apply.@computed_fieldvalues (e.g.head_dim) are recomputed from the overrides. Derived dimensions must therefore be computed fields, not stored fields.m3 training config
src/maxtext/m3/configs/training_config.py(TrainingConfig): runtime schema that is frozen, hashable and rejects unknown keys (via a shared_FrozenConfigbase). It is organized into scoped sub-configs:MeshConfig: ICI/DCN sizing over 4 axes (data,fsdp,tensor,expert), stored as frozen axis models.base.ymldefaults (ici={"tensor": 4}keepsfsdp=-1).context),boolsizes, and more than one-1auto axis are rejected.TransformConfig,CheckpointConfig,MetricsConfig,DataPipelineConfig.OptimizerConfig: inherits the AdamW fields fromcomponents.AdamW, adds the WSD schedule fields (wsd_decay_steps_fraction,wsd_decay_style), and validates AdamW ranges and WSD fractions.AOTConfig,OrbaxStorageConfig,ProfilingConfig: frozen, strictly validated views of thecomponentsmodels. The originals stay mutable forMaxTextConfig.base.yml:steps=-1,grain_worker_count=-1,mu_dtype=""(inherits the param dtype), andgrain_packing_type="concat_then_split".validate_training_config(model_cfg, train_cfg, mesh_shape): cross-config checks, covering vocab-tiling divisibility and the per-family mesh divisibility constraints.Tests
CI tests
Checklist
Before submitting this PR, please make sure (put X in square brackets):
gemini-reviewlabel.types.py; verified via the CPU unit tests listed above.)