Skip to content

pyconfig → pydantic #1836

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from
Draft

Conversation

SamuelMarks
Copy link
Collaborator

@SamuelMarks SamuelMarks commented Jun 15, 2025

Description

Background

MaxText is currently engineered around pyconfig. Pyconfig—https://pypi.org/project/pyconfig/—was last updated in 2017 and has 20k monthly downloads.

Pydantic—https://pypi.org/project/pydantic/—is constantly updated and has hundreds of millions of monthly downloads.

Pydantic is the most widely used data validation library for Python.

https://docs.pydantic.dev

Summary

The TL;DR version is:

  • pydantic has become basically the standard for configuration formats, specifying the inputs and outputs (e.g., for REST APIs in FastAPI framework)
  • pydantic links in well with the Python type-checker so you can oft find errors before runtime
  • pydantic errors are clean and clear
  • with my python compiler, you can have clean CLIs with --help and GUIs and generate SQL models (SQLAlchemy) as desired
  • SDK documentation becomes much cleaner (which is good in preparation for the pypi release + hosted doc pages)

Migration

Proposed changes to the MaxText codebase:

  1. Completely remove the pyconfig dependency
    1. maybe not immediately so there’s a chance for people to easily migration of their existing setups, e.g., with new functions from_pyconfig_to_pydantic
  2. Migrate all examples, and codebase occurrences with new pydantic types
  3. Put pydantic types on a computer+human understandable hierarchy, e.g.:
    1. One global types.py, or
    2. One types.py per config occurrence (e.g., one per module if each module has a different config)
  4. Create new CLI that uses common CLI syntax (e.g., this can be automatically created using my Python compiler https://github.com/offscale/cdd-python)
  5. Migrate all shell scripts and docs to use this new CLI
    1. TBD: remove the shell scripts in favour of Python SDK usage.

Technical implementation notes

Consistency

As part of migrating the codebase across to the new configuration format various small changes were made to improve consistency. These include:

  1. self.cfgself.config:
maxtext $ rg -Fq 'self.config' -tpy --stats --json | jq '.data.stats.matches'
547
maxtext $ rg -Fq 'self.cfg' -tpy --stats --json | jq '.data.stats.matches' 
144

Tests

Tested the change on your CI.

Checklist

Before submitting this PR, please make sure (put X in square brackets):

  • I have performed a self-review of my code.
  • I have necessary comments in my code, particularly in hard-to-understand areas.
  • I have run end-to-end tests tests and provided workload links above if applicable.
  • I have made or will make corresponding changes to the doc if needed.

…d config (over pyconfig) ; [*] Replace pyconfig with pydantic
…eline/input_pipeline_interface.py,MaxText/tests/inference/page_manager_test.py,MaxText/tests/{maxengine_test,pipeline_parallelism_test}.py] Improve config percolation
…just this one file to see if tests pass on CI
…onfigs/utils.py] Add `merge_pydantic_models` ; [MaxText/tests/attention_test.py] Carefully start migration to new `class` style config
…onfig usage to match new pydantic `class`es
…ate new config class thoughout ; [MaxText/configs/types_g.py] Ensure type defaults match attention expectations ; [MaxText/configs/utils.py] `pyink`
…te new config format throughout attention_test & attentions
…, as it's not in image yet) ; [MaxText/configs/{types_g,utils}.py] Add docstrings ; linting ; [MaxText/tests/attention_test.py] Linting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant