Upload example_submission.py
Browse files- example_submission.py +133 -0
example_submission.py
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
WM Bench β Example Submission Script
|
| 3 |
+
=====================================
|
| 4 |
+
Any world model can participate in WM Bench using this template.
|
| 5 |
+
No 3D environment needed β text input/output only.
|
| 6 |
+
|
| 7 |
+
Usage:
|
| 8 |
+
python example_submission.py --api_url YOUR_MODEL_API --api_key YOUR_KEY --model YOUR_MODEL_NAME
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
import json
|
| 12 |
+
import argparse
|
| 13 |
+
import requests
|
| 14 |
+
import time
|
| 15 |
+
from pathlib import Path
|
| 16 |
+
|
| 17 |
+
# ββ μ€μ ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 18 |
+
DATASET_PATH = Path(__file__).parent.parent / "data" / "wm_bench_dataset.json"
|
| 19 |
+
|
| 20 |
+
SYSTEM_PROMPT = """You are a world model. Given scene_context as JSON, respond in exactly 2 lines:
|
| 21 |
+
Line 1: PREDICT: left=<safe|danger>(<reason>), right=<safe|danger>(<reason>), fwd=<safe|danger>(<reason>), back=<safe|danger>(<reason>)
|
| 22 |
+
Line 2: MOTION: <describe the character's physical motion and emotional state in one sentence>
|
| 23 |
+
Respond ONLY these 2 lines. No explanation."""
|
| 24 |
+
|
| 25 |
+
# ββ λ©μΈ νκ° ν¨μ βββββββββββββββββββββββββββββββββββββββββββββββ
|
| 26 |
+
def run_evaluation(api_url: str, api_key: str, model: str, output_path: str = "my_submission.json"):
|
| 27 |
+
"""
|
| 28 |
+
WM Bench νκ°λ₯Ό μ€ννκ³ μ μΆ νμΌμ μμ±ν©λλ€.
|
| 29 |
+
|
| 30 |
+
Parameters:
|
| 31 |
+
api_url: OpenAI νΈν API URL (μ: https://api.openai.com/v1/chat/completions)
|
| 32 |
+
api_key: API ν€
|
| 33 |
+
model: λͺ¨λΈ μ΄λ¦
|
| 34 |
+
output_path: μ μΆ νμΌ κ²½λ‘
|
| 35 |
+
"""
|
| 36 |
+
# λ°μ΄ν°μ
λ‘λ
|
| 37 |
+
with open(DATASET_PATH, "r", encoding="utf-8") as f:
|
| 38 |
+
dataset = json.load(f)
|
| 39 |
+
|
| 40 |
+
scenarios = dataset["scenarios"]
|
| 41 |
+
print(f"β
λ°μ΄ν°μ
λ‘λ: {len(scenarios)}κ° μλ리μ€")
|
| 42 |
+
print(f"π€ λͺ¨λΈ: {model}")
|
| 43 |
+
print(f"π API: {api_url}\n")
|
| 44 |
+
|
| 45 |
+
results = []
|
| 46 |
+
errors = 0
|
| 47 |
+
|
| 48 |
+
for i, scenario in enumerate(scenarios):
|
| 49 |
+
sc_id = scenario["id"]
|
| 50 |
+
cat = scenario["cat"]
|
| 51 |
+
scene = scenario["scene_context"]
|
| 52 |
+
|
| 53 |
+
# API νΈμΆ
|
| 54 |
+
t0 = time.time()
|
| 55 |
+
response_text, latency_ms = call_api(api_url, api_key, model, scene)
|
| 56 |
+
|
| 57 |
+
if response_text is None:
|
| 58 |
+
errors += 1
|
| 59 |
+
print(f" β {sc_id} ({cat}): API μ€λ₯")
|
| 60 |
+
results.append({
|
| 61 |
+
"id": sc_id,
|
| 62 |
+
"cat": cat,
|
| 63 |
+
"response": None,
|
| 64 |
+
"latency_ms": latency_ms,
|
| 65 |
+
"error": True
|
| 66 |
+
})
|
| 67 |
+
else:
|
| 68 |
+
results.append({
|
| 69 |
+
"id": sc_id,
|
| 70 |
+
"cat": cat,
|
| 71 |
+
"response": response_text,
|
| 72 |
+
"latency_ms": round(latency_ms, 1),
|
| 73 |
+
"error": False
|
| 74 |
+
})
|
| 75 |
+
|
| 76 |
+
if (i + 1) % 10 == 0:
|
| 77 |
+
print(f" β {i+1}/100 μλ£ ({cat})")
|
| 78 |
+
|
| 79 |
+
# μ μΆ νμΌ μμ±
|
| 80 |
+
submission = {
|
| 81 |
+
"model": model,
|
| 82 |
+
"api_url": api_url,
|
| 83 |
+
"track": "A", # Text-Only Track
|
| 84 |
+
"submitted_at": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()),
|
| 85 |
+
"total_scenarios": len(scenarios),
|
| 86 |
+
"errors": errors,
|
| 87 |
+
"results": results
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
with open(output_path, "w", encoding="utf-8") as f:
|
| 91 |
+
json.dump(submission, f, ensure_ascii=False, indent=2)
|
| 92 |
+
|
| 93 |
+
print(f"\nβ
μ μΆ νμΌ μμ±: {output_path}")
|
| 94 |
+
print(f" μ΄ μλ리μ€: {len(scenarios)}, μ€λ₯: {errors}")
|
| 95 |
+
print(f"\nπ€ λ€μ λ¨κ³: WM Bench Spaceμ μ μΆ νμΌ μ
λ‘λ")
|
| 96 |
+
print(f" https://huggingface.co/spaces/FINAL-Bench/worldmodel-bench")
|
| 97 |
+
return output_path
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
def call_api(api_url: str, api_key: str, model: str, scene_context: dict):
|
| 101 |
+
"""OpenAI νΈν API νΈμΆ"""
|
| 102 |
+
headers = {
|
| 103 |
+
"Content-Type": "application/json",
|
| 104 |
+
"Authorization": f"Bearer {api_key}"
|
| 105 |
+
}
|
| 106 |
+
payload = {
|
| 107 |
+
"model": model,
|
| 108 |
+
"max_tokens": 200,
|
| 109 |
+
"temperature": 0.0,
|
| 110 |
+
"messages": [
|
| 111 |
+
{"role": "system", "content": SYSTEM_PROMPT},
|
| 112 |
+
{"role": "user", "content": f"scene_context: {json.dumps(scene_context)}"}
|
| 113 |
+
]
|
| 114 |
+
}
|
| 115 |
+
t0 = time.time()
|
| 116 |
+
try:
|
| 117 |
+
r = requests.post(api_url, headers=headers, json=payload, timeout=30)
|
| 118 |
+
r.raise_for_status()
|
| 119 |
+
text = r.json()["choices"][0]["message"]["content"]
|
| 120 |
+
return text, (time.time() - t0) * 1000
|
| 121 |
+
except Exception as e:
|
| 122 |
+
return None, (time.time() - t0) * 1000
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
if __name__ == "__main__":
|
| 126 |
+
parser = argparse.ArgumentParser(description="WM Bench Submission Script")
|
| 127 |
+
parser.add_argument("--api_url", required=True, help="OpenAI-compatible API URL")
|
| 128 |
+
parser.add_argument("--api_key", required=True, help="API Key")
|
| 129 |
+
parser.add_argument("--model", required=True, help="Model name")
|
| 130 |
+
parser.add_argument("--output", default="my_submission.json", help="Output file path")
|
| 131 |
+
args = parser.parse_args()
|
| 132 |
+
|
| 133 |
+
run_evaluation(args.api_url, args.api_key, args.model, args.output)
|