config.py 1.86 KB
Newer Older
Jasmond L's avatar
Jasmond L committed
1
2
from typing import Optional

3
4
5
6
7
8
from transformers import AutoConfig, PretrainedConfig

from vllm.transformers_utils.configs import *  # pylint: disable=wildcard-import

_CONFIG_REGISTRY = {
    "mpt": MPTConfig,
codethazine's avatar
codethazine committed
9
    "baichuan": BaiChuanConfig,
shunxing1234's avatar
shunxing1234 committed
10
    "aquila": AquilaConfig,
Qing's avatar
Qing committed
11
    "qwen": QWenConfig,
Zhuohan Li's avatar
Zhuohan Li committed
12
13
    "RefinedWeb": RWConfig,  # For tiiuae/falcon-40b(-instruct)
    "RefinedWebModel": RWConfig,  # For tiiuae/falcon-7b(-instruct)
14
15
16
}


Jasmond L's avatar
Jasmond L committed
17
18
19
def get_config(model: str,
               trust_remote_code: bool,
               revision: Optional[str] = None) -> PretrainedConfig:
Woosuk Kwon's avatar
Woosuk Kwon committed
20
21
22
23
24
25
26
27
28
    # NOTE: Because the Mistral model in HF hub does not have
    # `configuration_mistral.py`, we cannot use `AutoConfig` to load the
    # config. Instead, we use `MistralConfig` directly.
    # NOTE: This is a hack. This does not work for local models.
    # FIXME: Remove this once the Mistral model is available in the stable
    # version of HF transformers.
    if "mistral" in model.lower():
        return MistralConfig.from_pretrained(model, revision=revision)

29
30
    try:
        config = AutoConfig.from_pretrained(
Jasmond L's avatar
Jasmond L committed
31
            model, trust_remote_code=trust_remote_code, revision=revision)
32
33
34
35
36
37
38
39
40
41
42
    except ValueError as e:
        if (not trust_remote_code and
                "requires you to execute the configuration file" in str(e)):
            err_msg = (
                "Failed to load the model config. If the model is a custom "
                "model not yet available in the HuggingFace transformers "
                "library, consider setting `trust_remote_code=True` in LLM "
                "or using the `--trust-remote-code` flag in the CLI.")
            raise RuntimeError(err_msg) from e
        else:
            raise e
43
44
    if config.model_type in _CONFIG_REGISTRY:
        config_class = _CONFIG_REGISTRY[config.model_type]
Jasmond L's avatar
Jasmond L committed
45
        config = config_class.from_pretrained(model, revision=revision)
46
    return config