diff --git a/tests/test_config.py b/tests/test_config.py index a035d3f..b0f30e3 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -115,3 +115,33 @@ def test_warn_if_checkpoint_config_mismatch_no_warning_when_hashes_match( gconfig.warn_if_checkpoint_config_mismatch(ckpt_path) assert capsys.readouterr().err == "" + + +def test_resolve_expert_dims_default_config_inherits_hidden_dim_and_n_blocks(): + # The unset sentinel (expert_hidden_dim/n_blocks == 0 in DEFAULT_CONFIG) + # is exactly the bug fixed by resolve_expert_dims: it must not silently + # fall back to some other hardcoded default, only to the monolith's own + # hidden_dim/n_blocks, so --hidden-dim/--n-blocks reach the experts too. + router_cfg = dict(gconfig.DEFAULT_CONFIG["model"]["router"]) + assert router_cfg["expert_hidden_dim"] == 0 + assert router_cfg["expert_n_blocks"] == 0 + + hidden_dim, n_blocks = gconfig.resolve_expert_dims(router_cfg, 512, 6) + assert (hidden_dim, n_blocks) == (512, 6) + + +def test_resolve_expert_dims_missing_keys_also_inherit(): + hidden_dim, n_blocks = gconfig.resolve_expert_dims({}, 512, 6) + assert (hidden_dim, n_blocks) == (512, 6) + + +def test_resolve_expert_dims_explicit_override_wins(): + router_cfg = {"expert_hidden_dim": 128, "expert_n_blocks": 3} + hidden_dim, n_blocks = gconfig.resolve_expert_dims(router_cfg, 512, 6) + assert (hidden_dim, n_blocks) == (128, 3) + + +def test_resolve_expert_dims_partial_override_mixes_explicit_and_inherited(): + router_cfg = {"expert_hidden_dim": 128, "expert_n_blocks": 0} + hidden_dim, n_blocks = gconfig.resolve_expert_dims(router_cfg, 512, 6) + assert (hidden_dim, n_blocks) == (128, 6) # n_blocks inherited, hidden_dim not