Skip to content

Commit 076756e

Browse files
justinchubyCopilot
andcommitted
configs refactor part 1/3: split _configs.py into a package
_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>
1 parent 2a17a92 commit 076756e

4 files changed

Lines changed: 440 additions & 278 deletions

File tree

src/mobius/_configs/__init__.py

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
3+
4+
"""Model configuration dataclasses and HuggingFace → mobius conversion.
5+
6+
This package re-exports the public surface that used to live in
7+
``mobius._configs`` (a single 2.6k-line module). The split keeps that
8+
import path working while letting each concern grow in its own file:
9+
10+
* :mod:`._sub_configs` — pure-data dataclasses for sub-configs
11+
(RoPE, vision, audio, codec, TTS) shared across model families.
12+
* :mod:`._quantization` — :class:`QuantizationConfig` and its HF parser.
13+
* :mod:`._base` — :class:`BaseModelConfig`, :class:`ArchitectureConfig`,
14+
the per-model config subclasses, and the legacy ``_extract_*``
15+
helpers that build sub-configs from HuggingFace fields.
16+
17+
Follow-up PRs in this series convert the model-type switches inside the
18+
``_extract_*`` helpers into a registry-based dispatch, and move per-model
19+
config subclasses into their own files under ``per_model/``.
20+
"""
21+
22+
from __future__ import annotations
23+
24+
from mobius._configs._base import (
25+
DEFAULT_INT,
26+
ArchitectureConfig,
27+
BambaConfig,
28+
BaseModelConfig,
29+
CausalLMConfig,
30+
DepthAnythingConfig,
31+
EncoderConfig,
32+
Gemma2Config,
33+
Gemma3nConfig,
34+
Gemma4Config,
35+
GraniteMoeHybridConfig,
36+
JambaConfig,
37+
JetMoeConfig,
38+
LongcatFlashConfig,
39+
Mamba2Config,
40+
MambaConfig,
41+
MllamaConfig,
42+
NanoChatConfig,
43+
NemotronHConfig,
44+
Sam2Config,
45+
SegformerConfig,
46+
VisionLanguageConfig,
47+
WhisperConfig,
48+
YolosConfig,
49+
Zamba2Config,
50+
_as_int,
51+
_extract_audio_config,
52+
_extract_mrope_fields,
53+
_extract_rope_config,
54+
_extract_vision_config,
55+
_first,
56+
_first_not_none,
57+
_nested_rope_theta,
58+
_nested_rope_type,
59+
_normalize_rope_scaling,
60+
_resolve_dtype,
61+
_resolve_hidden_act,
62+
_shallow_fields,
63+
_shared_expert_size,
64+
)
65+
from mobius._configs._quantization import QuantizationConfig
66+
from mobius._configs._sub_configs import (
67+
AudioConfig,
68+
CodecDecoderConfig,
69+
CodecEncoderConfig,
70+
CodePredictorConfig,
71+
Gemma4AudioConfig,
72+
RoPEConfig,
73+
SpeakerEncoderConfig,
74+
TTSConfig,
75+
VisionConfig,
76+
)
77+
78+
__all__ = [
79+
"DEFAULT_INT",
80+
"ArchitectureConfig",
81+
"AudioConfig",
82+
"BambaConfig",
83+
"BaseModelConfig",
84+
"CausalLMConfig",
85+
"CodePredictorConfig",
86+
"CodecDecoderConfig",
87+
"CodecEncoderConfig",
88+
"DepthAnythingConfig",
89+
"EncoderConfig",
90+
"Gemma2Config",
91+
"Gemma3nConfig",
92+
"Gemma4AudioConfig",
93+
"Gemma4Config",
94+
"GraniteMoeHybridConfig",
95+
"JambaConfig",
96+
"JetMoeConfig",
97+
"LongcatFlashConfig",
98+
"Mamba2Config",
99+
"MambaConfig",
100+
"MllamaConfig",
101+
"NanoChatConfig",
102+
"NemotronHConfig",
103+
"QuantizationConfig",
104+
"RoPEConfig",
105+
"Sam2Config",
106+
"SegformerConfig",
107+
"SpeakerEncoderConfig",
108+
"TTSConfig",
109+
"VisionConfig",
110+
"VisionLanguageConfig",
111+
"WhisperConfig",
112+
"YolosConfig",
113+
"Zamba2Config",
114+
"_as_int",
115+
"_extract_audio_config",
116+
"_extract_mrope_fields",
117+
"_extract_rope_config",
118+
"_extract_vision_config",
119+
"_first",
120+
"_first_not_none",
121+
"_nested_rope_theta",
122+
"_nested_rope_type",
123+
"_normalize_rope_scaling",
124+
"_resolve_dtype",
125+
"_resolve_hidden_act",
126+
"_shallow_fields",
127+
"_shared_expert_size",
128+
]

0 commit comments

Comments
 (0)