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

3
from transformers import AutoConfig, PretrainedConfig
4

5
from vllm.transformers_utils.configs import *
6
7

_CONFIG_REGISTRY = {
8
    "baichuan": BaiChuanConfig,
GoHomeToMacDonal's avatar
GoHomeToMacDonal committed
9
    "chatglm": ChatGLMConfig,
10
    "mpt": MPTConfig,
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
def get_config(model: str,
               trust_remote_code: bool,
19
20
               revision: Optional[str] = None,
               code_revision: Optional[str] = None) -> PretrainedConfig:
21
22
    try:
        config = AutoConfig.from_pretrained(
23
24
25
26
            model,
            trust_remote_code=trust_remote_code,
            revision=revision,
            code_revision=code_revision)
27
28
29
30
31
32
33
34
35
36
37
    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
38
39
    if config.model_type in _CONFIG_REGISTRY:
        config_class = _CONFIG_REGISTRY[config.model_type]
40
41
42
        config = config_class.from_pretrained(model,
                                              revision=revision,
                                              code_revision=code_revision)
43
    return config