forked from tenstorrent/tt-inference-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel_config.py
307 lines (285 loc) · 11.9 KB
/
model_config.py
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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
# SPDX-License-Identifier: Apache-2.0
#
# SPDX-FileCopyrightText: © 2025 Tenstorrent AI ULC
import re
from pathlib import Path
from dataclasses import dataclass
from typing import Set, Dict
from workflows.utils import get_version
from workflows.workflow_types import DeviceTypes
VERSION = get_version()
@dataclass(frozen=True)
class ModelConfig:
"""
All static configuration and metadata required to execute workflows for a given model.
Note: model_name is unique from hf_model_repo so that we can have multiple
implementations of the same model, for example from tt-metal and tt-forge.
For details on tt-metal/TTNN implementation context limits see: https://github.com/tenstorrent/tt-metal/tree/main/models/tt_transformers#implementation-notes
"""
device_configurations: Set[DeviceTypes]
tt_metal_commit: str
vllm_commit: str
hf_model_repo: str = None
model_name: str = None # uses defaults based on hf_model_repo
model_id: str = None # uses defaults based on hf_model_repo
impl_id: str = "tt-metal" # implementation ID
version: str = "0.0.1"
param_count: int = None
min_disk_gb: int = None
min_ram_gb: int = None
repacked: int = 0
docker_image: str = None
max_concurrency_map: Dict[DeviceTypes, int] = None
max_context_map: Dict[DeviceTypes, int] = None
status: str = "preview" # default status for all models
code_link: str = None
def __post_init__(self):
self.validate_data()
self._infer_data()
def _infer_data(self):
# Note: ONLY run this in __post_init__
# need to use __setattr__ because instance is frozen
if not self.model_name:
# use basename of HF model ID to use same format as tt-transformers
object.__setattr__(self, "model_name", Path(self.hf_model_repo).name)
if not self.model_id:
object.__setattr__(self, "model_id", self.get_default_model_id())
# use param count to detemine conservative disk and ram minimums
# these are only checked during initial model setup
if not self.param_count:
object.__setattr__(
self, "param_count", ModelConfig.infer_param_count(self.hf_model_repo)
)
if not self.min_disk_gb:
if self.repacked:
# 2x for raw fp16 weights hf cache (may already be present)
# 1x for repacked quantized copy
# 1x for tt-metal cache
# 1x for overhead
object.__setattr__(self, "min_disk_gb", self.param_count * 5)
else:
# 2x for raw fp16 weights hf cache (may already be present
# 2x for copy
object.__setattr__(self, "min_disk_gb", self.param_count * 4)
if not self.min_ram_gb:
object.__setattr__(self, "min_ram_gb", self.param_count * 5)
if not self.docker_image:
# Note: default to release image, use --dev-mode at runtime to use dev images
_default_docker_repo = "ghcr.io/tenstorrent/tt-inference-server/vllm-tt-metal-src-release-ubuntu-20.04-amd64"
_default_docker_tag = f"{VERSION}-{self.tt_metal_commit}-{self.vllm_commit}"
object.__setattr__(
self, "docker_image", f"{_default_docker_repo}:{_default_docker_tag}"
)
if not self.max_concurrency_map:
_default_max_concurrent = 32
object.__setattr__(
self,
"max_concurrency_map",
{
device: _default_max_concurrent
for device in self.device_configurations
},
)
if not self.max_context_map:
_default_max_context = 128 * 1024
object.__setattr__(
self,
"max_context_map",
{device: _default_max_context for device in self.device_configurations},
)
if not self.code_link:
# default to the commit hash of the tt-metal repo
object.__setattr__(self, "code_link", self.tt_metal_commit)
def validate_data(self):
assert (
self.hf_model_repo or self.model_name
), "either hf_model_repo or model_name must be set."
def get_default_model_id(self):
return f"id_{self.impl_id}-{self.model_name}-v{self.version}"
@staticmethod
def infer_param_count(hf_model_repo: str) -> int:
"""
Infers the parameter count (in billions) from the hf_model_repo string.
Examples:
"deepseek-ai/DeepSeek-R1-Distill-Llama-70B" -> 70
"Qwen/Qwen2.5-72B" -> 72
"meta-llama/Llama-3.1-8B" -> 8
Returns:
The inferred parameter count as an int, or None if no pattern is found.
"""
matches = re.findall(r"(\d+(?:\.\d+)?)B", hf_model_repo)
if matches:
# Take the last match which is typically the parameter count
count_str = matches[-1]
try:
# Convert to float first (to handle potential decimals) and then to int.
count_float = float(count_str)
return int(count_float)
except ValueError:
return None
return None
config_list = [
ModelConfig(
device_configurations={DeviceTypes.T3K},
hf_model_repo="Qwen/QwQ-32B",
tt_metal_commit="v0.56.0-rc51",
vllm_commit="e2e0002ac7dc",
code_link="https://github.com/tenstorrent/tt-metal/tree/v0.56.0-rc51/models/demos/llama3",
),
ModelConfig(
device_configurations={DeviceTypes.T3K},
hf_model_repo="deepseek-ai/DeepSeek-R1-Distill-Llama-70B",
tt_metal_commit="v0.56.0-rc47",
vllm_commit="e2e0002ac7dc",
code_link="https://github.com/tenstorrent/tt-metal/tree/v0.56.0-rc47/models/demos/llama3",
),
ModelConfig(
device_configurations={DeviceTypes.T3K},
hf_model_repo="Qwen/Qwen2.5-72B",
tt_metal_commit="v0.56.0-rc33",
vllm_commit="e2e0002ac7dc",
code_link="https://github.com/tenstorrent/tt-metal/tree/v0.56.0-rc33/models/demos/llama3",
),
ModelConfig(
device_configurations={DeviceTypes.T3K},
hf_model_repo="Qwen/Qwen2.5-72B-Instruct",
tt_metal_commit="v0.56.0-rc33",
vllm_commit="e2e0002ac7dc",
code_link="https://github.com/tenstorrent/tt-metal/tree/v0.56.0-rc33/models/demos/llama3",
),
ModelConfig(
device_configurations={DeviceTypes.N300, DeviceTypes.T3K},
hf_model_repo="Qwen/Qwen2.5-7B",
tt_metal_commit="v0.56.0-rc33",
vllm_commit="e2e0002ac7dc",
code_link="https://github.com/tenstorrent/tt-metal/tree/v0.56.0-rc33/models/demos/llama3",
),
ModelConfig(
device_configurations={DeviceTypes.N300, DeviceTypes.T3K},
hf_model_repo="Qwen/Qwen2.5-7B-Instruct",
tt_metal_commit="v0.56.0-rc33",
vllm_commit="e2e0002ac7dc",
code_link="https://github.com/tenstorrent/tt-metal/tree/v0.56.0-rc33/models/demos/llama3",
),
ModelConfig(
device_configurations={DeviceTypes.T3K},
hf_model_repo="meta-llama/Llama-3.3-70B-Instruct",
repacked=1,
tt_metal_commit="v0.56.0-rc47",
vllm_commit="e2e0002ac7dc",
status="ready",
code_link="https://github.com/tenstorrent/tt-metal/tree/v0.56.0-rc47/models/demos/llama3",
),
ModelConfig(
device_configurations={DeviceTypes.N150, DeviceTypes.N300, DeviceTypes.T3K},
hf_model_repo="meta-llama/Llama-3.2-11B-Vision",
tt_metal_commit="v0.56.0-rc47",
vllm_commit="e2e0002ac7dc",
code_link="https://github.com/tenstorrent/tt-metal/tree/v0.56.0-rc47/models/demos/llama3",
max_concurrency_map={
DeviceTypes.N150: 16,
DeviceTypes.N300: 16,
DeviceTypes.T3K: 16,
},
max_context_map={
DeviceTypes.N150: 64 * 1024,
DeviceTypes.N300: 128 * 1024,
DeviceTypes.T3K: 128 * 1024,
},
),
ModelConfig(
device_configurations={DeviceTypes.N150, DeviceTypes.N300, DeviceTypes.T3K},
hf_model_repo="meta-llama/Llama-3.2-11B-Vision-Instruct",
tt_metal_commit="v0.56.0-rc47",
vllm_commit="e2e0002ac7dc",
code_link="https://github.com/tenstorrent/tt-metal/tree/v0.56.0-rc47/models/demos/llama3",
max_concurrency_map={
DeviceTypes.N150: 16,
DeviceTypes.N300: 16,
DeviceTypes.T3K: 16,
},
max_context_map={
DeviceTypes.N150: 64 * 1024,
DeviceTypes.N300: 128 * 1024,
DeviceTypes.T3K: 128 * 1024,
},
),
ModelConfig(
device_configurations={DeviceTypes.N150, DeviceTypes.N300, DeviceTypes.T3K},
hf_model_repo="meta-llama/Llama-3.2-1B",
tt_metal_commit="v0.56.0-rc47",
vllm_commit="e2e0002ac7dc",
status="ready",
code_link="https://github.com/tenstorrent/tt-metal/tree/v0.56.0-rc47/models/demos/llama3",
),
ModelConfig(
device_configurations={DeviceTypes.N150, DeviceTypes.N300, DeviceTypes.T3K},
hf_model_repo="meta-llama/Llama-3.2-1B-Instruct",
tt_metal_commit="v0.56.0-rc47",
vllm_commit="e2e0002ac7dc",
status="ready",
code_link="https://github.com/tenstorrent/tt-metal/tree/v0.56.0-rc47/models/demos/llama3",
),
ModelConfig(
device_configurations={DeviceTypes.N150, DeviceTypes.N300, DeviceTypes.T3K},
hf_model_repo="meta-llama/Llama-3.2-3B",
tt_metal_commit="v0.56.0-rc47",
vllm_commit="e2e0002ac7dc",
status="ready",
code_link="https://github.com/tenstorrent/tt-metal/tree/v0.56.0-rc47/models/demos/llama3",
),
ModelConfig(
device_configurations={DeviceTypes.N150, DeviceTypes.N300, DeviceTypes.T3K},
hf_model_repo="meta-llama/Llama-3.2-3B-Instruct",
tt_metal_commit="v0.56.0-rc47",
vllm_commit="e2e0002ac7dc",
status="ready",
code_link="https://github.com/tenstorrent/tt-metal/tree/v0.56.0-rc47/models/demos/llama3",
),
ModelConfig(
device_configurations={DeviceTypes.T3K},
hf_model_repo="meta-llama/Llama-3.1-70B",
repacked=1,
tt_metal_commit="v0.56.0-rc47",
vllm_commit="e2e0002ac7dc",
status="ready",
code_link="https://github.com/tenstorrent/tt-metal/tree/v0.56.0-rc47/models/demos/llama3",
),
ModelConfig(
device_configurations={DeviceTypes.T3K},
hf_model_repo="meta-llama/Llama-3.1-70B-Instruct",
repacked=1,
tt_metal_commit="v0.56.0-rc47",
vllm_commit="e2e0002ac7dc",
status="ready",
code_link="https://github.com/tenstorrent/tt-metal/tree/v0.56.0-rc47/models/demos/llama3",
),
ModelConfig(
device_configurations={DeviceTypes.N150, DeviceTypes.N300, DeviceTypes.T3K},
hf_model_repo="meta-llama/Llama-3.1-8B",
tt_metal_commit="v0.56.0-rc47",
vllm_commit="e2e0002ac7dc",
status="ready",
code_link="https://github.com/tenstorrent/tt-metal/tree/v0.56.0-rc47/models/demos/llama3",
max_context_map={
DeviceTypes.N150: 64 * 1024,
DeviceTypes.N300: 128 * 1024,
DeviceTypes.T3K: 128 * 1024,
},
),
ModelConfig(
device_configurations={DeviceTypes.N150, DeviceTypes.N300, DeviceTypes.T3K},
hf_model_repo="meta-llama/Llama-3.1-8B-Instruct",
tt_metal_commit="v0.56.0-rc47",
vllm_commit="e2e0002ac7dc",
status="ready",
code_link="https://github.com/tenstorrent/tt-metal/tree/v0.56.0-rc47/models/demos/llama3",
max_context_map={
DeviceTypes.N150: 64 * 1024,
DeviceTypes.N300: 128 * 1024,
DeviceTypes.T3K: 128 * 1024,
},
),
]
# Generate a dictionary keyed by the model_name for each ModelConfig instance
MODEL_CONFIGS = {config.model_name: config for config in config_list}