Parse HF API response into ModelInfo.
(data: dict)
| 569 | |
| 570 | |
| 571 | def _parse_model(data: dict) -> ModelInfo | None: |
| 572 | """Parse HF API response into ModelInfo.""" |
| 573 | model_id = data.get("id", "") |
| 574 | if not model_id: |
| 575 | return None |
| 576 | |
| 577 | config = data.get("config", {}) or {} |
| 578 | card_data = data.get("cardData", {}) or {} |
| 579 | |
| 580 | # Base model from card data |
| 581 | base_model_raw = card_data.get("base_model") |
| 582 | base_model = None |
| 583 | if isinstance(base_model_raw, str): |
| 584 | base_model = base_model_raw |
| 585 | elif isinstance(base_model_raw, list) and base_model_raw: |
| 586 | base_model = base_model_raw[0] |
| 587 | |
| 588 | param_count = _extract_param_count(data) |
| 589 | param_count = _normalize_param_count(param_count, model_id, base_model) |
| 590 | if param_count == 0: |
| 591 | return None |
| 592 | |
| 593 | # MoE detection. HF model configs use a variety of keys for the |
| 594 | # expert-count field — try the common ones before giving up. |
| 595 | num_experts = 0 |
| 596 | for k in ( |
| 597 | "num_local_experts", |
| 598 | "num_experts", |
| 599 | "n_routed_experts", |
| 600 | "moe_num_experts", |
| 601 | "num_moe_experts", |
| 602 | "n_local_experts", |
| 603 | ): |
| 604 | v = config.get(k, 0) |
| 605 | if isinstance(v, int) and v > num_experts: |
| 606 | num_experts = v |
| 607 | experts_per_tok = 0 |
| 608 | for k in ( |
| 609 | "num_experts_per_tok", |
| 610 | "moe_topk", |
| 611 | "moe_top_k", |
| 612 | "num_experts_per_token", |
| 613 | "top_k", |
| 614 | ): |
| 615 | v = config.get(k, 0) |
| 616 | if isinstance(v, int) and v > experts_per_tok: |
| 617 | experts_per_tok = v |
| 618 | |
| 619 | # Known-frontier MoE registry and A*B naming hints: when HF config lacks |
| 620 | # expert metadata, fall back to release-card counts or model IDs such as |
| 621 | # Qwen3.6-35B-A3B. The A3B suffix means 3B active params per token. |
| 622 | known_moe_active = _resolve_moe_active_params(param_count, model_id, base_model) |
| 623 | is_moe = num_experts > 0 or known_moe_active is not None |
| 624 | active_params = None |
| 625 | if is_moe: |
| 626 | if known_moe_active is not None: |
| 627 | active_params = known_moe_active |
| 628 | elif num_experts > 0: |