A high-throughput and memory-efficient inference and serving engine for LLMs
Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git
Synced Nov 16, 15:45 UTC
[Misc] Update config loading for Qwen2-VL and remove Granite (#8837)
Roger Wang committed
Sep 26, 2024 at 07:45 UTC
4bb98f2190aaf408cb063df5184829fb54ee5f81
7 files changed
+144
-224
docs/source/models/supported_models.rst
+1
-10
@@ -280,7 +280,7 @@ Multimodal Language Models
280
- :code:`Qwen/Qwen-VL`, :code:`Qwen/Qwen-VL-Chat`, etc.
281
-
282
* - :code:`Qwen2VLForConditionalGeneration`
283
- - Qwen2-VL (see note)
283
+ - Qwen2-VL
284
- Image\ :sup:`+` / Video\ :sup:`+`
285
- :code:`Qwen/Qwen2-VL-2B-Instruct`, :code:`Qwen/Qwen2-VL-7B-Instruct`, :code:`Qwen/Qwen2-VL-72B-Instruct`, etc.
286
-
@@ -297,15 +297,6 @@ Multimodal Language Models
297
For :code:`openbmb/MiniCPM-V-2`, the official repo doesn't work yet, so we need to use a fork (:code:`HwwwH/MiniCPM-V-2`) for now.
298
For more details, please see: https://github.com/vllm-project/vllm/pull/4087#issuecomment-2250397630
299
300
-.. note::
301
- For :code:`Qwen2-VL`, the latest release of :code:`huggingface/transformers` doesn't work yet, so we need to use a developer version (:code:`21fac7abba2a37fae86106f87fcf9974fd1e3830`) for now.
302
- This can be installed by running the following command:
303
-
304
- .. code-block:: bash
305
-
306
- pip install git+https://github.com/huggingface/transformers.git@21fac7abba2a37fae86106f87fcf9974fd1e3830
307
-
308
-----
300
301
If your model uses one of the above model architectures, you can seamlessly run your model with vLLM.
302
Otherwise, please refer to :ref:`Adding a New Model <adding_a_new_model>` and :ref:`Enabling Multimodal Inputs <enabling_multimodal_inputs>`
vllm/model_executor/models/granite.py
+1
-1
@@ -25,6 +25,7 @@ from typing import Any, Dict, Iterable, List, Optional, Tuple, Union
25
26
import torch
27
from torch import nn
28
+from transformers import GraniteConfig
29
30
from vllm.attention import Attention, AttentionMetadata
31
from vllm.config import CacheConfig, LoRAConfig
@@ -48,7 +49,6 @@ from vllm.model_executor.model_loader.weight_utils import (
49
default_weight_loader, kv_cache_scales_loader, maybe_remap_kv_scale_name)
50
from vllm.model_executor.sampling_metadata import SamplingMetadata
51
from vllm.sequence import IntermediateTensors
51
-from vllm.transformers_utils.configs.granite import GraniteConfig
52
from vllm.utils import is_hip
53
54
from .interfaces import SupportsLoRA
vllm/model_executor/models/qwen2_vl.py
+2
-3
@@ -31,12 +31,9 @@ import torch.nn as nn
31
import torch.nn.functional as F
32
from einops import rearrange, repeat
33
from PIL import Image
34
-from transformers import Qwen2VLConfig
34
from transformers.image_utils import (get_image_size,
35
infer_channel_dimension_format,
36
to_numpy_array)
38
-from transformers.models.qwen2_vl.configuration_qwen2_vl import (
39
- Qwen2VLVisionConfig)
37
from transformers.models.qwen2_vl.image_processing_qwen2_vl import (
38
make_batched_images, make_batched_videos, smart_resize)
39
@@ -66,6 +63,8 @@ from vllm.multimodal.base import MultiModalData
63
from vllm.multimodal.image import cached_get_image_processor
64
from vllm.platforms import current_platform
65
from vllm.sequence import IntermediateTensors, SequenceData
66
+from vllm.transformers_utils.configs.qwen2vl import (Qwen2VLConfig,
67
+ Qwen2VLVisionConfig)
68
from vllm.transformers_utils.processor import get_processor
69
from vllm.utils import is_cpu
70
vllm/transformers_utils/config.py
+5
-7
@@ -20,10 +20,10 @@ from vllm.logger import init_logger
20
# yapf: disable
21
from vllm.transformers_utils.configs import (ChatGLMConfig, DbrxConfig,
22
EAGLEConfig, ExaoneConfig,
23
- GraniteConfig, InternVLChatConfig,
24
- JAISConfig, MedusaConfig,
25
- MllamaConfig, MLPSpeculatorConfig,
26
- MPTConfig, NemotronConfig,
23
+ InternVLChatConfig, JAISConfig,
24
+ MedusaConfig, MllamaConfig,
25
+ MLPSpeculatorConfig, MPTConfig,
26
+ NemotronConfig, Qwen2VLConfig,
27
RWConfig, SolarConfig,
28
UltravoxConfig)
29
# yapf: enable
@@ -57,9 +57,7 @@ _CONFIG_REGISTRY: Dict[str, Type[PretrainedConfig]] = {
57
"nemotron": NemotronConfig,
58
"solar": SolarConfig,
59
"ultravox": UltravoxConfig,
60
- # Granite can be removed from here once we have upgraded to
61
- # transformers 4.45+
62
- "granite": GraniteConfig,
60
+ "qwen2_vl": Qwen2VLConfig,
61
**_CONFIG_REGISTRY_OVERRIDE_HF
62
}
63
vllm/transformers_utils/configs/__init__.py
+4
-4
@@ -6,7 +6,6 @@ from vllm.transformers_utils.configs.exaone import ExaoneConfig
6
# tiiuae/falcon-7b(-instruct) models. Newer Falcon models will use the
7
# `FalconConfig` class from the official HuggingFace transformers library.
8
from vllm.transformers_utils.configs.falcon import RWConfig
9
-from vllm.transformers_utils.configs.granite import GraniteConfig
9
from vllm.transformers_utils.configs.internvl import InternVLChatConfig
10
from vllm.transformers_utils.configs.jais import JAISConfig
11
from vllm.transformers_utils.configs.medusa import MedusaConfig
@@ -14,6 +13,8 @@ from vllm.transformers_utils.configs.mllama import MllamaConfig
13
from vllm.transformers_utils.configs.mlp_speculator import MLPSpeculatorConfig
14
from vllm.transformers_utils.configs.mpt import MPTConfig
15
from vllm.transformers_utils.configs.nemotron import NemotronConfig
16
+from vllm.transformers_utils.configs.qwen2vl import (Qwen2VLConfig,
17
+ Qwen2VLVisionConfig)
18
from vllm.transformers_utils.configs.solar import SolarConfig
19
from vllm.transformers_utils.configs.ultravox import UltravoxConfig
20
@@ -32,7 +33,6 @@ __all__ = [
33
"NemotronConfig",
34
"SolarConfig",
35
"UltravoxConfig",
35
- # Granite can be removed from here once we have upgraded to
36
- # transformers 4.45+
37
- "GraniteConfig",
36
+ "Qwen2VLConfig",
37
+ "Qwen2VLVisionConfig",
38
]
vllm/transformers_utils/configs/granite.py
deleted
-199
@@ -1,199 +0,0 @@
1
-# coding=utf-8
2
-# Copyright 2024 EleutherAI and the HuggingFace Inc. team. All rights reserved.
3
-#
4
-# This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX
5
-# and OPT implementations in this library. It has been modified from its
6
-# original forms to accommodate minor architectural differences compared
7
-# to GPT-NeoX and OPT used by the Meta AI team that trained the model.
8
-#
9
-# Licensed under the Apache License, Version 2.0 (the "License");
10
-# you may not use this file except in compliance with the License.
11
-# You may obtain a copy of the License at
12
-#
13
-# http://www.apache.org/licenses/LICENSE-2.0
14
-#
15
-# Unless required by applicable law or agreed to in writing, software
16
-# distributed under the License is distributed on an "AS IS" BASIS,
17
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
-# See the License for the specific language governing permissions and
19
-# limitations under the License.
20
-"""Granite model configuration"""
21
-
22
-from transformers.configuration_utils import PretrainedConfig
23
-from transformers.modeling_rope_utils import rope_config_validation
24
-from transformers.utils import logging
25
-
26
-logger = logging.get_logger(__name__)
27
-
28
-
29
-class GraniteConfig(PretrainedConfig):
30
- r"""
31
- This is the configuration class to store the configuration of
32
- a [`GraniteModel`]. It is used to instantiate an Granite
33
- model according to the specified arguments, defining the model architecture.
34
- Instantiating a configuration with the defaults will yield a similar
35
- configuration to that of the Granite-3B.
36
-
37
- Configuration objects inherit from [`PretrainedConfig`] and can be used to
38
- control the model outputs. Read the documentation from [`PretrainedConfig`]
39
- for more information.
40
-
41
-
42
- Args:
43
- vocab_size (`int`, *optional*, defaults to 32000):
44
- Vocabulary size of the Granite model. Defines the number of
45
- different tokens that can be represented by the `inputs_ids`
46
- passed when calling [`GraniteModel`]
47
- hidden_size (`int`, *optional*, defaults to 4096):
48
- Dimension of the hidden representations.
49
- intermediate_size (`int`, *optional*, defaults to 11008):
50
- Dimension of the MLP representations.
51
- num_hidden_layers (`int`, *optional*, defaults to 32):
52
- Number of hidden layers in the Transformer decoder.
53
- num_attention_heads (`int`, *optional*, defaults to 32):
54
- Number of attention heads for each attention layer in the
55
- Transformer decoder.
56
- num_key_value_heads (`int`, *optional*):
57
- This is the number of key_value heads that should be used to
58
- implement Grouped Query Attention. If
59
- `num_key_value_heads=num_attention_heads`, the model will use Multi
60
- Head Attention (MHA), if `num_key_value_heads=1` the model will use
61
- Multi Query Attention (MQA) otherwise GQA is used. When converting
62
- a multi-head checkpoint to a GQA checkpoint, each group key and
63
- value head should be constructed by meanpooling all the original
64
- heads within that group. For more details checkout
65
- [this paper](https://arxiv.org/pdf/2305.13245.pdf). If it is not
66
- specified, will default to `num_attention_heads`.
67
- hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
68
- The non-linear activation function (function or string) in the
69
- decoder.
70
- max_position_embeddings (`int`, *optional*, defaults to 2048):
71
- The maximum sequence length that this model might ever be used with.
72
- initializer_range (`float`, *optional*, defaults to 0.02):
73
- The standard deviation of the truncated_normal_initializer for
74
- initializing all weight matrices.
75
- rms_norm_eps (`float`, *optional*, defaults to 1e-06):
76
- The epsilon used by the rms normalization layers.
77
- use_cache (`bool`, *optional*, defaults to `True`):
78
- Whether or not the model should return the last key/values
79
- attentions (not used by all models). Only relevant if
80
- `config.is_decoder=True`.
81
- pad_token_id (`int`, *optional*):
82
- Padding token id.
83
- bos_token_id (`int`, *optional*, defaults to 1):
84
- Beginning of stream token id.
85
- eos_token_id (`int`, *optional*, defaults to 2):
86
- End of stream token id.
87
- tie_word_embeddings (`bool`, *optional*, defaults to `False`):
88
- Whether to tie weight embeddings
89
- rope_theta (`float`, *optional*, defaults to 10000.0):
90
- The base period of the RoPE embeddings.
91
- rope_scaling (`Dict`, *optional*):
92
- Dictionary containing the scaling configuration for the RoPE
93
- embeddings. Currently supports two scaling strategies: linear and
94
- dynamic. Their scaling factor must be a float greater than 1. The
95
- expected format is
96
- `{"type": strategy name, "factor": scaling factor}`.
97
- When using this flag, don't update `max_position_embeddings` to
98
- the expected new maximum. See the following thread for more
99
- information on how these scaling strategies behave:
100
- https://www.reddit.com/r/LocalLLaMA/comments/14mrgpr/dynamically_scaled_rope_further_increases/.
101
- This is an experimental feature, subject to breaking API changes
102
- in future versions.
103
- attention_bias (`bool`, *optional*, defaults to `False`):
104
- Whether to use a bias in the query, key, value and output
105
- projection layers during self-attention.
106
- attention_dropout (`float`, *optional*, defaults to 0.0):
107
- The dropout ratio for the attention probabilities.
108
- mlp_bias (`bool`, *optional*, defaults to `False`):
109
- Whether to use a bias in up_proj, down_proj and gate_proj layers
110
- in the MLP layers.
111
- embedding_multiplier (`float`, *optional*, defaults to 1.0):
112
- embedding multiplier
113
- logits_scaling (`float`, *optional*, defaults to 1.0):
114
- divisor for output logits
115
- residual_multiplier (`float`, *optional*, defaults to 1.0):
116
- residual multiplier
117
- attention_multiplier (`float`, *optional*, defaults to 1.0):
118
- attention multiplier
119
-
120
- ```python
121
- >>> from transformers import GraniteModel, GraniteConfig
122
-
123
- >>> # Initializing a Granite granite-3b style configuration
124
- >>> configuration = GraniteConfig()
125
-
126
- >>> # Initializing a model from the granite-7b style configuration
127
- >>> model = GraniteModel(configuration)
128
-
129
- >>> # Accessing the model configuration
130
- >>> configuration = model.config
131
- ```"""
132
-
133
- model_type = "granite"
134
- keys_to_ignore_at_inference = ["past_key_values"]
135
-
136
- def __init__(
137
- self,
138
- vocab_size=32000,
139
- hidden_size=4096,
140
- intermediate_size=11008,
141
- num_hidden_layers=32,
142
- num_attention_heads=32,
143
- num_key_value_heads=None,
144
- hidden_act="silu",
145
- max_position_embeddings=2048,
146
- initializer_range=0.02,
147
- rms_norm_eps=1e-6,
148
- use_cache=True,
149
- pad_token_id=None,
150
- bos_token_id=1,
151
- eos_token_id=2,
152
- tie_word_embeddings=False,
153
- rope_theta=10000.0,
154
- rope_scaling=None,
155
- attention_bias=False,
156
- attention_dropout=0.0,
157
- mlp_bias=False,
158
- embedding_multiplier=1.0,
159
- logits_scaling=1.0,
160
- residual_multiplier=1.0,
161
- attention_multiplier=1.0,
162
- **kwargs,
163
- ):
164
- self.vocab_size = vocab_size
165
- self.max_position_embeddings = max_position_embeddings
166
- self.hidden_size = hidden_size
167
- self.intermediate_size = intermediate_size
168
- self.num_hidden_layers = num_hidden_layers
169
- self.num_attention_heads = num_attention_heads
170
-
171
- # for backward compatibility
172
- if num_key_value_heads is None:
173
- num_key_value_heads = num_attention_heads
174
-
175
- self.num_key_value_heads = num_key_value_heads
176
- self.hidden_act = hidden_act
177
- self.initializer_range = initializer_range
178
- self.rms_norm_eps = rms_norm_eps
179
- self.use_cache = use_cache
180
- self.rope_theta = rope_theta
181
- self.rope_scaling = rope_scaling
182
- self.attention_bias = attention_bias
183
- self.attention_dropout = attention_dropout
184
- self.mlp_bias = mlp_bias
185
-
186
- self.embedding_multiplier = embedding_multiplier
187
- self.logits_scaling = logits_scaling
188
- self.residual_multiplier = residual_multiplier
189
- self.attention_multiplier = attention_multiplier
190
-
191
- super().__init__(
192
- pad_token_id=pad_token_id,
193
- bos_token_id=bos_token_id,
194
- eos_token_id=eos_token_id,
195
- tie_word_embeddings=tie_word_embeddings,
196
- **kwargs,
197
- )
198
-
199
- rope_config_validation(self)
vllm/transformers_utils/configs/qwen2vl.py
new
+131
@@ -0,0 +1,131 @@
1
+# coding=utf-8
2
+# Copyright 2024 The Qwen team, Alibaba Group and the HuggingFace Inc. team.
3
+# All rights reserved.
4
+#
5
+# Licensed under the Apache License, Version 2.0 (the "License");
6
+# you may not use this file except in compliance with the License.
7
+# You may obtain a copy of the License at
8
+#
9
+# http://www.apache.org/licenses/LICENSE-2.0
10
+#
11
+# Unless required by applicable law or agreed to in writing, software
12
+# distributed under the License is distributed on an "AS IS" BASIS,
13
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+# See the License for the specific language governing permissions and
15
+# limitations under the License.
16
+"""Qwen2VL model configuration"""
17
+
18
+import os
19
+from typing import Union
20
+
21
+from transformers import PretrainedConfig
22
+
23
+
24
+class Qwen2VLVisionConfig(PretrainedConfig):
25
+ model_type = "qwen2_vl"
26
+
27
+ def __init__(
28
+ self,
29
+ depth=32,
30
+ embed_dim=1280,
31
+ hidden_size=3584,
32
+ hidden_act="quick_gelu",
33
+ mlp_ratio=4,
34
+ num_heads=16,
35
+ in_channels=3,
36
+ patch_size=14,
37
+ spatial_merge_size=2,
38
+ temporal_patch_size=2,
39
+ **kwargs,
40
+ ):
41
+ super().__init__(**kwargs)
42
+
43
+ self.depth = depth
44
+ self.embed_dim = embed_dim
45
+ self.hidden_size = hidden_size
46
+ self.hidden_act = hidden_act
47
+ self.mlp_ratio = mlp_ratio
48
+ self.num_heads = num_heads
49
+ self.in_channels = in_channels
50
+ self.patch_size = patch_size
51
+ self.spatial_merge_size = spatial_merge_size
52
+ self.temporal_patch_size = temporal_patch_size
53
+
54
+ @classmethod
55
+ def from_pretrained(cls, pretrained_model_name_or_path: Union[str,
56
+ os.PathLike],
57
+ **kwargs) -> "PretrainedConfig":
58
+ cls._set_token_in_kwargs(kwargs)
59
+
60
+ config_dict, kwargs = cls.get_config_dict(
61
+ pretrained_model_name_or_path, **kwargs)
62
+
63
+ if config_dict.get("model_type") == "qwen2_vl":
64
+ config_dict = config_dict["vision_config"]
65
+
66
+ return cls.from_dict(config_dict, **kwargs)
67
+
68
+
69
+class Qwen2VLConfig(PretrainedConfig):
70
+
71
+ def __init__(
72
+ self,
73
+ vocab_size=152064,
74
+ hidden_size=8192,
75
+ intermediate_size=29568,
76
+ num_hidden_layers=80,
77
+ num_attention_heads=64,
78
+ num_key_value_heads=8,
79
+ hidden_act="silu",
80
+ max_position_embeddings=32768,
81
+ initializer_range=0.02,
82
+ rms_norm_eps=1e-05,
83
+ use_cache=True,
84
+ tie_word_embeddings=False,
85
+ rope_theta=1000000.0,
86
+ use_sliding_window=False,
87
+ sliding_window=4096,
88
+ max_window_layers=80,
89
+ attention_dropout=0.0,
90
+ vision_config=None,
91
+ rope_scaling=None,
92
+ **kwargs,
93
+ ):
94
+ if isinstance(vision_config, dict):
95
+ self.vision_config = Qwen2VLVisionConfig(**vision_config)
96
+ elif vision_config is None:
97
+ self.vision_config = Qwen2VLVisionConfig()
98
+
99
+ self.vocab_size = vocab_size
100
+ self.max_position_embeddings = max_position_embeddings
101
+ self.hidden_size = hidden_size
102
+ self.intermediate_size = intermediate_size
103
+ self.num_hidden_layers = num_hidden_layers
104
+ self.num_attention_heads = num_attention_heads
105
+ self.use_sliding_window = use_sliding_window
106
+ self.sliding_window = sliding_window
107
+ self.max_window_layers = max_window_layers
108
+
109
+ # for backward compatibility
110
+ if num_key_value_heads is None:
111
+ num_key_value_heads = num_attention_heads
112
+
113
+ self.num_key_value_heads = num_key_value_heads
114
+ self.hidden_act = hidden_act
115
+ self.initializer_range = initializer_range
116
+ self.rms_norm_eps = rms_norm_eps
117
+ self.use_cache = use_cache
118
+ self.rope_theta = rope_theta
119
+ self.attention_dropout = attention_dropout
120
+ self.rope_scaling = rope_scaling
121
+
122
+ # NOTE: the following section from original transformers config
123
+ # for Qwen2-VL is commented out to address rope config loading issue
124
+ #
125
+ # if self.rope_scaling is not None and "type" in self.rope_scaling:
126
+ # if self.rope_scaling["type"] == "mrope":
127
+ # self.rope_scaling["type"] = "default"
128
+ # self.rope_scaling["rope_type"] = self.rope_scaling["type"]
129
+ # rope_config_validation(self)
130
+
131
+ super().__init__(tie_word_embeddings=tie_word_embeddings, **kwargs)