specbench-cli 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- specbench_cli-0.1.0.dist-info/METADATA +236 -0
- specbench_cli-0.1.0.dist-info/RECORD +22 -0
- specbench_cli-0.1.0.dist-info/WHEEL +4 -0
- specbench_cli-0.1.0.dist-info/entry_points.txt +2 -0
- specbench_cli-0.1.0.dist-info/licenses/LICENSE +201 -0
- speculation_benchmark/__init__.py +45 -0
- speculation_benchmark/backends/__init__.py +27 -0
- speculation_benchmark/backends/base.py +73 -0
- speculation_benchmark/backends/llamacpp.py +660 -0
- speculation_benchmark/cli.py +661 -0
- speculation_benchmark/config.py +415 -0
- speculation_benchmark/hf_jobs.py +379 -0
- speculation_benchmark/publisher.py +196 -0
- speculation_benchmark/runner.py +479 -0
- speculation_benchmark/suites/__init__.py +19 -0
- speculation_benchmark/suites/base.py +96 -0
- speculation_benchmark/suites/bundled/assets/sample_architecture.png +0 -0
- speculation_benchmark/suites/bundled/assets/sample_bar_chart.png +0 -0
- speculation_benchmark/suites/bundled/coding_smoke.jsonl +5 -0
- speculation_benchmark/suites/bundled/multimodal_smoke.jsonl +2 -0
- speculation_benchmark/suites/loaders.py +715 -0
- speculation_benchmark/visualize.py +1228 -0
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import re
|
|
4
|
+
from collections.abc import Iterable
|
|
5
|
+
from datetime import datetime, timezone
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Any, Literal
|
|
8
|
+
from uuid import uuid4
|
|
9
|
+
|
|
10
|
+
import yaml
|
|
11
|
+
from pydantic import BaseModel, Field, field_validator
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
_UNQUANTIZED_LABELS = {"F32", "FP32", "F16", "FP16", "BF16"}
|
|
15
|
+
_GGUF_QUANT_RE = re.compile(
|
|
16
|
+
r"(?:^|[._-])("
|
|
17
|
+
r"(?:UD-)?(?:IQ[1-4]_[A-Z0-9]+|Q[1-8]_[A-Z0-9]+(?:_[A-Z0-9]+)?|TQ[12]_[0-9]+)"
|
|
18
|
+
r"|MXFP4(?:_[A-Z0-9]+)?"
|
|
19
|
+
r"|FP8(?:_[A-Z0-9]+)?"
|
|
20
|
+
r"|BF16|FP16|F16|FP32|F32"
|
|
21
|
+
r")(?:[._-]|$)",
|
|
22
|
+
re.IGNORECASE,
|
|
23
|
+
)
|
|
24
|
+
_SPLIT_SHARD_RE = re.compile(r"-(\d{5})-of-\d{5}\.gguf$", re.IGNORECASE)
|
|
25
|
+
|
|
26
|
+
# Sidecar GGUF filename prefixes auto-discovered by llama.cpp (common/download.cpp) per --spec-type.
|
|
27
|
+
SPEC_TYPE_SIDECAR_PREFIXES: dict[str, tuple[str, ...]] = {
|
|
28
|
+
"draft-dflash": ("dflash-",),
|
|
29
|
+
"draft-dflash2": ("dflash2-", "dflash-"),
|
|
30
|
+
"draft-mtp": ("mtp-",),
|
|
31
|
+
"draft-eagle3": ("eagle3-",),
|
|
32
|
+
"draft-dspark": ("dspark-",),
|
|
33
|
+
"draft-lilicorr": ("lilicorr-", "dflash-"),
|
|
34
|
+
}
|
|
35
|
+
_SIDECAR_FALLBACK_QUANTS: tuple[str, ...] = ("Q8_0", "BF16", "F16", "FP16", "Q4_K_M")
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def sidecar_prefixes_for_spec_type(spec_type: str | None) -> tuple[str, ...]:
|
|
39
|
+
"""Return ordered sidecar GGUF filename prefixes for a llama.cpp `--spec-type` string."""
|
|
40
|
+
if not spec_type:
|
|
41
|
+
return ()
|
|
42
|
+
prefixes: list[str] = []
|
|
43
|
+
for part in spec_type.split(","):
|
|
44
|
+
key = part.strip().lower()
|
|
45
|
+
for prefix in SPEC_TYPE_SIDECAR_PREFIXES.get(key, ()):
|
|
46
|
+
if prefix not in prefixes:
|
|
47
|
+
prefixes.append(prefix)
|
|
48
|
+
return tuple(prefixes)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def select_hf_sidecar_file(
|
|
52
|
+
repo_files: Iterable[str],
|
|
53
|
+
spec_type: str | None,
|
|
54
|
+
preferred_quant: str | None = None,
|
|
55
|
+
) -> str | None:
|
|
56
|
+
"""Mirror llama.cpp's sidecar auto-discovery for a HF repo file list and `--spec-type`."""
|
|
57
|
+
prefixes = sidecar_prefixes_for_spec_type(spec_type)
|
|
58
|
+
if not prefixes:
|
|
59
|
+
return None
|
|
60
|
+
|
|
61
|
+
for prefix in prefixes:
|
|
62
|
+
candidates: list[str] = []
|
|
63
|
+
for path_str in repo_files:
|
|
64
|
+
name = Path(path_str).name
|
|
65
|
+
lower = name.lower()
|
|
66
|
+
if not lower.endswith(".gguf"):
|
|
67
|
+
continue
|
|
68
|
+
if not lower.startswith(prefix):
|
|
69
|
+
continue
|
|
70
|
+
shard_match = _SPLIT_SHARD_RE.search(name)
|
|
71
|
+
if shard_match and shard_match.group(1) != "00001":
|
|
72
|
+
continue
|
|
73
|
+
candidates.append(path_str)
|
|
74
|
+
|
|
75
|
+
if not candidates:
|
|
76
|
+
continue
|
|
77
|
+
if len(candidates) == 1:
|
|
78
|
+
return candidates[0]
|
|
79
|
+
|
|
80
|
+
if preferred_quant:
|
|
81
|
+
wanted = preferred_quant.strip().upper()
|
|
82
|
+
for candidate in sorted(candidates):
|
|
83
|
+
q = extract_quant_label(None, candidate)
|
|
84
|
+
if q and q.upper() == wanted:
|
|
85
|
+
return candidate
|
|
86
|
+
|
|
87
|
+
for fallback_q in _SIDECAR_FALLBACK_QUANTS:
|
|
88
|
+
for candidate in sorted(candidates):
|
|
89
|
+
q = extract_quant_label(None, candidate)
|
|
90
|
+
if q and q.upper() == fallback_q:
|
|
91
|
+
return candidate
|
|
92
|
+
|
|
93
|
+
return sorted(candidates)[0]
|
|
94
|
+
|
|
95
|
+
return None
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def extract_quant_label(repo: str | None, filename: str | None = None) -> str | None:
|
|
99
|
+
"""Extract a quant label (e.g. 'UD-Q4_K_M', 'Q8_0', 'BF16') from `repo[:quant]` or GGUF filename."""
|
|
100
|
+
if repo and ":" in repo:
|
|
101
|
+
tag = repo.rsplit(":", 1)[1].strip()
|
|
102
|
+
if tag:
|
|
103
|
+
return tag
|
|
104
|
+
if filename:
|
|
105
|
+
stem = Path(filename).stem
|
|
106
|
+
stem = re.sub(r"-\d{5}-of-\d{5}$", "", stem)
|
|
107
|
+
match = _GGUF_QUANT_RE.search(stem)
|
|
108
|
+
if match:
|
|
109
|
+
return match.group(1).upper()
|
|
110
|
+
return None
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def is_quantized_label(quant: str | None) -> bool | None:
|
|
114
|
+
"""Return False for full/half float (F32/F16/BF16), True for quantized labels, None if unknown."""
|
|
115
|
+
if not quant:
|
|
116
|
+
return None
|
|
117
|
+
normalized = quant.strip().upper()
|
|
118
|
+
if not normalized:
|
|
119
|
+
return None
|
|
120
|
+
return normalized not in _UNQUANTIZED_LABELS
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
DRAFT_TOKEN_PRESETS: dict[str, tuple[int, ...]] = {
|
|
124
|
+
"default": (0, 4, 8, 12),
|
|
125
|
+
"spec-only": (4, 8, 12),
|
|
126
|
+
"fine": (0, 1, 2, 4, 8, 12, 16),
|
|
127
|
+
}
|
|
128
|
+
DEFAULT_DRAFT_TOKENS: list[int] = list(DRAFT_TOKEN_PRESETS["default"])
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def resolve_draft_tokens(value: str | list[int] | tuple[int, ...]) -> list[int]:
|
|
132
|
+
"""Resolve a draft-token preset name (e.g. 'default', 'spec-only') or integer list/CSV."""
|
|
133
|
+
if isinstance(value, str):
|
|
134
|
+
stripped = value.strip()
|
|
135
|
+
if stripped in DRAFT_TOKEN_PRESETS:
|
|
136
|
+
return list(DRAFT_TOKEN_PRESETS[stripped])
|
|
137
|
+
return [int(part.strip()) for part in stripped.split(",") if part.strip()]
|
|
138
|
+
return [int(v) for v in value]
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def _default_run_id() -> str:
|
|
142
|
+
ts = datetime.now(timezone.utc).strftime("%Y%m%dT%H%M%SZ")
|
|
143
|
+
return f"{ts}-{uuid4().hex[:8]}"
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
class ModelSpec(BaseModel):
|
|
147
|
+
"""Model and speculator specification supporting both single-repo and dual-repo HF setups.
|
|
148
|
+
|
|
149
|
+
- Single-repo bundled speculator (e.g. MTP bundled in HF repo):
|
|
150
|
+
set `model_repo="org/model-gguf:Q4_K_M"` and leave `speculator_repo=None`.
|
|
151
|
+
- Single-repo with explicit draft GGUF in the same repo:
|
|
152
|
+
set `model_repo="org/model-gguf:Q4_K_M"` and `speculator_file="draft-Q8_0.gguf"`.
|
|
153
|
+
- Dual-repo (main model + separate speculator HF repo):
|
|
154
|
+
set both `model_repo` and `speculator_repo` (with optional `speculator_file` / `spec_type`).
|
|
155
|
+
"""
|
|
156
|
+
|
|
157
|
+
model_repo: str = Field(
|
|
158
|
+
...,
|
|
159
|
+
description="Hugging Face repo for the target model, optionally with :quant (e.g. org/repo:Q4_K_M).",
|
|
160
|
+
)
|
|
161
|
+
model_file: str | None = Field(
|
|
162
|
+
default=None,
|
|
163
|
+
description="Optional explicit GGUF filename inside model_repo (--hf-file).",
|
|
164
|
+
)
|
|
165
|
+
speculator_repo: str | None = Field(
|
|
166
|
+
default=None,
|
|
167
|
+
description="Optional separate Hugging Face repo for the speculator/draft model (--spec-draft-hf).",
|
|
168
|
+
)
|
|
169
|
+
speculator_file: str | None = Field(
|
|
170
|
+
default=None,
|
|
171
|
+
description="Optional explicit GGUF filename for the speculator/draft model (--spec-draft-model).",
|
|
172
|
+
)
|
|
173
|
+
spec_type: str | None = Field(
|
|
174
|
+
default=None,
|
|
175
|
+
description=(
|
|
176
|
+
"llama.cpp --spec-type (draft-simple, draft-eagle3, draft-dflash, draft-mtp, "
|
|
177
|
+
"ngram-mod, ngram-simple, ngram-map-k, ngram-map-k4v, ngram-cache). "
|
|
178
|
+
"If omitted, defaults to 'draft-mtp' for single-repo bundled speculators and "
|
|
179
|
+
"'draft-simple' when speculator_repo or speculator_file is provided "
|
|
180
|
+
"(llama.cpp defaults --spec-type to 'none' unless explicitly passed)."
|
|
181
|
+
),
|
|
182
|
+
)
|
|
183
|
+
mmproj: str | None = Field(
|
|
184
|
+
default=None,
|
|
185
|
+
description="Optional local path or URL for mmproj override. By default llama serve auto-discovers mmproj from model_repo.",
|
|
186
|
+
)
|
|
187
|
+
no_mmproj: bool = Field(
|
|
188
|
+
default=False,
|
|
189
|
+
description="Pass --no-mmproj to disable multimodal projector auto-download/loading.",
|
|
190
|
+
)
|
|
191
|
+
model_quant: str | None = Field(
|
|
192
|
+
default=None,
|
|
193
|
+
description="Optional quant label override (auto-inferred from model_repo ':quant' or model_file).",
|
|
194
|
+
)
|
|
195
|
+
speculator_quant: str | None = Field(
|
|
196
|
+
default=None,
|
|
197
|
+
description=(
|
|
198
|
+
"Optional speculator quant label override. When omitted, auto-detected from "
|
|
199
|
+
"the speculator GGUF loaded/discovered by llama.cpp for --spec-type (or from "
|
|
200
|
+
"speculator_repo/speculator_file), falling back to model_quant for in-file bundled MTP."
|
|
201
|
+
),
|
|
202
|
+
)
|
|
203
|
+
|
|
204
|
+
@property
|
|
205
|
+
def model_repo_base(self) -> str:
|
|
206
|
+
"""Target model HF repo ID with any trailing `:quant` tag stripped."""
|
|
207
|
+
return self.model_repo.rsplit(":", 1)[0] if ":" in self.model_repo else self.model_repo
|
|
208
|
+
|
|
209
|
+
@property
|
|
210
|
+
def speculator_mode(self) -> Literal["separate_repo", "same_repo_file", "bundled"]:
|
|
211
|
+
if self.speculator_repo:
|
|
212
|
+
return "separate_repo"
|
|
213
|
+
if self.speculator_file:
|
|
214
|
+
return "same_repo_file"
|
|
215
|
+
return "bundled"
|
|
216
|
+
|
|
217
|
+
@property
|
|
218
|
+
def effective_speculator_repo(self) -> str:
|
|
219
|
+
return self.speculator_repo or self.model_repo_base
|
|
220
|
+
|
|
221
|
+
@property
|
|
222
|
+
def resolved_spec_type(self) -> str:
|
|
223
|
+
if self.spec_type:
|
|
224
|
+
return self.spec_type
|
|
225
|
+
if self.speculator_repo or self.speculator_file:
|
|
226
|
+
return "draft-simple"
|
|
227
|
+
return "draft-mtp"
|
|
228
|
+
|
|
229
|
+
@property
|
|
230
|
+
def resolved_model_quant(self) -> str | None:
|
|
231
|
+
return self.model_quant or extract_quant_label(self.model_repo, self.model_file)
|
|
232
|
+
|
|
233
|
+
@property
|
|
234
|
+
def is_quantized(self) -> bool | None:
|
|
235
|
+
return is_quantized_label(self.resolved_model_quant)
|
|
236
|
+
|
|
237
|
+
def resolve_speculator_file(self, detected_file: str | None = None) -> str:
|
|
238
|
+
"""Return explicit `speculator_file` or an auto-detected sidecar/draft filename."""
|
|
239
|
+
return self.speculator_file or detected_file or ""
|
|
240
|
+
|
|
241
|
+
def resolve_speculator_quant(self, detected_file: str | None = None) -> str | None:
|
|
242
|
+
"""Resolve speculator quant, preferring explicit overrides, then auto-detected file."""
|
|
243
|
+
if self.speculator_quant:
|
|
244
|
+
return self.speculator_quant
|
|
245
|
+
if self.speculator_repo or self.speculator_file:
|
|
246
|
+
return (
|
|
247
|
+
extract_quant_label(self.speculator_repo, self.speculator_file)
|
|
248
|
+
or extract_quant_label(None, detected_file)
|
|
249
|
+
)
|
|
250
|
+
if detected_file:
|
|
251
|
+
detected_quant = extract_quant_label(None, detected_file)
|
|
252
|
+
if detected_quant:
|
|
253
|
+
return detected_quant
|
|
254
|
+
spec_types = [t.strip() for t in self.resolved_spec_type.split(",") if t.strip()]
|
|
255
|
+
if spec_types and not any(t.startswith("draft-") for t in spec_types):
|
|
256
|
+
return None
|
|
257
|
+
return self.resolved_model_quant
|
|
258
|
+
|
|
259
|
+
@property
|
|
260
|
+
def resolved_speculator_quant(self) -> str | None:
|
|
261
|
+
return self.resolve_speculator_quant()
|
|
262
|
+
|
|
263
|
+
@property
|
|
264
|
+
def speculator_is_quantized(self) -> bool | None:
|
|
265
|
+
return is_quantized_label(self.resolved_speculator_quant)
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
class ServerConfig(BaseModel):
|
|
269
|
+
"""Configuration for launching local `llama serve` (or `llama-server`)."""
|
|
270
|
+
|
|
271
|
+
llama_cmd: list[str] = Field(
|
|
272
|
+
default_factory=lambda: ["llama", "serve"],
|
|
273
|
+
description="Base command to start llama.cpp server (e.g. ['llama', 'serve'] or ['/path/to/llama-server']).",
|
|
274
|
+
)
|
|
275
|
+
host: str = "127.0.0.1"
|
|
276
|
+
port: int = Field(
|
|
277
|
+
default=8090,
|
|
278
|
+
ge=0,
|
|
279
|
+
le=65535,
|
|
280
|
+
description="Port to bind llama serve to. Use 0 to auto-select a free local port.",
|
|
281
|
+
)
|
|
282
|
+
ctx_size: int | None = Field(default=8192, ge=0)
|
|
283
|
+
n_gpu_layers: str | None = Field(
|
|
284
|
+
default="all",
|
|
285
|
+
description="Passed to -ngl ('all', 'auto', or integer string).",
|
|
286
|
+
)
|
|
287
|
+
flash_attn: str | None = Field(
|
|
288
|
+
default="on",
|
|
289
|
+
description="Passed to --flash-attn ('on', 'off', 'auto', or None to omit).",
|
|
290
|
+
)
|
|
291
|
+
parallel: int = Field(default=1, ge=1)
|
|
292
|
+
draft_n_min: int | None = Field(default=None, ge=0)
|
|
293
|
+
draft_p_min: float | None = Field(default=None, ge=0.0, le=1.0)
|
|
294
|
+
extra_args: list[str] = Field(
|
|
295
|
+
default_factory=list,
|
|
296
|
+
description="Additional raw CLI flags passed through to llama serve.",
|
|
297
|
+
)
|
|
298
|
+
startup_timeout_s: float = Field(default=600.0, gt=0)
|
|
299
|
+
request_timeout_s: float = Field(default=300.0, gt=0)
|
|
300
|
+
hf_token: str | None = Field(
|
|
301
|
+
default=None,
|
|
302
|
+
description="Optional HF token passed via HF_TOKEN env var to llama serve.",
|
|
303
|
+
)
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
class SuiteSpec(BaseModel):
|
|
307
|
+
"""Defines one capability benchmark suite (curated JSONL or Hugging Face dataset)."""
|
|
308
|
+
|
|
309
|
+
capability: str = Field(..., description="Capability label, e.g. 'coding' or 'multimodal'.")
|
|
310
|
+
source: str = Field(
|
|
311
|
+
...,
|
|
312
|
+
description=(
|
|
313
|
+
"Suite source: local .jsonl/.json path, 'preset:<name>', or 'hf:<repo_id>'."
|
|
314
|
+
),
|
|
315
|
+
)
|
|
316
|
+
hf_config: str | None = Field(default=None, description="Optional HF dataset config/subset name.")
|
|
317
|
+
hf_split: str | None = Field(default=None, description="Optional HF dataset split (auto-picks test/validation/train when omitted).")
|
|
318
|
+
limit: int | None = Field(default=20, ge=1, description="Maximum number of samples to evaluate.")
|
|
319
|
+
prompt_column: str | None = Field(default=None, description="Override prompt column name for generic HF datasets.")
|
|
320
|
+
image_columns: list[str] | None = Field(default=None, description="Override image column name(s) for generic HF datasets.")
|
|
321
|
+
id_column: str | None = Field(default=None, description="Override sample ID column name for generic HF datasets.")
|
|
322
|
+
system_prompt: str | None = Field(default=None, description="Optional system prompt prepended to every sample.")
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
class GenerationConfig(BaseModel):
|
|
326
|
+
"""Sampling and completion settings sent to /v1/chat/completions."""
|
|
327
|
+
|
|
328
|
+
max_tokens: int = Field(default=512, ge=1)
|
|
329
|
+
temperature: float = Field(default=0.0, ge=0.0)
|
|
330
|
+
seed: int | None = 42
|
|
331
|
+
extra_body: dict[str, Any] = Field(default_factory=dict)
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
class OutputConfig(BaseModel):
|
|
335
|
+
"""Local artifact and Hugging Face Hub dataset publishing settings."""
|
|
336
|
+
|
|
337
|
+
output_dir: Path = Field(default=Path("results"))
|
|
338
|
+
hf_dataset_repo: str | None = Field(
|
|
339
|
+
default="merve/drafter-bench",
|
|
340
|
+
description="Target Hugging Face dataset repo ID (default: 'merve/drafter-bench').",
|
|
341
|
+
)
|
|
342
|
+
private: bool = False
|
|
343
|
+
append: bool = Field(
|
|
344
|
+
default=True,
|
|
345
|
+
description="When pushing to Hub, merge with existing summary/samples rows if the dataset repo already exists.",
|
|
346
|
+
)
|
|
347
|
+
dry_run: bool = Field(
|
|
348
|
+
default=False,
|
|
349
|
+
description="If True, save Parquet/JSON locally without pushing to Hugging Face Hub.",
|
|
350
|
+
)
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
class BenchmarkConfig(BaseModel):
|
|
354
|
+
"""Top-level configuration for a speculative decoding sweep."""
|
|
355
|
+
|
|
356
|
+
run_id: str = Field(default_factory=_default_run_id)
|
|
357
|
+
model: ModelSpec
|
|
358
|
+
draft_tokens: list[int] = Field(
|
|
359
|
+
default_factory=lambda: list(DEFAULT_DRAFT_TOKENS),
|
|
360
|
+
description=(
|
|
361
|
+
"Draft token counts (--spec-draft-n-max) to sweep, or a preset name "
|
|
362
|
+
"('default'=[0,4,8,12], 'spec-only'=[4,8,12], 'fine'=[0,1,2,4,8,12,16]). "
|
|
363
|
+
"Include 0 for baseline speedup and extra GPU memory measurement."
|
|
364
|
+
),
|
|
365
|
+
)
|
|
366
|
+
suites: list[SuiteSpec] = Field(
|
|
367
|
+
default_factory=lambda: [
|
|
368
|
+
SuiteSpec(capability="coding", source="preset:coding", limit=20),
|
|
369
|
+
SuiteSpec(capability="multimodal", source="preset:multimodal", limit=20),
|
|
370
|
+
]
|
|
371
|
+
)
|
|
372
|
+
server: ServerConfig = Field(default_factory=ServerConfig)
|
|
373
|
+
generation: GenerationConfig = Field(default_factory=GenerationConfig)
|
|
374
|
+
output: OutputConfig = Field(default_factory=OutputConfig)
|
|
375
|
+
hardware_tag: str | None = Field(
|
|
376
|
+
default=None,
|
|
377
|
+
description="Optional hardware label recorded in dataset rows (auto-detected if omitted).",
|
|
378
|
+
)
|
|
379
|
+
backend_name: str = Field(default="llama.cpp")
|
|
380
|
+
|
|
381
|
+
@field_validator("draft_tokens", mode="before")
|
|
382
|
+
@classmethod
|
|
383
|
+
def _coerce_draft_tokens(cls, value: Any) -> Any:
|
|
384
|
+
if isinstance(value, str):
|
|
385
|
+
return resolve_draft_tokens(value)
|
|
386
|
+
return value
|
|
387
|
+
|
|
388
|
+
@field_validator("draft_tokens")
|
|
389
|
+
@classmethod
|
|
390
|
+
def _validate_draft_tokens(cls, values: list[int]) -> list[int]:
|
|
391
|
+
if not values:
|
|
392
|
+
raise ValueError("draft_tokens must contain at least one non-negative integer.")
|
|
393
|
+
deduped: list[int] = []
|
|
394
|
+
for n in values:
|
|
395
|
+
if n < 0:
|
|
396
|
+
raise ValueError(f"draft_tokens values must be >= 0, got {n}.")
|
|
397
|
+
if n not in deduped:
|
|
398
|
+
deduped.append(n)
|
|
399
|
+
return deduped
|
|
400
|
+
|
|
401
|
+
@field_validator("suites")
|
|
402
|
+
@classmethod
|
|
403
|
+
def _validate_suites(cls, suites: list[SuiteSpec]) -> list[SuiteSpec]:
|
|
404
|
+
if not suites:
|
|
405
|
+
raise ValueError("At least one capability suite must be configured.")
|
|
406
|
+
return suites
|
|
407
|
+
|
|
408
|
+
@classmethod
|
|
409
|
+
def from_yaml(cls, path: str | Path) -> BenchmarkConfig:
|
|
410
|
+
raw = yaml.safe_load(Path(path).read_text(encoding="utf-8")) or {}
|
|
411
|
+
return cls.model_validate(raw)
|
|
412
|
+
|
|
413
|
+
def to_yaml(self, path: str | Path) -> None:
|
|
414
|
+
data = self.model_dump(mode="json")
|
|
415
|
+
Path(path).write_text(yaml.safe_dump(data, sort_keys=False), encoding="utf-8")
|