Update task_template.py
Browse files- task_template.py +41 -26
task_template.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
"""Model equality challenge - task template (task 33-model-equality).
|
| 2 |
|
| 3 |
You are given
|
| 4 |
-
|
| 5 |
Each team can collect up to 100 answers per endpoint (at most 256 generated tokens per answer, prompts up to 1,024
|
| 6 |
tokens), with at most 4 requests at a time.
|
| 7 |
|
|
@@ -14,12 +14,19 @@ This file shows you how to
|
|
| 14 |
3. write a random, valid submission file (make_random_submission()), as an example of the file format.
|
| 15 |
Put your method in solve().
|
| 16 |
|
| 17 |
-
Submission file: a
|
| 18 |
-
|
| 19 |
-
model
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
-
Score: Matthews correlation coefficient (MCC
|
| 22 |
-
|
|
|
|
| 23 |
|
| 24 |
Needs: pip install requests
|
| 25 |
"""
|
|
@@ -45,7 +52,8 @@ OUTPUT_FILE = Path("submission.csv")
|
|
| 45 |
QUERY = False # set to True to query the endpoints
|
| 46 |
RANDOM_SUBMISSION = False # set to True to write a random example submission
|
| 47 |
|
| 48 |
-
|
|
|
|
| 49 |
REPEATS = 1 # answers per prompt and endpoint (answers are sampled, so they differ)
|
| 50 |
MAX_TOKENS = 256 # the server caps answers at 256 tokens
|
| 51 |
PARALLEL = 4 # the most requests the server allows at once per team
|
|
@@ -160,26 +168,31 @@ def query(prompts: list, output: Path = ANSWERS_FILE, endpoints: list = ENDPOINT
|
|
| 160 |
print(f"Finished: {output}")
|
| 161 |
|
| 162 |
|
| 163 |
-
def write_submission(
|
| 164 |
-
"""Writes
|
|
|
|
| 165 |
with path.open("w", newline="") as handle:
|
| 166 |
-
csv.writer(handle)
|
|
|
|
|
|
|
| 167 |
|
| 168 |
|
| 169 |
-
def make_random_submission(
|
| 170 |
-
"""A random valid submission:
|
| 171 |
-
|
| 172 |
rng = random.Random(seed)
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
|
|
|
|
|
|
| 176 |
|
| 177 |
|
| 178 |
-
def solve() -> list:
|
| 179 |
-
"""TODO: your method. Must return
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
return [
|
| 183 |
|
| 184 |
|
| 185 |
def main() -> None:
|
|
@@ -187,21 +200,23 @@ def main() -> None:
|
|
| 187 |
print("Set API_KEY at the top of task_template.py to your team's API key.", file=sys.stderr)
|
| 188 |
raise SystemExit(1)
|
| 189 |
|
|
|
|
| 190 |
print("Budget left per endpoint:")
|
| 191 |
-
for ep, n in
|
| 192 |
print(f" {ep}: {n}")
|
|
|
|
| 193 |
|
| 194 |
if QUERY:
|
| 195 |
if not PROMPTS_FILE.exists():
|
| 196 |
print(f"Error: {PROMPTS_FILE} not found. Write your prompts there (one per line).", file=sys.stderr)
|
| 197 |
raise SystemExit(1)
|
| 198 |
-
query(read_prompts(PROMPTS_FILE))
|
| 199 |
|
| 200 |
if RANDOM_SUBMISSION:
|
| 201 |
-
|
| 202 |
else:
|
| 203 |
-
|
| 204 |
-
write_submission(
|
| 205 |
print(f"Saved submission to {OUTPUT_FILE}. Upload it with submission.py.")
|
| 206 |
|
| 207 |
|
|
|
|
| 1 |
"""Model equality challenge - task template (task 33-model-equality).
|
| 2 |
|
| 3 |
You are given
|
| 4 |
+
33 API endpoints, ep-01 ... ep-33 (in this order), some of which serve the same model.
|
| 5 |
Each team can collect up to 100 answers per endpoint (at most 256 generated tokens per answer, prompts up to 1,024
|
| 6 |
tokens), with at most 4 requests at a time.
|
| 7 |
|
|
|
|
| 14 |
3. write a random, valid submission file (make_random_submission()), as an example of the file format.
|
| 15 |
Put your method in solve().
|
| 16 |
|
| 17 |
+
Submission file: a CSV with one line per endpoint and three columns, endpoint,family,model (the header line is optional,
|
| 18 |
+
the order of the lines does not matter). Labels are any text you like (no commas):
|
| 19 |
+
endpoint,family,model
|
| 20 |
+
ep-01,A,A1
|
| 21 |
+
ep-02,B,B1
|
| 22 |
+
ep-03,A,A2
|
| 23 |
+
Endpoints with the same family label are built on the same base model. Endpoints with the same model label serve exactly
|
| 24 |
+
the same model; they must also share the family label. Submit it with submission.py. The old matrix format is no longer
|
| 25 |
+
accepted.
|
| 26 |
|
| 27 |
+
Score: Matthews correlation coefficient (MCC, below 0 counts as 0) over pairs of endpoints. 10 % of the score is for the
|
| 28 |
+
same-family question (all pairs), 90 % for the same-model question (only pairs within one family). The leaderboard shows
|
| 29 |
+
the score on a part of the pairs; the final ranking uses the rest.
|
| 30 |
|
| 31 |
Needs: pip install requests
|
| 32 |
"""
|
|
|
|
| 52 |
QUERY = False # set to True to query the endpoints
|
| 53 |
RANDOM_SUBMISSION = False # set to True to write a random example submission
|
| 54 |
|
| 55 |
+
NUM_ENDPOINTS = 33 # the server lists the real endpoints: python task_template.py prints them
|
| 56 |
+
ENDPOINTS = [f"ep-{i:02d}" for i in range(1, NUM_ENDPOINTS + 1)]
|
| 57 |
REPEATS = 1 # answers per prompt and endpoint (answers are sampled, so they differ)
|
| 58 |
MAX_TOKENS = 256 # the server caps answers at 256 tokens
|
| 59 |
PARALLEL = 4 # the most requests the server allows at once per team
|
|
|
|
| 168 |
print(f"Finished: {output}")
|
| 169 |
|
| 170 |
|
| 171 |
+
def write_submission(rows: list, path: Path = OUTPUT_FILE) -> None:
|
| 172 |
+
"""Writes the submission as a CSV with the header endpoint,family,model and one (endpoint, family, model) row per
|
| 173 |
+
endpoint."""
|
| 174 |
with path.open("w", newline="") as handle:
|
| 175 |
+
writer = csv.writer(handle)
|
| 176 |
+
writer.writerow(["endpoint", "family", "model"])
|
| 177 |
+
writer.writerows(rows)
|
| 178 |
|
| 179 |
|
| 180 |
+
def make_random_submission(endpoints: list = ENDPOINTS, families: int = 3, seed: int = None) -> list:
|
| 181 |
+
"""A random valid submission: every endpoint gets a random family, and inside a family a random model label.
|
| 182 |
+
Two endpoints with the same model label always share the family label. Returns [(endpoint, family, model), ...]."""
|
| 183 |
rng = random.Random(seed)
|
| 184 |
+
rows = []
|
| 185 |
+
for endpoint in endpoints:
|
| 186 |
+
family = f"F{rng.randrange(families)}"
|
| 187 |
+
rows.append((endpoint, family, f"{family}-M{rng.randrange(3)}"))
|
| 188 |
+
return rows
|
| 189 |
|
| 190 |
|
| 191 |
+
def solve(endpoints: list = ENDPOINTS) -> list:
|
| 192 |
+
"""TODO: your method. Must return [(endpoint, family, model), ...], one row per endpoint. Endpoints with the same
|
| 193 |
+
model label must share the family label. This baseline says "all different" (every endpoint in its own family and
|
| 194 |
+
model); it scores 0."""
|
| 195 |
+
return [(endpoint, f"F{i}", f"M{i}") for i, endpoint in enumerate(endpoints, 1)]
|
| 196 |
|
| 197 |
|
| 198 |
def main() -> None:
|
|
|
|
| 200 |
print("Set API_KEY at the top of task_template.py to your team's API key.", file=sys.stderr)
|
| 201 |
raise SystemExit(1)
|
| 202 |
|
| 203 |
+
budget = get_budget(make_session())
|
| 204 |
print("Budget left per endpoint:")
|
| 205 |
+
for ep, n in budget.items():
|
| 206 |
print(f" {ep}: {n}")
|
| 207 |
+
endpoints = [ep for ep in budget if ep.startswith("ep-")] # the server also lists the ref-* practice endpoints
|
| 208 |
|
| 209 |
if QUERY:
|
| 210 |
if not PROMPTS_FILE.exists():
|
| 211 |
print(f"Error: {PROMPTS_FILE} not found. Write your prompts there (one per line).", file=sys.stderr)
|
| 212 |
raise SystemExit(1)
|
| 213 |
+
query(read_prompts(PROMPTS_FILE), endpoints=endpoints)
|
| 214 |
|
| 215 |
if RANDOM_SUBMISSION:
|
| 216 |
+
rows = make_random_submission(endpoints)
|
| 217 |
else:
|
| 218 |
+
rows = solve(endpoints)
|
| 219 |
+
write_submission(rows)
|
| 220 |
print(f"Saved submission to {OUTPUT_FILE}. Upload it with submission.py.")
|
| 221 |
|
| 222 |
|