From fd7748ea2c6affc4804bf7bd731b19f7bc5be2c2 Mon Sep 17 00:00:00 2001 From: Ming Liang Dai Date: Wed, 22 Nov 2023 22:30:38 +0000 Subject: [PATCH 1/4] config support multiple architectures --- ADDING_NEW_MODEL.md | 2 +- .../openllm_core/config/configuration_auto.py | 23 ++++++++++++++++++- .../config/configuration_baichuan.py | 4 ++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/ADDING_NEW_MODEL.md b/ADDING_NEW_MODEL.md index 15996e193..cbac1de57 100644 --- a/ADDING_NEW_MODEL.md +++ b/ADDING_NEW_MODEL.md @@ -33,7 +33,7 @@ default parameters, as well as additional fields for the models. ### Entrypoint After establishing the model config and implementation class, register them in -the `__init__` file, and the tuple under `CONFIG_MAPPING_NAMES` in [openllm-core/src/openllm_core/config/configuration_auto.py#CONFIG_MAPPING_NAMES](https://github.com/bentoml/OpenLLM/blob/main/openllm-core/src/openllm_core/config/configuration_auto.py#L30). Basically you need to register `ModelConfig` classes with its given name for `for_model` to use. +the `__init__` file, and the tuple under `CONFIG_MAPPING_NAMES` in [openllm-core/src/openllm_core/config/configuration_auto.py#CONFIG_MAPPING_NAMES](https://github.com/bentoml/OpenLLM/blob/main/openllm-core/src/openllm_core/config/configuration_auto.py#L24) and `CONFIG_SUPPORTED_ARCHITECTURES_MAPPING` tuple in [openllm-core/src/openllm_core/config/configuration_auto.py#CONFIG_SUPPORTED_ARCHITECTURES_MAPPING](https://github.com/bentoml/OpenLLM/blob/main/openllm-core/src/openllm_core/config/configuration_auto.py#L45). Basically you need to register `ModelConfig` classes with its given name for `for_model` to use. ## Raise a Pull Request diff --git a/openllm-core/src/openllm_core/config/configuration_auto.py b/openllm-core/src/openllm_core/config/configuration_auto.py index 6ff0098a4..ce7df1994 100644 --- a/openllm-core/src/openllm_core/config/configuration_auto.py +++ b/openllm-core/src/openllm_core/config/configuration_auto.py @@ -42,6 +42,27 @@ ) ) +# NOTE: This is the entrypoint when adding new model config +CONFIG_SUPPORTED_ARCHITECTURES_MAPPING = OrderedDict( + sorted( + [ + ('FlanT5Config', ('T5ForConditionalGeneration',)), + ('BaichuanConfig', ('BaiChuanForCausalLM', 'BaichuanForCausalLM')), + ('ChatGLMConfig', ('ChatGLMModel',)), + ('FalconConfig', ('FalconForCausalLM',)), + ('GPTNeoXConfig', ('GPTNeoXForCausalLM',)), + ('DollyV2Config', ('GPTNeoXForCausalLM',)), + ('StableLMConfig', ('GPTNeoXForCausalLM',)), + ('LlamaConfig', ('LlamaForCausalLM',)), + ('MPTConfig', ('MPTForCausalLM',)), + ('OPTConfig', ('OPTForCausalLM',)), + ('PhiConfig', ('PhiForCausalLM',)), + ('StarCoderConfig', ('GPTBigCodeForCausalLM',)), + ('MistralConfig', ('MistralForCausalLM',)), + ('YiConfig', ('YiForCausalLM',)), + ] + ) +) class _LazyConfigMapping(OrderedDictType, ReprMixin): def __init__(self, mapping: OrderedDict[LiteralString, LiteralString]): @@ -180,7 +201,7 @@ def infer_class_from_name(cls, name: str) -> type[openllm_core.LLMConfig]: @classmethod def _CONFIG_MAPPING_NAMES_TO_ARCHITECTURE(cls) -> dict[str, str]: if cls._cached_mapping is None: - AutoConfig._cached_mapping = {v.__config__['architecture']: k for k, v in CONFIG_MAPPING.items()} + AutoConfig._cached_mapping = {arch: name for name in CONFIG_MAPPING_NAMES for arch in CONFIG_SUPPORTED_ARCHITECTURES_MAPPING[CONFIG_MAPPING_NAMES[name]]} return AutoConfig._cached_mapping @classmethod diff --git a/openllm-core/src/openllm_core/config/configuration_baichuan.py b/openllm-core/src/openllm_core/config/configuration_baichuan.py index d1c232726..143969aad 100644 --- a/openllm-core/src/openllm_core/config/configuration_baichuan.py +++ b/openllm-core/src/openllm_core/config/configuration_baichuan.py @@ -34,6 +34,10 @@ class BaichuanConfig(openllm_core.LLMConfig): 'fireballoon/baichuan-vicuna-chinese-7b', 'fireballoon/baichuan-vicuna-7b', 'hiyouga/baichuan-7b-sft', + 'baichuan-inc/baichuan2-7b-base', + 'baichuan-inc/baichuan2-7b-chat', + 'baichuan-inc/baichuan2-13b-base', + 'baichuan-inc/baichuan2-13b-chat', ], } From ce272713ff378ac748f7e7eeb10783d217a76717 Mon Sep 17 00:00:00 2001 From: Aaron <29749331+aarnphm@users.noreply.github.com> Date: Fri, 24 Nov 2023 02:05:21 -0500 Subject: [PATCH 2/4] chore: only support baichuan2 from now on Signed-off-by: Aaron <29749331+aarnphm@users.noreply.github.com> --- ADDING_NEW_MODEL.md | 2 +- .../openllm_core/config/configuration_auto.py | 24 +------------------ .../config/configuration_baichuan.py | 8 +------ 3 files changed, 3 insertions(+), 31 deletions(-) diff --git a/ADDING_NEW_MODEL.md b/ADDING_NEW_MODEL.md index cbac1de57..15996e193 100644 --- a/ADDING_NEW_MODEL.md +++ b/ADDING_NEW_MODEL.md @@ -33,7 +33,7 @@ default parameters, as well as additional fields for the models. ### Entrypoint After establishing the model config and implementation class, register them in -the `__init__` file, and the tuple under `CONFIG_MAPPING_NAMES` in [openllm-core/src/openllm_core/config/configuration_auto.py#CONFIG_MAPPING_NAMES](https://github.com/bentoml/OpenLLM/blob/main/openllm-core/src/openllm_core/config/configuration_auto.py#L24) and `CONFIG_SUPPORTED_ARCHITECTURES_MAPPING` tuple in [openllm-core/src/openllm_core/config/configuration_auto.py#CONFIG_SUPPORTED_ARCHITECTURES_MAPPING](https://github.com/bentoml/OpenLLM/blob/main/openllm-core/src/openllm_core/config/configuration_auto.py#L45). Basically you need to register `ModelConfig` classes with its given name for `for_model` to use. +the `__init__` file, and the tuple under `CONFIG_MAPPING_NAMES` in [openllm-core/src/openllm_core/config/configuration_auto.py#CONFIG_MAPPING_NAMES](https://github.com/bentoml/OpenLLM/blob/main/openllm-core/src/openllm_core/config/configuration_auto.py#L30). Basically you need to register `ModelConfig` classes with its given name for `for_model` to use. ## Raise a Pull Request diff --git a/openllm-core/src/openllm_core/config/configuration_auto.py b/openllm-core/src/openllm_core/config/configuration_auto.py index ce7df1994..431d66914 100644 --- a/openllm-core/src/openllm_core/config/configuration_auto.py +++ b/openllm-core/src/openllm_core/config/configuration_auto.py @@ -42,28 +42,6 @@ ) ) -# NOTE: This is the entrypoint when adding new model config -CONFIG_SUPPORTED_ARCHITECTURES_MAPPING = OrderedDict( - sorted( - [ - ('FlanT5Config', ('T5ForConditionalGeneration',)), - ('BaichuanConfig', ('BaiChuanForCausalLM', 'BaichuanForCausalLM')), - ('ChatGLMConfig', ('ChatGLMModel',)), - ('FalconConfig', ('FalconForCausalLM',)), - ('GPTNeoXConfig', ('GPTNeoXForCausalLM',)), - ('DollyV2Config', ('GPTNeoXForCausalLM',)), - ('StableLMConfig', ('GPTNeoXForCausalLM',)), - ('LlamaConfig', ('LlamaForCausalLM',)), - ('MPTConfig', ('MPTForCausalLM',)), - ('OPTConfig', ('OPTForCausalLM',)), - ('PhiConfig', ('PhiForCausalLM',)), - ('StarCoderConfig', ('GPTBigCodeForCausalLM',)), - ('MistralConfig', ('MistralForCausalLM',)), - ('YiConfig', ('YiForCausalLM',)), - ] - ) -) - class _LazyConfigMapping(OrderedDictType, ReprMixin): def __init__(self, mapping: OrderedDict[LiteralString, LiteralString]): self._mapping = mapping @@ -201,7 +179,7 @@ def infer_class_from_name(cls, name: str) -> type[openllm_core.LLMConfig]: @classmethod def _CONFIG_MAPPING_NAMES_TO_ARCHITECTURE(cls) -> dict[str, str]: if cls._cached_mapping is None: - AutoConfig._cached_mapping = {arch: name for name in CONFIG_MAPPING_NAMES for arch in CONFIG_SUPPORTED_ARCHITECTURES_MAPPING[CONFIG_MAPPING_NAMES[name]]} + AutoConfig._cached_mapping = {v.__config__['architecture']: k for k, v in CONFIG_MAPPING.items()} return AutoConfig._cached_mapping @classmethod diff --git a/openllm-core/src/openllm_core/config/configuration_baichuan.py b/openllm-core/src/openllm_core/config/configuration_baichuan.py index 143969aad..4265deb99 100644 --- a/openllm-core/src/openllm_core/config/configuration_baichuan.py +++ b/openllm-core/src/openllm_core/config/configuration_baichuan.py @@ -21,19 +21,13 @@ class BaichuanConfig(openllm_core.LLMConfig): 'url': 'https://github.com/baichuan-inc/Baichuan-7B', 'requirements': ['cpm-kernels'], 'backend': ('pt', 'vllm'), - 'architecture': 'BaiChuanForCausalLM', + 'architecture': 'BaichuanForCausalLM', # NOTE: See the following # https://huggingface.co/baichuan-inc/Baichuan-13B-Chat/blob/19ef51ba5bad8935b03acd20ff04a269210983bc/modeling_baichuan.py#L555 # https://huggingface.co/baichuan-inc/Baichuan-13B-Chat/blob/main/generation_config.json # https://github.com/baichuan-inc/Baichuan-13B/issues/25 'default_id': 'baichuan-inc/baichuan-7b', 'model_ids': [ - 'baichuan-inc/baichuan-7b', - 'baichuan-inc/baichuan-13b-base', - 'baichuan-inc/baichuan-13b-chat', - 'fireballoon/baichuan-vicuna-chinese-7b', - 'fireballoon/baichuan-vicuna-7b', - 'hiyouga/baichuan-7b-sft', 'baichuan-inc/baichuan2-7b-base', 'baichuan-inc/baichuan2-7b-chat', 'baichuan-inc/baichuan2-13b-base', From c76fdb498ccc8489096e9d3fa941f2e560aeba1c Mon Sep 17 00:00:00 2001 From: Aaron <29749331+aarnphm@users.noreply.github.com> Date: Fri, 24 Nov 2023 02:06:05 -0500 Subject: [PATCH 3/4] chore: update notes Signed-off-by: Aaron <29749331+aarnphm@users.noreply.github.com> --- changelog.d/728.change.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/728.change.md diff --git a/changelog.d/728.change.md b/changelog.d/728.change.md new file mode 100644 index 000000000..c41db5373 --- /dev/null +++ b/changelog.d/728.change.md @@ -0,0 +1 @@ +Only baichuan2 and baichuan3 are supported. We dropped baichuan 1 support From 14bf582e3e1f2c37ab3ae2b62bf587b82a1d819f Mon Sep 17 00:00:00 2001 From: Aaron <29749331+aarnphm@users.noreply.github.com> Date: Fri, 24 Nov 2023 02:06:38 -0500 Subject: [PATCH 4/4] chore: run script [skip ci] Signed-off-by: Aaron <29749331+aarnphm@users.noreply.github.com> --- README.md | 14 ++++++-------- openllm-python/README.md | 14 ++++++-------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index e1a96b2f2..3e614fe70 100644 --- a/README.md +++ b/README.md @@ -226,12 +226,10 @@ openllm query 'What are large language models?' You can specify any of the following Baichuan models via `openllm start`: -- [baichuan-inc/baichuan-7b](https://huggingface.co/baichuan-inc/baichuan-7b) -- [baichuan-inc/baichuan-13b-base](https://huggingface.co/baichuan-inc/baichuan-13b-base) -- [baichuan-inc/baichuan-13b-chat](https://huggingface.co/baichuan-inc/baichuan-13b-chat) -- [fireballoon/baichuan-vicuna-chinese-7b](https://huggingface.co/fireballoon/baichuan-vicuna-chinese-7b) -- [fireballoon/baichuan-vicuna-7b](https://huggingface.co/fireballoon/baichuan-vicuna-7b) -- [hiyouga/baichuan-7b-sft](https://huggingface.co/hiyouga/baichuan-7b-sft) +- [baichuan-inc/baichuan2-7b-base](https://huggingface.co/baichuan-inc/baichuan2-7b-base) +- [baichuan-inc/baichuan2-7b-chat](https://huggingface.co/baichuan-inc/baichuan2-7b-chat) +- [baichuan-inc/baichuan2-13b-base](https://huggingface.co/baichuan-inc/baichuan2-13b-base) +- [baichuan-inc/baichuan2-13b-chat](https://huggingface.co/baichuan-inc/baichuan2-13b-chat) ### Supported backends @@ -249,7 +247,7 @@ OpenLLM will support vLLM and PyTorch as default backend. By default, it will us To install vLLM, run `pip install "openllm[vllm]"` ```bash -TRUST_REMOTE_CODE=True openllm start baichuan-inc/baichuan-7b --backend vllm +TRUST_REMOTE_CODE=True openllm start baichuan-inc/baichuan2-7b-base --backend vllm ``` @@ -264,7 +262,7 @@ TRUST_REMOTE_CODE=True openllm start baichuan-inc/baichuan-7b --backend vllm ```bash -TRUST_REMOTE_CODE=True openllm start baichuan-inc/baichuan-7b --backend pt +TRUST_REMOTE_CODE=True openllm start baichuan-inc/baichuan2-7b-base --backend pt ``` diff --git a/openllm-python/README.md b/openllm-python/README.md index e1a96b2f2..3e614fe70 100644 --- a/openllm-python/README.md +++ b/openllm-python/README.md @@ -226,12 +226,10 @@ openllm query 'What are large language models?' You can specify any of the following Baichuan models via `openllm start`: -- [baichuan-inc/baichuan-7b](https://huggingface.co/baichuan-inc/baichuan-7b) -- [baichuan-inc/baichuan-13b-base](https://huggingface.co/baichuan-inc/baichuan-13b-base) -- [baichuan-inc/baichuan-13b-chat](https://huggingface.co/baichuan-inc/baichuan-13b-chat) -- [fireballoon/baichuan-vicuna-chinese-7b](https://huggingface.co/fireballoon/baichuan-vicuna-chinese-7b) -- [fireballoon/baichuan-vicuna-7b](https://huggingface.co/fireballoon/baichuan-vicuna-7b) -- [hiyouga/baichuan-7b-sft](https://huggingface.co/hiyouga/baichuan-7b-sft) +- [baichuan-inc/baichuan2-7b-base](https://huggingface.co/baichuan-inc/baichuan2-7b-base) +- [baichuan-inc/baichuan2-7b-chat](https://huggingface.co/baichuan-inc/baichuan2-7b-chat) +- [baichuan-inc/baichuan2-13b-base](https://huggingface.co/baichuan-inc/baichuan2-13b-base) +- [baichuan-inc/baichuan2-13b-chat](https://huggingface.co/baichuan-inc/baichuan2-13b-chat) ### Supported backends @@ -249,7 +247,7 @@ OpenLLM will support vLLM and PyTorch as default backend. By default, it will us To install vLLM, run `pip install "openllm[vllm]"` ```bash -TRUST_REMOTE_CODE=True openllm start baichuan-inc/baichuan-7b --backend vllm +TRUST_REMOTE_CODE=True openllm start baichuan-inc/baichuan2-7b-base --backend vllm ``` @@ -264,7 +262,7 @@ TRUST_REMOTE_CODE=True openllm start baichuan-inc/baichuan-7b --backend vllm ```bash -TRUST_REMOTE_CODE=True openllm start baichuan-inc/baichuan-7b --backend pt +TRUST_REMOTE_CODE=True openllm start baichuan-inc/baichuan2-7b-base --backend pt ```