Skip to content

feat(m3): add base ModelConfig, registry, and TrainingConfig - #6539

Open
SurbhiJainUSC wants to merge 1 commit into
mainfrom
m3-configs
Open

SurbhiJainUSC wants to merge 1 commit into
mainfrom
m3-configs

Conversation

@SurbhiJainUSC

@SurbhiJainUSC SurbhiJainUSC commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Adds the base pure-Python, frozen Pydantic v2 configuration schemas for m3 pre-training, and extracts the shared config enums and leaf models out of types.py so that both MaxTextConfig and the new m3 schemas can use them.

Today, configuring m3 models is coupled to base.yml, per-model .yml files, and the monolithic MaxTextConfig schema. This PR adds the standalone base schemas as the first step in a small stacked sequence.

Shared config components (types.py refactor, no behavior change)

  • src/maxtext/configs/components.py (new): dependency-free module (only the standard library and pydantic; no jax or maxtext.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.py imports from components the 13 names it uses, so from maxtext.configs.types import DType (etc.) keeps working. The MaxTextConfig JSON schema is unchanged (same fields and defaults).
  • tests/unit/profiler_test.py: imports XProfTPUPowerTraceMode from components. It was the only caller reading it through types.

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 matches train.py checkpoints; m3-native families use 0).
    • a mesh_divisibility_constraints() hook, so each family declares which of its dimensions must divide which mesh axis.
    • from_model_name(name, **overrides).
    • a transitional to_pyconfig_dict() hook.
  • src/maxtext/m3/models/registry.py: static MODEL_GARDEN_REGISTRY of zero-argument preset factories, plus normalize_model_name(), get_model_config() and get_pyconfig_model_dict() (for the transitional pyconfig.py fallback).
    • Overrides are re-validated, not copied, so extra="forbid", field bounds and family validators all apply.
    • @computed_field values (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 _FrozenConfig base). It is organized into scoped sub-configs:
    • MeshConfig: ICI/DCN sizing over 4 axes (data, fsdp, tensor, expert), stored as frozen axis models.
      • Partial dicts merge onto the base.yml defaults (ici={"tensor": 4} keeps fsdp=-1).
      • Unknown axes (e.g. context), bool sizes, and more than one -1 auto axis are rejected.
    • TransformConfig, CheckpointConfig, MetricsConfig, DataPipelineConfig.
    • OptimizerConfig: inherits the AdamW fields from components.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 the components models. The originals stay mutable for MaxTextConfig.
  • Defaults and sentinel values match base.yml: steps=-1, grain_worker_count=-1, mu_dtype="" (inherits the param dtype), and grain_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):

  • I have performed a self-review of my code. For an optional AI review, add the gemini-review label.
  • I have necessary comments in my code, particularly in hard-to-understand areas.
  • I have run end-to-end tests and provided workload links above if applicable. (Schema-only PR plus a pure-move refactor of types.py; verified via the CPU unit tests listed above.)
  • I have made or will make corresponding changes to the doc if needed, including adding new documentation pages to the relevant Table of Contents (toctree directive) as explained in our documentation.

@github-actions github-actions Bot added the skip-ci-tests Add this label to the PR to skip running CI tests label Nov 24, 2026
@SurbhiJainUSC SurbhiJainUSC removed the skip-ci-tests Add this label to the PR to skip running CI tests label Nov 24, 2026
@codecov

codecov Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.08676% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/maxtext/m3/configs/training_config.py 98.83% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@github-actions

Copy link
Copy Markdown
Contributor

🤖 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 gemini-review label or comment @gemini-cli /review.

@github-actions

Copy link
Copy Markdown
Contributor

🤖 I'm sorry @SurbhiJainUSC, but I was unable to process your request. Please see the logs for more details.

@bvandermoon bvandermoon left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The components.py split and ModelConfig/TrainingConfig structure look really clean. A few things to sort out before merging:

Comment thread src/maxtext/configs/components.py Resolved
@SurbhiJainUSC
SurbhiJainUSC force-pushed the m3-configs branch 2 times, most recently from 129c56f to 5190505 Compare November 25, 2026 06:47
@github-actions

Copy link
Copy Markdown
Contributor

🤖 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.

@github-actions github-actions 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.

📋 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: m3 model configuration is currently coupled to base.yml and the monolithic MaxTextConfig.
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 bvandermoon left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: context is valid now, so this test name is a bit stale (e.g. test_mesh_config_rejects_unknown_axes_and_invalid_sizes).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants