config.py 2.03 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 = {
GoHomeToMacDonal's avatar
GoHomeToMacDonal committed
8
    "chatglm": ChatGLMConfig,
9
    "mpt": MPTConfig,
Zhuohan Li's avatar
Zhuohan Li committed
10
11
    "RefinedWeb": RWConfig,  # For tiiuae/falcon-40b(-instruct)
    "RefinedWebModel": RWConfig,  # For tiiuae/falcon-7b(-instruct)
12
    "starcoder2": Starcoder2Config,
13
14
15
}


Jasmond L's avatar
Jasmond L committed
16
17
def get_config(model: str,
               trust_remote_code: bool,
18
19
               revision: Optional[str] = None,
               code_revision: Optional[str] = None) -> PretrainedConfig:
20
21
22
23
24
25
26
27
28
    # FIXME(woosuk): This is a temporary fix for StarCoder2.
    # Remove this when the model is supported by HuggingFace transformers.
    if "bigcode" in model and "starcoder2" in model:
        config_class = _CONFIG_REGISTRY["starcoder2"]
        config = config_class.from_pretrained(model,
                                              revision=revision,
                                              code_revision=code_revision)
        return config

29
30
    try:
        config = AutoConfig.from_pretrained(
31
32
33
34
            model,
            trust_remote_code=trust_remote_code,
            revision=revision,
            code_revision=code_revision)
35
36
37
38
39
40
41
42
43
44
45
    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
46
47
    if config.model_type in _CONFIG_REGISTRY:
        config_class = _CONFIG_REGISTRY[config.model_type]
48
49
50
        config = config_class.from_pretrained(model,
                                              revision=revision,
                                              code_revision=code_revision)
51
    return config