Files
DeepInfer/deepinfer/model_config_loader.py
2026-10-20 12:09:42 +08:00

24 lines
886 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from __future__ import annotations
from pathlib import Path
from deepinfer import AttrDict
def load_model_config(model: str) -> AttrDict:
"""加载 V4.1 的 model_cfg(AttrDict)。
`model` 必须指向 HF 目录;配置与权重来自同一目录。
返回的 model_cfg 至少包含:
- model_cfg.architecture:HF architectures 中声明且通过注册表校验的架构名
- model_cfg.gpt:模型结构(num_attention_heads / hidden_size / vocab_size / kv_lora_rank ...)
- model_cfg.vl_aligner:必需的 HF 视觉/投影结构
"""
# HF 配置解析只处理数据,不导入模型实现。
from deepinfer.hugging_face import load_hf_model_config
model_cfg = load_hf_model_config(Path(model) / "config.json")
assert "vl_aligner" in model_cfg, "Only multimodal HF models with vl_aligner are supported"
return model_cfg