Leon4gr45 commited on
Commit
dfec44e
·
verified ·
1 Parent(s): c0c678a

Delete benchmarks/longmemeval/config.py

Browse files
Files changed (1) hide show
  1. benchmarks/longmemeval/config.py +0 -261
benchmarks/longmemeval/config.py DELETED
@@ -1,261 +0,0 @@
1
- from __future__ import annotations
2
-
3
- import os
4
- from dataclasses import dataclass
5
- from pathlib import Path
6
-
7
- from dotenv import load_dotenv
8
-
9
- BENCHMARKS_ROOT = Path(__file__).resolve().parent.parent
10
- DATA_DIR = BENCHMARKS_ROOT / "data"
11
- RUNS_DIR = BENCHMARKS_ROOT / "runs"
12
-
13
- HF_CLEANED_BASE = (
14
- "https://huggingface.co/datasets/xiaowu0162/longmemeval-cleaned/resolve/main"
15
- )
16
-
17
- VARIANT_FILES = {
18
- "s": "longmemeval_s_cleaned.json",
19
- "oracle": "longmemeval_oracle.json",
20
- "m": "longmemeval_m_cleaned.json",
21
- }
22
-
23
- DEFAULT_VARIANT = "s"
24
- DEFAULT_LLM_BASE_URL = "https://api.deepseek.com"
25
- DEFAULT_ANSWER_MODEL = "deepseek-v4-flash"
26
- DEFAULT_SOTA_ANSWER_MODEL = "deepseek-v4-flash"
27
- DEFAULT_AZURE_JUDGE_MODEL = "gpt-4o"
28
- DEFAULT_AZURE_API_VERSION = "2024-12-01-preview"
29
- DEFAULT_BENCH_PROFILE = "product"
30
-
31
- QUESTION_TYPES = (
32
- "single-session-user",
33
- "single-session-assistant",
34
- "single-session-preference",
35
- "temporal-reasoning",
36
- "knowledge-update",
37
- "multi-session",
38
- )
39
-
40
- _MODEL_FAMILY_PREFIXES = {
41
- "deepseek": "deepseek",
42
- "gpt": "openai",
43
- "o1": "openai",
44
- "o3": "openai",
45
- "o4": "openai",
46
- "chatgpt": "openai",
47
- "claude": "anthropic",
48
- "gemini": "google",
49
- "grok": "xai",
50
- "qwen": "qwen",
51
- "llama": "meta",
52
- "mistral": "mistral",
53
- }
54
-
55
- TERMINAL_TASK_STATUSES = frozenset({"completed", "failed", "partial_failed"})
56
-
57
-
58
- def model_family(model: str) -> str:
59
- name = (model or "").strip().lower().rsplit("/", 1)[-1]
60
- for prefix, family in _MODEL_FAMILY_PREFIXES.items():
61
- if name.startswith(prefix):
62
- return family
63
- return name.split("-", 1)[0] or "unknown"
64
-
65
-
66
- def variant_url(variant: str) -> str:
67
- key = (variant or DEFAULT_VARIANT).strip().lower()
68
- if key not in VARIANT_FILES:
69
- raise ValueError(f"Unknown variant {variant!r}; choose from {sorted(VARIANT_FILES)}")
70
- return f"{HF_CLEANED_BASE}/{VARIANT_FILES[key]}"
71
-
72
-
73
- def variant_path(variant: str) -> Path:
74
- key = (variant or DEFAULT_VARIANT).strip().lower()
75
- if key not in VARIANT_FILES:
76
- raise ValueError(f"Unknown variant {variant!r}; choose from {sorted(VARIANT_FILES)}")
77
- return DATA_DIR / VARIANT_FILES[key]
78
-
79
-
80
- def profile_defaults(profile: str) -> dict:
81
- name = (profile or "product").strip().lower()
82
- if name == "sota":
83
- return {
84
- "bench_profile": "sota",
85
- "sc_samples": int(os.getenv("BENCH_SC_SAMPLES", "5")),
86
- "sc_temperature": float(os.getenv("BENCH_SC_TEMPERATURE", "0.7")),
87
- "gap_fill": os.getenv("BENCH_GAP_FILL", "1") not in {"0", "false", "False"},
88
- }
89
- return {
90
- "bench_profile": "product",
91
- "sc_samples": int(os.getenv("BENCH_SC_SAMPLES", "1")),
92
- "sc_temperature": 0.0,
93
- "gap_fill": os.getenv("BENCH_GAP_FILL", "0") in {"1", "true", "True"},
94
- }
95
-
96
-
97
- @dataclass
98
- class Settings:
99
- brainapi_url: str
100
- brainpat_token: str
101
- openai_api_key: str
102
- llm_base_url: str | None
103
- answer_model: str
104
- judge_model: str
105
- judge_api_key: str
106
- judge_base_url: str | None
107
- judge_azure_endpoint: str | None
108
- judge_azure_api_version: str
109
- dataset_path: Path
110
- dataset_url: str
111
- variant: str
112
- runs_dir: Path
113
- bench_profile: str
114
- sc_samples: int
115
- sc_temperature: float
116
- gap_fill: bool
117
- answer_azure_endpoint: str | None = None
118
- answer_azure_api_version: str = DEFAULT_AZURE_API_VERSION
119
-
120
- @classmethod
121
- def load(cls, env_file: Path | None = None, *, variant: str | None = None) -> "Settings":
122
- if env_file is None:
123
- env_file = BENCHMARKS_ROOT / ".env"
124
- if env_file.exists():
125
- load_dotenv(env_file, override=False)
126
- else:
127
- load_dotenv(override=False)
128
-
129
- profile = (
130
- os.getenv("BENCH_PROFILE", DEFAULT_BENCH_PROFILE) or DEFAULT_BENCH_PROFILE
131
- ).strip().lower()
132
- if profile not in {"product", "sota"}:
133
- profile = DEFAULT_BENCH_PROFILE
134
- defaults = profile_defaults(profile)
135
-
136
- api_key = (
137
- os.getenv("DEEPSEEK_API_KEY")
138
- or os.getenv("OPENAI_API_KEY")
139
- or ""
140
- )
141
- llm_base_url = os.getenv("BENCH_LLM_BASE_URL", DEFAULT_LLM_BASE_URL) or None
142
- answer_model = os.getenv("BENCH_ANSWER_MODEL", DEFAULT_ANSWER_MODEL)
143
-
144
- azure_endpoint = (
145
- os.getenv("BENCH_JUDGE_AZURE_ENDPOINT")
146
- or os.getenv("AZURE_LARGE_LLM_ENDPOINT")
147
- or ""
148
- ).rstrip("/")
149
- azure_key = (
150
- os.getenv("BENCH_JUDGE_AZURE_KEY")
151
- or os.getenv("AZURE_LARGE_LLM_SUBSCRIPTION_KEY")
152
- or ""
153
- )
154
- azure_available = bool(azure_endpoint and azure_key)
155
-
156
- answer_azure_endpoint: str | None = None
157
- if profile == "sota":
158
- sota_answer = os.getenv("BENCH_SOTA_ANSWER_MODEL", "").strip()
159
- if sota_answer:
160
- answer_model = sota_answer
161
- sota_base = os.getenv("BENCH_SOTA_LLM_BASE_URL", "").strip()
162
- if sota_base:
163
- llm_base_url = sota_base
164
- else:
165
- answer_model = os.getenv(
166
- "BENCH_ANSWER_MODEL", DEFAULT_SOTA_ANSWER_MODEL
167
- )
168
-
169
- judge_model = os.getenv("BENCH_JUDGE_MODEL", "")
170
- judge_base_url = os.getenv("BENCH_JUDGE_BASE_URL", "")
171
- judge_api_key = os.getenv("BENCH_JUDGE_API_KEY", "")
172
- use_azure_judge = azure_available and not judge_model and not judge_base_url
173
- if use_azure_judge:
174
- judge_model = os.getenv(
175
- "AZURE_LARGE_LLM_MODEL", DEFAULT_AZURE_JUDGE_MODEL
176
- )
177
- if profile == "sota":
178
- sota_judge = os.getenv("BENCH_SOTA_JUDGE_MODEL", "").strip()
179
- if sota_judge:
180
- judge_model = sota_judge
181
- use_azure_judge = False
182
- elif not os.getenv("BENCH_JUDGE_MODEL"):
183
- judge_model = answer_model
184
- use_azure_judge = False
185
- judge_base_url = llm_base_url or ""
186
- judge_api_key = api_key
187
-
188
- resolved_variant = (
189
- variant
190
- or os.getenv("BENCH_LME_VARIANT", DEFAULT_VARIANT)
191
- or DEFAULT_VARIANT
192
- ).strip().lower()
193
- if resolved_variant not in VARIANT_FILES:
194
- resolved_variant = DEFAULT_VARIANT
195
- default_path = variant_path(resolved_variant)
196
- default_url = variant_url(resolved_variant)
197
-
198
- return cls(
199
- brainapi_url=os.getenv("BRAINAPI_URL", "http://localhost:8000").rstrip("/"),
200
- brainpat_token=os.getenv("BRAINPAT_TOKEN", ""),
201
- openai_api_key=api_key,
202
- llm_base_url=llm_base_url,
203
- answer_model=answer_model,
204
- judge_model=judge_model or answer_model,
205
- judge_api_key=(
206
- azure_key if use_azure_judge else (judge_api_key or api_key)
207
- ),
208
- judge_base_url=(
209
- None if use_azure_judge else (judge_base_url or llm_base_url)
210
- ),
211
- judge_azure_endpoint=azure_endpoint if use_azure_judge else None,
212
- judge_azure_api_version=os.getenv(
213
- "BENCH_JUDGE_AZURE_API_VERSION",
214
- os.getenv("AZURE_LARGE_LLM_API_VERSION", DEFAULT_AZURE_API_VERSION),
215
- ),
216
- dataset_path=Path(
217
- os.getenv("BENCH_LME_DATASET_PATH", str(default_path))
218
- ),
219
- dataset_url=os.getenv("BENCH_LME_DATASET_URL", default_url),
220
- variant=resolved_variant,
221
- runs_dir=Path(os.getenv("BENCH_RUNS_DIR", str(RUNS_DIR))),
222
- bench_profile=str(defaults["bench_profile"]),
223
- sc_samples=max(1, int(defaults["sc_samples"])),
224
- sc_temperature=float(defaults["sc_temperature"]),
225
- gap_fill=bool(defaults["gap_fill"]),
226
- answer_azure_endpoint=answer_azure_endpoint,
227
- answer_azure_api_version=os.getenv(
228
- "BENCH_JUDGE_AZURE_API_VERSION",
229
- os.getenv("AZURE_LARGE_LLM_API_VERSION", DEFAULT_AZURE_API_VERSION),
230
- ),
231
- )
232
-
233
- @property
234
- def judge_shares_answer_family(self) -> bool:
235
- return model_family(self.judge_model) == model_family(self.answer_model)
236
-
237
- def judge_provider(self) -> str:
238
- if self.judge_azure_endpoint:
239
- return "azure"
240
- return self.judge_base_url or "openai-default"
241
-
242
- def require_brainapi(self) -> None:
243
- if not self.brainpat_token:
244
- raise SystemExit(
245
- "BRAINPAT_TOKEN is required. Copy .env.example to .env and set it."
246
- )
247
-
248
- def require_llm(self) -> None:
249
- if not self.openai_api_key:
250
- raise SystemExit(
251
- "DEEPSEEK_API_KEY (or OPENAI_API_KEY) is required for answer/judge "
252
- "LLM calls. Copy .env.example to .env and set it."
253
- )
254
-
255
- def require_judge_llm(self) -> None:
256
- if not self.judge_api_key:
257
- raise SystemExit(
258
- "No judge API key. Set BENCH_JUDGE_API_KEY (with BENCH_JUDGE_BASE_URL "
259
- "and BENCH_JUDGE_MODEL), or DEEPSEEK_API_KEY / OPENAI_API_KEY to reuse "
260
- "the answerer's provider."
261
- )