Skip to content

Commit bb9be82

Browse files
justinchubyCopilot
andcommitted
Add registry/model config_class consistency test
Catches silent bugs where a registry entry specifies a specialized config_class but the model class has a different one (e.g. the LongcatFlash bug where missing config_class caused wrong ONNX graphs). Co-authored-by: Copilot <[email protected]> Signed-off-by: Justin Chu <[email protected]>
1 parent 6dad6e3 commit bb9be82

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

‎tests/arch_validation_test.py‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,45 @@ def test_graph_shapes_consistent(self, model_type: str, model_id: str):
209209
assert output.name, f"{component_name} has an unnamed output"
210210

211211
del pkg
212+
213+
214+
class TestRegistryConsistency:
215+
"""Verify registry and model class metadata are consistent."""
216+
217+
def test_config_class_declared_on_model(self):
218+
"""Registry config_class must match the model class declaration.
219+
220+
When a registry entry specifies a non-default config_class,
221+
the model class must also declare it (not silently inherit a
222+
different one from a parent).
223+
224+
Catches bugs like LongcatFlash where a missing config_class
225+
declaration caused the model to load with the wrong config,
226+
producing incorrect ONNX graphs without any error.
227+
"""
228+
from mobius._configs import ArchitectureConfig, CausalLMConfig
229+
230+
issues = []
231+
for model_type, reg in registry._map.items():
232+
reg_config = reg.config_class
233+
if reg_config is None or reg_config is ArchitectureConfig:
234+
continue
235+
236+
cls = reg.module_class
237+
model_config = getattr(cls, "config_class", None)
238+
239+
# If registry specifies a specialized config (not the base
240+
# CausalLMConfig), the model class should agree — unless the
241+
# model doesn't define config_class at all (multimodal models
242+
# that aren't CausalLMModel subclasses rely on the registry).
243+
if (
244+
reg_config is not CausalLMConfig
245+
and model_config is not None
246+
and model_config is not reg_config
247+
):
248+
issues.append(
249+
f"{model_type}: registry says "
250+
f"{reg_config.__name__} but {cls.__name__} "
251+
f"has {getattr(model_config, '__name__', None)}"
252+
)
253+
assert not issues, "Registry/model config_class mismatch:\n" + "\n".join(issues)

0 commit comments

Comments
 (0)