configs refactor 1/3: split _configs.py into a package - #309
Merged
Conversation
_configs.py grew to 2591 lines (9 sub-configs, 19 per-model configs,
3 mega-extractor switch functions, a 530-line ArchitectureConfig.
from_transformers). This is the first of three mechanical refactors
that carve it into a scalable package layout. No behavior change in
this PR — every public name is still importable from mobius._configs.
src/mobius/_configs/
├── __init__.py # re-exports everything that was in _configs.py
├── _sub_configs.py # pure-data dataclasses (RoPE/Vision/Audio/Codec/TTS)
├── _quantization.py # QuantizationConfig + from_transformers
└── _base.py # BaseModelConfig, ArchitectureConfig, per-model
# subclasses, and the _extract_* helpers
Follow-up PRs in this series:
Part 2/3 — convert the _extract_audio_config / _extract_vision_config
model_type switches into a decorator-registered dispatch
so new models add a file under per_model/ instead of a
branch in the central function.
Part 3/3 — move per-model config subclasses (Gemma2Config,
MllamaConfig, NemotronHConfig, ...) into per_model/ and
carve up ArchitectureConfig.from_transformers.
Tests: 2769 passed (full src/ + tests/build_graph_test.py + cli_test.py).
Ruff: clean.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchu@microsoft.com>
Performance Comparison
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the previously monolithic mobius._configs module into a package (src/mobius/_configs/) while preserving the existing public import surface (from mobius._configs import ...). The goal is to make the configuration system easier to scale and maintain as more model families/config variants are added.
Changes:
- Introduces a new
mobius._configspackage with focused modules for sub-config dataclasses and quantization config parsing. - Moves pure-data sub-config dataclasses (RoPE/Vision/Audio/Codec/TTS) into
_sub_configs.py. - Moves
QuantizationConfiginto_quantization.pyand updates_base.pyto import these types instead of defining them inline.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/mobius/_configs/_sub_configs.py |
New module containing pure-data dataclasses for sub-configs (vision/audio/codec/TTS/RoPE). |
src/mobius/_configs/_quantization.py |
New module for QuantizationConfig and HF parsing helper. |
src/mobius/_configs/_base.py |
Updated to import the moved dataclasses/configs and remove their inline definitions. |
src/mobius/_configs/__init__.py |
New package initializer that re-exports the legacy mobius._configs public API. |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
justinchuby
added a commit
that referenced
this pull request
May 21, 2026
## Part 2 of 3 — stacked on #309 Replaces the 135-line `model_type` switch in `_extract_audio_config` with a tiny plugin registry. Each model now contributes a hook in its own file under `src/mobius/_configs/per_model/`, mutating an `audio_fields` dict or short-circuiting with a fully-formed sub-config. **Adding a new audio-capable architecture no longer requires editing `_base.py`.** ## Layout ``` src/mobius/_configs/ ├── _extractors.py # @register_audio_hook + dispatch └── per_model/ ├── _audio_default.py # audio_processor / embd_layer / speech_lora ├── _phi4mm_audio.py # phi4mm audio_token_id ├── _qwen3_asr_audio.py # thinker_config.audio_config + token ids ├── _gemma4_audio.py # short-circuit to Gemma4AudioConfig └── _sensevoice_audio.py # encoder_conf + frontend_conf mapping ``` `_extract_audio_config` in `_base.py` shrinks to a 5-line shim that triggers the `per_model` side-effect import and calls the dispatcher. **No behavior change**: every existing audio-capable model still produces the same `AudioConfig` from the same HF config. ## Hook protocol ```python @register_audio_hook def _my_model(config, parent_config, model_type: str, fields: dict) -> dict | None: if model_type != "my_model": return None fields.update(attention_dim=..., ...) return None # contribute fields, defer to default AudioConfig(**fields) # OR return {"audio": MySubclassAudioConfig(...)} # short-circuit ``` ## Deferred Vision-side conversion (also a mega-switch) is intentionally deferred to a follow-up so reviewers can verify the registry pattern on the smaller surface first. ## Tests | Suite | Result | |---|---| | `pytest src/ tests/build_graph_test.py tests/cli_test.py -n auto` | 2769 passed, 41 skipped | | `pytest tests/arch_validation_test.py -k 'sensevoice_small or phi4mm or qwen3_asr or gemma4'` | 15 passed | | Ruff | clean | --------- Signed-off-by: Justin Chu <justinchu@microsoft.com> Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part 1 of 3
src/mobius/_configs.pyhad grown to 2591 lines (9 sub-configs + 19 per-model configs + 3 mega-switch extractors + a 530-lineArchitectureConfig.from_transformers). This PR is the first of three mechanical refactors that carve it into a scalable package layout. No behavior change — every public name is still importable frommobius._configs.Follow-ups in this series
_extract_audio_config/_extract_vision_configmodel_type switches into a decorator-registered dispatch so new models add a file underper_model/instead of a branch in the central function.Gemma2Config,MllamaConfig,NemotronHConfig, …) intoper_model/and carve upArchitectureConfig.from_transformers.Tests
src/+tests/build_graph_test.py+tests/cli_test.py)