diff --git a/services/hwfit/hf_discovery.py b/services/hwfit/hf_discovery.py index 3bea44931..7d7d5eeb1 100644 --- a/services/hwfit/hf_discovery.py +++ b/services/hwfit/hf_discovery.py @@ -210,9 +210,11 @@ def _entry_from_collection_item(collection, item, source): if repo_prefix and not repo_id.startswith(repo_prefix): return None raw_params = item.get("numParameters") or 0 - active = None + # Read the name even when HF gives a total: it is the only source of the + # MoE active size (e.g. "-35B-A3B"), which the speed estimate depends on. + name_params, active = _parse_params_from_name(repo_id) if not raw_params: - raw_params, active = _parse_params_from_name(repo_id) + raw_params = name_params param_label, raw_params = _format_params(raw_params) if not raw_params: return None diff --git a/tests/test_hwfit_hf_discovery_moe.py b/tests/test_hwfit_hf_discovery_moe.py new file mode 100644 index 000000000..58f6b098c --- /dev/null +++ b/tests/test_hwfit_hf_discovery_moe.py @@ -0,0 +1,33 @@ +from services.hwfit.hf_discovery import _entry_from_collection_item + +_SOURCE = {"owner": "Qwen", "provider": "Qwen"} +_COLLECTION = {"title": "Qwen3.6"} + + +def _item(repo_id, num_params): + item = {"id": repo_id, "type": "model", "pipeline_tag": "text-generation"} + if num_params is not None: + item["numParameters"] = num_params + return item + + +def test_moe_active_size_is_read_from_name_when_hf_reports_total(): + # HF collection items carry numParameters for nearly every repo. The MoE + # active size only exists in the name, so it must still be parsed. + entry = _entry_from_collection_item(_COLLECTION, _item("Qwen/Qwen3.6-35B-A3B", 35_951_822_704), _SOURCE) + assert entry["parameters_raw"] == 35_951_822_704 + assert entry["is_moe"] is True + assert entry["active_parameters"] == 3_000_000_000 + + +def test_moe_entry_without_hf_count_falls_back_to_name(): + entry = _entry_from_collection_item(_COLLECTION, _item("Qwen/Qwen3-Coder-30B-A3B-Instruct", None), _SOURCE) + assert entry["parameters_raw"] == 30_000_000_000 + assert entry["is_moe"] is True + assert entry["active_parameters"] == 3_000_000_000 + + +def test_dense_entry_keeps_hf_count_and_is_not_moe(): + entry = _entry_from_collection_item(_COLLECTION, _item("Qwen/Qwen3.6-27B", 27_781_427_952), _SOURCE) + assert entry["parameters_raw"] == 27_781_427_952 + assert "is_moe" not in entry