-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathconstants.py
More file actions
271 lines (233 loc) · 7.27 KB
/
constants.py
File metadata and controls
271 lines (233 loc) · 7.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
#!/usr/bin/env python
# Copyright (c) 2024, 2025 Oracle and/or its affiliates.
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
"""
aqua.shaperecommend.constants
~~~~~~~~~~~~~~
This module contains constants used in Aqua GPU Recommendation for Models.
LLAMA_REQUIRED_FIELDS refer to fields necessary for calculating model memory for GQA Architecture Models
MOE_REQUIRED_FIELDS refer to fields necessary for Mixture of Experts (MoE) Architecture Models
NEXT_QUANT suggests the next quantization level based on the current quantization (if applied) or the model weights (if no quantization yet)
EXCLUDED_MODELS contains a set of model identifiers that are known to be unsupported for shape recommendation.
ARCHITECTURE_TYPE identifies the detected model architecture category for strategy selection.
SUPPORTED_TASKS defines the set of model task types that the recommender can handle.
"""
# ---------------------------------------------------------------------------
# Architecture type identifiers (used by StrategyFactory)
# ---------------------------------------------------------------------------
ARCH_TEXT_GENERATION = "text_generation"
ARCH_MULTIMODAL = "multimodal"
ARCH_EMBEDDING = "embedding"
ARCH_AUDIO = "audio"
ARCH_UNSUPPORTED = "unsupported"
# ---------------------------------------------------------------------------
# Supported task tags (from HF / OCI freeform_tags)
# ---------------------------------------------------------------------------
SUPPORTED_TASKS = {
"text_generation",
"text-generation",
"image_text_to_text",
"image-text-to-text",
"feature_extraction",
"feature-extraction",
"automatic_speech_recognition",
"automatic-speech-recognition",
}
# ---------------------------------------------------------------------------
# Model types that map to specific architecture strategies
# ---------------------------------------------------------------------------
MULTIMODAL_MODEL_TYPES = {
"llava",
"llava_next",
"llava_onevision",
"qwen2_vl",
"internvl",
"phi3_v",
"pixtral",
"idefics2",
"idefics3",
"mllama",
"paligemma",
}
EMBEDDING_MODEL_TYPES = {
"bert",
"roberta",
"xlm-roberta",
"xlm_roberta",
"modernbert",
"nomic_bert",
}
# Architecture class names in HF 'architectures' list that identify embedding-only models
EMBEDDING_ARCHITECTURE_KEYWORDS = {
"embeddingmodel",
"formaskedlm",
"xlmrobertamodel", # Jina embeddings (XLMRobertaModel)
"bertmodel", # bert-base etc.
"robertamodel", # roberta-base etc.
}
AUDIO_MODEL_TYPES = {
"whisper",
}
# Architecture keywords in HF 'architectures' list that indicate multimodal
MULTIMODAL_ARCHITECTURE_KEYWORDS = {
"llava",
"vila",
"nemotron_vl",
"nemotron_nano_vl",
"qwen2vl",
"internvl",
"phi3v",
"pixtral",
"idefics",
"paligemma",
"mllama",
}
LLAMA_REQUIRED_FIELDS = [
"num_hidden_layers",
"hidden_size",
"num_attention_heads",
"num_key_value_heads",
"head_dim",
"intermediate_size",
"vocab_size",
]
MOE_REQUIRED_FIELDS = LLAMA_REQUIRED_FIELDS + ["num_local_experts", "intermediate_size"]
NEXT_QUANT = {
"float32": ["8bit", "4bit"],
"bfloat16": ["8bit", "4bit"],
"float16": ["8bit", "4bit"],
"int8": ["4bit"],
"fp8": ["4bit"],
"8bit": ["4bit"],
"int4": ["No smaller quantization available"],
"4bit": ["No smaller quantization available"],
}
RUNTIME_WEIGHTS = {
"use_bfloat16": "bfloat16",
"use_fp16": "float16",
"use_fp32": "float32",
"use_int8": "int8",
"use_int4": "int4",
"use_bfloat32": "bfloat32",
}
TEXT_GENERATION = "text_generation"
SAFETENSORS = "safetensors"
QUANT_METHODS = [
"aqlm",
"awq",
"deepspeedfp",
"tpu_int8",
"fp8",
"ptpc_fp8",
"fbgemm_fp8",
"modelopt",
"modelopt_fp4",
"marlin",
"bitblas",
"gguf",
"gptq_marlin_24",
"gptq_marlin",
"gptq_bitblas",
"awq_marlin",
"gptq",
"compressed-tensors",
"bitsandbytes",
"qqq",
"hqq",
"experts_int8",
"neuron_quant",
"ipex",
"quark",
"moe_wna16",
"torchao",
"auto-round",
"rtn",
"inc",
"mxfp4",
]
IN_FLIGHT_QUANTIZATION = {"4bit"} # vLLM only supports 4bit in-flight-quantization
VLLM_PARAMS_FAMILY = "VLLM_PARAMS"
VLLM_ENV = "VLLM"
QUANT_FLAG = "--quantization"
WEIGHT_DTYPE_FLAG = "--dtype"
MAX_MODEL_LEN_FLAG = "--max-model-len"
TROUBLESHOOT_MSG = "The selected model is too large to fit on standard GPU shapes with the current configuration.\nAs troubleshooting, we have suggested the two largest available GPU shapes using the smallest quantization level ('4bit') to maximize chances of fitting the model. "
VLLM_PARAMS = {
"max_model_len": "--max-model-len",
"in_flight_quant": "--quantization bitsandbytes --load-format bitsandbytes",
"trust_remote_code": "--trust-remote-code",
"task_embedding": "--task embedding",
"task_transcribe": "--task transcribe",
"limit_mm_per_prompt_image": '--limit-mm-per-prompt {"image": 1}',
"limit_mm_per_prompt_audio": '--limit-mm-per-prompt {"audio": 1}',
"limit_mm_per_prompt_video": '--limit-mm-per-prompt {"video": 1}',
"enforce_eager": "--enforce-eager",
"dtype": "--dtype",
}
# ---------------------------------------------------------------------------
# Multimodal model characteristics that affect vLLM param selection
# ---------------------------------------------------------------------------
# Models supporting multiple images per prompt (image_grid_pinpoints or tiling)
# These benefit from higher --limit-mm-per-prompt image counts
MULTI_IMAGE_MODEL_TYPES = {
"llava_onevision",
"qwen2_vl",
"idefics3",
"mllama", # Llama 3.2 Vision supports multi-image
}
# Models that require --enforce-eager due to custom CUDA graph limitations
# Typically those with non-standard attention patterns or custom ops
ENFORCE_EAGER_MODEL_TYPES = {
"phi3_v", # Phi-3-Vision needs eager mode
"idefics2", # IDEFICS-2 needs eager mode
"paligemma", # PaliGemma can have issues with CUDA graphs
}
# Large-context embedding models with LLM backbones (hidden_size threshold)
# These use decoder architectures and benefit from context-length tuning
LARGE_EMBEDDING_HIDDEN_SIZE_THRESHOLD = (
1024 # >= this => "large" LLM-backbone embedding
)
# Whisper distilled model threshold: decoder_layers below this => distilled variant
WHISPER_DISTILLED_DECODER_LAYERS_THRESHOLD = 4
DEFAULT_WEIGHT_SIZE = "float32"
DEFAULT_MAX_SEQ_LEN = 4096
BITS_AND_BYTES_8BIT = "8bit"
BITS_AND_BYTES_4BIT = "4bit"
BITSANDBYTES = "bitsandbytes"
QUANT_MAPPING = {
"float32": 4,
"bfloat16": 2,
"float16": 2,
"fp16": 2,
"half": 2,
"int8": 1,
"fp8": 1,
"8bit": 1,
"4bit": 0.5,
"int4": 0.5,
}
SHAPE_MAP = {
"NVIDIA_GPU": "GPU",
"AMD_ROME": "CPU",
"GENERIC": "CPU",
"LEGACY": "CPU",
"ARM": "CPU",
"UNKNOWN_ENUM_VALUE": "N/A",
}
# Models that are truly unsupported (encoder-decoder text gen, no vLLM support)
EXCLUDED_MODELS = {
"t5",
"bart",
"albert",
"t5gemma",
}
# Encoder-decoder text models that cannot be served via standard vLLM text generation
ENCODER_DECODER_TEXT_MODELS = {
"t5",
"bart",
"albert",
"t5gemma",
"ul2",
"longt5",
"pegasus",
}