Skip to content

Commit afe234e

Browse files
committed
Fingerprint HyV3 routing floor
Include the routing normalization floor in HyV3 route identities because it changes expert mixing semantics, while regression tests preserve byte-identical fingerprints for legacy and unrelated consumers. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 4d631b7b-5551-4cbd-bd00-4e53f18bf75e Signed-off-by: Justin Chu <[email protected]>
1 parent 4a13b39 commit afe234e

2 files changed

Lines changed: 54 additions & 1 deletion

File tree

‎src/mobius/integrations/gguf/_builder.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6672,7 +6672,9 @@ def _logical_source_filename(reference: str | Path, resolved_path: str | Path) -
66726672
"attention_clamp": frozenset({"dbrx"}),
66736673
"encoder_fused_qkv": frozenset({"jina-bert-v3"}),
66746674
"moe_layer_frequency": frozenset({"ernie4_5-moe", "nomic-bert-moe"}),
6675-
"routing_weight_normalization_floor": frozenset({"dots1", "ernie4_5-moe", "smallthinker"}),
6675+
"routing_weight_normalization_floor": frozenset(
6676+
{"dots1", "ernie4_5-moe", "hy_v3", "smallthinker"}
6677+
),
66766678
}
66776679

66786680

‎src/mobius/integrations/gguf/_moe_cohort_test.py‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from __future__ import annotations
55

66
import dataclasses
7+
import hashlib
78
import json
89
from types import SimpleNamespace
910

@@ -21,6 +22,7 @@
2122
_graph_config_fields_for_fingerprint,
2223
_normalize_gguf_weights,
2324
_raise_for_invalid_moe_cohort_tensor_contract,
25+
_serialize_route_graph_config,
2426
)
2527
from mobius.integrations.gguf._config_mapping import gguf_to_config
2628
from mobius.integrations.gguf._tensor_mapping import map_gguf_to_hf_names
@@ -98,6 +100,54 @@ def test_new_cohort_fields_preserve_existing_route_fingerprint_bytes(
98100
assert current_bytes == legacy_bytes
99101

100102

103+
def test_hy_v3_route_fingerprint_includes_routing_floor() -> None:
104+
config = ArchitectureConfig(routing_weight_normalization_floor=6.103515625e-5)
105+
default_floor = _serialize_route_graph_config(config, "hy_v3")
106+
changed_floor = _serialize_route_graph_config(
107+
dataclasses.replace(config, routing_weight_normalization_floor=0.25),
108+
"hy_v3",
109+
)
110+
111+
assert json.loads(default_floor)["routing_weight_normalization_floor"] == pytest.approx(
112+
6.103515625e-5
113+
)
114+
assert json.loads(changed_floor)["routing_weight_normalization_floor"] == pytest.approx(
115+
0.25
116+
)
117+
assert default_floor != changed_floor
118+
assert (
119+
hashlib.sha256(default_floor.encode()).digest()
120+
!= hashlib.sha256(changed_floor.encode()).digest()
121+
)
122+
123+
124+
@pytest.mark.parametrize(
125+
"architecture",
126+
[
127+
"llama",
128+
"qwen2",
129+
"lfm2",
130+
"qwen35moe",
131+
"arctic",
132+
"dbrx",
133+
"nomic-bert-moe",
134+
"jina-bert-v3",
135+
],
136+
)
137+
def test_unaffected_route_fingerprints_ignore_routing_floor(architecture: str) -> None:
138+
config = ArchitectureConfig(routing_weight_normalization_floor=6.103515625e-5)
139+
baseline = _serialize_route_graph_config(config, architecture)
140+
changed = _serialize_route_graph_config(
141+
dataclasses.replace(config, routing_weight_normalization_floor=0.25),
142+
architecture,
143+
)
144+
145+
assert changed.encode() == baseline.encode()
146+
assert (
147+
hashlib.sha256(changed.encode()).digest() == hashlib.sha256(baseline.encode()).digest()
148+
)
149+
150+
101151
@pytest.mark.parametrize(
102152
("architecture", "included"),
103153
[
@@ -108,6 +158,7 @@ def test_new_cohort_fields_preserve_existing_route_fingerprint_bytes(
108158
frozenset({"moe_layer_frequency", "routing_weight_normalization_floor"}),
109159
),
110160
("nomic-bert-moe", frozenset({"moe_layer_frequency"})),
161+
("hy_v3", frozenset({"routing_weight_normalization_floor"})),
111162
("smallthinker", frozenset({"routing_weight_normalization_floor"})),
112163
],
113164
)

0 commit comments

Comments
 (0)