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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""SLM Tetris Arena — decoder-only LMs play Tetris zero-shot and earn Elo."""
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
# Keep the write token out of the environment before any model code runs:
|
| 5 |
+
# only the results store receives it (custom model code runs in this process).
|
| 6 |
+
_TOKEN = os.environ.pop("HF_TOKEN", None) or os.environ.pop("HUGGING_FACE_HUB_TOKEN", None)
|
| 7 |
+
os.environ.setdefault("HF_HUB_DISABLE_PROGRESS_BARS", "1")
|
| 8 |
+
|
| 9 |
+
import html
|
| 10 |
+
import inspect
|
| 11 |
+
import random
|
| 12 |
+
import time
|
| 13 |
+
|
| 14 |
+
import gradio as gr
|
| 15 |
+
import torch
|
| 16 |
+
|
| 17 |
+
from arena import MAX_PIECES, SEASON, ResultsStore, choose, rank_games
|
| 18 |
+
from leaderboard import LB_CSS, leaderboard_html
|
| 19 |
+
from leaderboard import fmt_params as short_params
|
| 20 |
+
from players import (BASELINES, MAX_PARAMS, MIN_PARAMS, ORACLE_ID, PROMPTS, RANDOM_ID, ModelRejected, OracleReaderPlayer,
|
| 21 |
+
RandomPlayer, fmt_params, load_player, precheck)
|
| 22 |
+
from ranked import Pool, RankedRunner
|
| 23 |
+
from render import CSS, arena_html, empty_html, results_html
|
| 24 |
+
from tetris import TetrisGame
|
| 25 |
+
|
| 26 |
+
# cpu-basic Spaces have 2 vCPUs; os.cpu_count() reports the host, which oversubscribes threads
|
| 27 |
+
torch.set_num_threads(int(os.environ.get("TORCH_THREADS", 2)))
|
| 28 |
+
|
| 29 |
+
RESULTS_REPO = os.environ.get("RESULTS_REPO", "DedeProGames/lm-tetris-arena-results")
|
| 30 |
+
MAX_MODELS = int(os.environ.get("MAX_MODELS", 4))
|
| 31 |
+
# Optional size limit for the random ranked pick (0 = none). Without it every model can meet every other, so all
|
| 32 |
+
# ratings sit on one comparable scale; Elo already weighs each win by the opponent's rating, so beating a much
|
| 33 |
+
# weaker model earns almost nothing once ratings have settled.
|
| 34 |
+
MAX_PARAM_GAP = int(os.environ.get("MAX_PARAM_GAP", 0))
|
| 35 |
+
# ...with a gap, models this size or bigger can still all play each other
|
| 36 |
+
LARGE_FROM = int(os.environ.get("LARGE_FROM", 100_000_000))
|
| 37 |
+
if MAX_PARAM_GAP:
|
| 38 |
+
SIZE_RULE = (f"all within ±{short_params(MAX_PARAM_GAP)} parameters of each other "
|
| 39 |
+
f"(models with {short_params(LARGE_FROM)}+ parameters can all play each other)")
|
| 40 |
+
else:
|
| 41 |
+
SIZE_RULE = "of any size (Elo weighs every win by the opponent's rating, so all models share one scale)"
|
| 42 |
+
|
| 43 |
+
SUGGESTED = [
|
| 44 |
+
'AxiomicLabs/GPT-S-1.4M',
|
| 45 |
+
'AxiomicLabs/GPT-S2-5M',
|
| 46 |
+
'AxiomicLabs/GPT-X2.5-135M',
|
| 47 |
+
'BananaMind/BananaMind-2-Medium',
|
| 48 |
+
'BananaMind/BananaMind-2-Nano',
|
| 49 |
+
'BananaMind/BananaMind-2-Pro',
|
| 50 |
+
'BananaMind/BananaMind-2.1-Pico-Preview',
|
| 51 |
+
'DedeBckp/BackKiyo-10M',
|
| 52 |
+
'DedeProGames/DynamicMind-Mini',
|
| 53 |
+
'DedeProGames/GPT-U-20M',
|
| 54 |
+
'DedeProGames/Kiyo-230M-Preview',
|
| 55 |
+
'DedeProGames/Kiyo-65M',
|
| 56 |
+
'DedeProGames/LowOnMind-5M',
|
| 57 |
+
'DedeProGames/Overaddicted-500K',
|
| 58 |
+
'DedeProGames/Wisp-15M',
|
| 59 |
+
'DedeProGames/Wisp-5M',
|
| 60 |
+
'GODELEV/Rose-1.5-Medium',
|
| 61 |
+
'GODELEV/Rose-Mini',
|
| 62 |
+
'HuggingFaceTB/SmolLM-135M',
|
| 63 |
+
'HuggingFaceTB/SmolLM2-135M',
|
| 64 |
+
'openai-community/gpt2',
|
| 65 |
+
'opencerebral/Boris-1.3-75M',
|
| 66 |
+
'SupraLabs/Supra2-100M-Base',
|
| 67 |
+
'SupraLabs/Supra2-Medium-Base',
|
| 68 |
+
'SupraLabs/SupraNeo-4M',
|
| 69 |
+
'veyra-ai/Veyra2-Apricot-50M-Base',
|
| 70 |
+
'veyra-ai/Veyra2-Blueberry-5M-Base',
|
| 71 |
+
'veyra-ai/Veyra2-Mango-30M-Base',
|
| 72 |
+
]
|
| 73 |
+
DEFAULT_MODELS = ["DedeProGames/Kiyo-65M", "BananaMind/BananaMind-2-Medium", "HuggingFaceTB/SmolLM2-135M", "SupraLabs/Supra2-Medium-Base"]
|
| 74 |
+
# The leaderboard only keeps pool models: removing a model from SUGGESTED also removes it from the leaderboard.
|
| 75 |
+
STORE = ResultsStore(RESULTS_REPO, _TOKEN, min_params=MIN_PARAMS, allowed=SUGGESTED)
|
| 76 |
+
# Ranked: the arena picks the players at random from the suggested models (nobody chooses who plays)
|
| 77 |
+
POOL = Pool(SUGGESTED, MAX_PARAM_GAP, MAX_MODELS, LARGE_FROM)
|
| 78 |
+
RANKED = RankedRunner(POOL, STORE)
|
| 79 |
+
PROTOCOL_CHOICES = [("Guided: the rules are in the prompt", "guided"), ("Blind: no rules, only pre-training knowledge", "blind")]
|
| 80 |
+
BASELINE_CHOICES = [(label, key) for key, label in BASELINES.items()]
|
| 81 |
+
|
| 82 |
+
# ---- Look & feel: BananaMind SLM Leaderboard palette and type (dark + light), light-blue accent ----
|
| 83 |
+
_D = dict(bg="#0b0e0d", surface="#111613", surface2="#191e1b", text="#f0f1ec", muted="#929b93", line="#29312c", accent="#4d9fff")
|
| 84 |
+
_L = dict(bg="#f4f5f1", surface="#ffffff", surface2="#edf0e9", text="#17221b", muted="#626e64", line="#d7ded5", accent="#1b64c4")
|
| 85 |
+
_CHECK = ("url(\"data:image/svg+xml,%3csvg viewBox='0 0 16 16' fill='%2307182e' xmlns='http://www.w3.org/2000/svg'%3e"
|
| 86 |
+
"%3cpath d='M12.207 4.793a1 1 0 010 1.414l-5 5a1 1 0 01-1.414 0l-2-2a1 1 0 011.414-1.414L6.5 9.086l4.293-4.293a1 1 0 011.414 0z'/%3e%3c/svg%3e\")")
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
_THEME_KEYS = set(inspect.signature(gr.themes.Base.set).parameters)
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
def _both(**pairs):
|
| 93 |
+
"""name=(light, dark) -> theme kwargs for both modes (skips variables this Gradio version lacks)."""
|
| 94 |
+
out = {}
|
| 95 |
+
for k, (light, dark) in pairs.items():
|
| 96 |
+
if k in _THEME_KEYS:
|
| 97 |
+
out[k] = light
|
| 98 |
+
if k + "_dark" in _THEME_KEYS:
|
| 99 |
+
out[k + "_dark"] = dark
|
| 100 |
+
return out
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
THEME = gr.themes.Base(
|
| 104 |
+
primary_hue=gr.themes.colors.blue, secondary_hue=gr.themes.colors.blue, neutral_hue=gr.themes.colors.stone,
|
| 105 |
+
font=[gr.themes.GoogleFont("DM Sans"), "Arial", "sans-serif"], font_mono=["ui-monospace", "SFMono-Regular", "monospace"],
|
| 106 |
+
).set(
|
| 107 |
+
block_border_width="1px", block_radius="13px", block_label_border_width="0px", block_title_text_weight="500",
|
| 108 |
+
input_radius="8px", checkbox_check=_CHECK,
|
| 109 |
+
**_both(
|
| 110 |
+
body_background_fill=(_L["bg"], _D["bg"]), body_text_color=(_L["text"], _D["text"]),
|
| 111 |
+
body_text_color_subdued=(_L["muted"], _D["muted"]),
|
| 112 |
+
background_fill_primary=(_L["surface"], _D["surface"]), background_fill_secondary=(_L["surface2"], _D["surface2"]),
|
| 113 |
+
block_background_fill=(_L["surface"], _D["surface"]), block_border_color=(_L["line"], _D["line"]),
|
| 114 |
+
block_shadow=("none", "none"), block_label_background_fill=("transparent", "transparent"),
|
| 115 |
+
block_label_text_color=(_L["muted"], _D["muted"]), block_label_shadow=("none", "none"),
|
| 116 |
+
block_title_background_fill=("transparent", "transparent"), block_title_text_color=(_L["muted"], _D["muted"]),
|
| 117 |
+
block_info_text_color=(_L["muted"], _D["muted"]),
|
| 118 |
+
border_color_primary=(_L["line"], _D["line"]), border_color_accent=("#4d9fff", "#4d9fff"),
|
| 119 |
+
color_accent=("#4d9fff", "#4d9fff"), color_accent_soft=("#4d9fff26", "#4d9fff26"),
|
| 120 |
+
input_background_fill=(_L["surface2"], _D["surface2"]), input_border_color=(_L["line"], _D["line"]),
|
| 121 |
+
input_border_color_focus=("#4d9fff", "#4d9fff"),
|
| 122 |
+
button_primary_background_fill=("#4d9fff", "#4d9fff"), button_primary_background_fill_hover=("#74b4ff", "#74b4ff"),
|
| 123 |
+
button_primary_text_color=("#07182e", "#07182e"), button_primary_border_color=("#4d9fff", "#4d9fff"),
|
| 124 |
+
button_secondary_background_fill=(_L["surface2"], _D["surface2"]),
|
| 125 |
+
button_secondary_background_fill_hover=(_L["line"], _D["line"]),
|
| 126 |
+
button_secondary_text_color=(_L["text"], _D["text"]), button_secondary_border_color=(_L["line"], _D["line"]),
|
| 127 |
+
checkbox_background_color_selected=("#4d9fff", "#4d9fff"), checkbox_border_color_selected=("#4d9fff", "#4d9fff"),
|
| 128 |
+
checkbox_label_background_fill=(_L["surface2"], _D["surface2"]),
|
| 129 |
+
checkbox_label_background_fill_selected=(_L["surface2"], _D["surface2"]),
|
| 130 |
+
checkbox_label_border_color=(_L["line"], _D["line"]), checkbox_label_border_color_selected=("#4d9fff", "#4d9fff"),
|
| 131 |
+
checkbox_label_text_color_selected=(_L["text"], _D["text"]),
|
| 132 |
+
slider_color=("#4d9fff", "#4d9fff"), loader_color=("#4d9fff", "#4d9fff"),
|
| 133 |
+
link_text_color=(_L["accent"], _D["accent"]), link_text_color_hover=(_L["accent"], _D["accent"]),
|
| 134 |
+
panel_background_fill=(_L["surface"], _D["surface"]), panel_border_color=(_L["line"], _D["line"]),
|
| 135 |
+
table_border_color=(_L["line"], _D["line"]), code_background_fill=(_L["surface2"], _D["surface2"]),
|
| 136 |
+
),
|
| 137 |
+
)
|
| 138 |
+
|
| 139 |
+
APP_CSS = """
|
| 140 |
+
@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=Space+Grotesk:wght@400;500;600;700&family=Press+Start+2P&display=swap');
|
| 141 |
+
.gradio-container{font-family:'DM Sans',Arial,sans-serif!important}
|
| 142 |
+
.gradio-container h1,.gradio-container h2,.gradio-container h3{font-family:'Space Grotesk',Arial,sans-serif!important;letter-spacing:-.4px}
|
| 143 |
+
.ah-heading{display:flex;justify-content:space-between;align-items:center;gap:20px;padding:10px 0 6px}
|
| 144 |
+
.ah-eyebrow{font:11px/1.5 monospace!important;letter-spacing:1.9px;color:var(--body-text-color-subdued)!important;margin:0 0 10px!important}
|
| 145 |
+
.ah-heading h1{font:500 clamp(32px,4vw,48px)/1.2 'Space Grotesk',Arial,sans-serif!important;letter-spacing:-2px!important;margin:0!important;
|
| 146 |
+
color:var(--body-text-color)!important}
|
| 147 |
+
.ah-accent{color:#1b64c4}.dark .ah-accent{color:#4d9fff}
|
| 148 |
+
.ah-intro{margin:10px 0 0!important;font-size:15px!important;color:var(--body-text-color-subdued)!important;max-width:860px}
|
| 149 |
+
.ah-version{font:11px monospace;letter-spacing:1px;color:var(--body-text-color-subdued);display:flex;align-items:center;gap:10px;white-space:nowrap}
|
| 150 |
+
.ah-dot{height:6px;width:6px;background:#95c79a;border-radius:50%}
|
| 151 |
+
.ah-note{margin:0 0 4px!important;font-size:14px!important;line-height:1.55;color:var(--body-text-color-subdued)!important;max-width:900px}
|
| 152 |
+
.ah-note b{color:var(--body-text-color)}
|
| 153 |
+
.ah-warn{margin-top:14px;padding:10px 14px;border:1px solid #4d9fff66;border-radius:8px;font-size:13px;color:var(--body-text-color)}
|
| 154 |
+
button[role=tab]{font-size:14px!important;color:var(--body-text-color-subdued)!important}
|
| 155 |
+
button[role=tab][aria-selected=true]{color:var(--body-text-color)!important;border-color:#4d9fff!important}
|
| 156 |
+
@media(max-width:550px){.ah-version{display:none}}
|
| 157 |
+
"""
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
def _status(text, kind="info"):
|
| 161 |
+
icon = {"info": "⏳", "ok": "✅", "err": "⛔", "warn": "⚠️"}[kind]
|
| 162 |
+
return f"{icon} {text}"
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
def run_match(model_ids, baselines, protocol, seed, delay):
|
| 166 |
+
"""Friendly match: any models, any seed, nothing is recorded (Elo only changes in the Ranked tab)."""
|
| 167 |
+
model_ids = [m.strip() for m in (model_ids or []) if m and m.strip()]
|
| 168 |
+
model_ids = list(dict.fromkeys(model_ids))
|
| 169 |
+
baselines = baselines or []
|
| 170 |
+
protocol = protocol or "guided"
|
| 171 |
+
if not model_ids:
|
| 172 |
+
yield _status("Pick at least one language model.", "err"), empty_html(), ""
|
| 173 |
+
return
|
| 174 |
+
if len(model_ids) > MAX_MODELS:
|
| 175 |
+
yield _status(f"At most {MAX_MODELS} language models per match on this CPU.", "err"), empty_html(), ""
|
| 176 |
+
return
|
| 177 |
+
if len(model_ids) + len(baselines) < 2:
|
| 178 |
+
yield _status("A match needs at least 2 players: add another model or a baseline.", "err"), empty_html(), ""
|
| 179 |
+
return
|
| 180 |
+
|
| 181 |
+
players = []
|
| 182 |
+
try:
|
| 183 |
+
metas = []
|
| 184 |
+
for m in model_ids:
|
| 185 |
+
yield _status(f"Checking `{m}`…"), empty_html("Checking models…"), ""
|
| 186 |
+
meta = precheck(m)
|
| 187 |
+
if any(x["id"] == meta["id"] for x in metas):
|
| 188 |
+
continue # same repo typed twice with different casing
|
| 189 |
+
metas.append(meta)
|
| 190 |
+
model_ids = [x["id"] for x in metas]
|
| 191 |
+
for i, (m, meta) in enumerate(zip(model_ids, metas), 1):
|
| 192 |
+
yield _status(f"Loading `{m}` on CPU ({i}/{len(model_ids)})… first load downloads the weights."), empty_html("Loading models…"), ""
|
| 193 |
+
players.append(load_player(m, meta))
|
| 194 |
+
except ModelRejected as e:
|
| 195 |
+
yield _status(str(e), "err"), empty_html("Match cancelled."), ""
|
| 196 |
+
return
|
| 197 |
+
if RANDOM_ID in baselines:
|
| 198 |
+
players.append(RandomPlayer())
|
| 199 |
+
if ORACLE_ID in baselines:
|
| 200 |
+
players.append(OracleReaderPlayer())
|
| 201 |
+
|
| 202 |
+
seed = int(seed) if seed else random.SystemRandom().randrange(1, 10**9)
|
| 203 |
+
games = [TetrisGame(seed) for _ in players]
|
| 204 |
+
mode = "friendly"
|
| 205 |
+
yield _status(f"Seed {seed} · {protocol} · {mode}. Scoring the first moves…"), arena_html(games, players), ""
|
| 206 |
+
|
| 207 |
+
last = time.time()
|
| 208 |
+
try:
|
| 209 |
+
while True:
|
| 210 |
+
active = [(g, p) for g, p in zip(games, players) if g.alive and g.pieces < MAX_PIECES]
|
| 211 |
+
if not active:
|
| 212 |
+
break
|
| 213 |
+
for g, p in active:
|
| 214 |
+
choose(g, p, protocol, seed)
|
| 215 |
+
elapsed = time.time() - last
|
| 216 |
+
if elapsed < delay:
|
| 217 |
+
time.sleep(delay - elapsed)
|
| 218 |
+
last = time.time()
|
| 219 |
+
n = max(g.pieces for g in games)
|
| 220 |
+
alive = sum(g.alive for g in games)
|
| 221 |
+
yield _status(f"Seed {seed} · {protocol} · {mode} · piece {n}/{MAX_PIECES} · {alive} still playing"), arena_html(games, players), ""
|
| 222 |
+
except ModelRejected as e:
|
| 223 |
+
yield _status(str(e), "err"), arena_html(games, players), ""
|
| 224 |
+
return
|
| 225 |
+
except Exception as e:
|
| 226 |
+
yield _status(f"A model crashed during play: {type(e).__name__}: {str(e)[:200]}", "err"), arena_html(games, players), ""
|
| 227 |
+
return
|
| 228 |
+
|
| 229 |
+
ranks = rank_games(games)
|
| 230 |
+
order = sorted(range(len(players)), key=lambda i: ranks[i])
|
| 231 |
+
elos = None
|
| 232 |
+
note = "Friendly match: Elo not changed (only matches in the Ranked tab count)."
|
| 233 |
+
note += f" Ranking: score, then lines, then pieces survived. ✓ = still alive at the {MAX_PIECES}-piece cap."
|
| 234 |
+
results = results_html(order, ranks, players, games, elos, note)
|
| 235 |
+
yield _status(f"Match finished · seed {seed} · {protocol} · {mode}.", "ok"), arena_html(games, players, ranks, elos), results
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
def ranked_play(protocol):
|
| 239 |
+
"""Start a ranked match (models picked at random) or watch the one already running."""
|
| 240 |
+
match, started = RANKED.start_or_join(protocol or "guided")
|
| 241 |
+
joined = "" if started else f" · you joined the ranked match already in progress ({match.protocol})"
|
| 242 |
+
seen = -1
|
| 243 |
+
while True:
|
| 244 |
+
version, status, boards, results, done = match.snapshot()
|
| 245 |
+
if version != seen:
|
| 246 |
+
seen = version
|
| 247 |
+
yield status + joined, boards, results
|
| 248 |
+
if done:
|
| 249 |
+
return
|
| 250 |
+
time.sleep(0.1)
|
| 251 |
+
|
| 252 |
+
|
| 253 |
+
def stop_status(current):
|
| 254 |
+
# only claim a stop when a match was actually running
|
| 255 |
+
if (current or "").startswith("⏳"):
|
| 256 |
+
return _status("Match stopped. Nothing was recorded.", "warn")
|
| 257 |
+
return current
|
| 258 |
+
|
| 259 |
+
|
| 260 |
+
def leaderboard_view(protocol):
|
| 261 |
+
protocol = protocol or "guided"
|
| 262 |
+
entries = [e for e in STORE.rows(protocol) if e["model"] not in BASELINES]
|
| 263 |
+
return leaderboard_html(entries, protocol, MAX_PARAM_GAP, short_params(MAX_PARAM_GAP))
|
| 264 |
+
|
| 265 |
+
|
| 266 |
+
def refresh_leaderboard(protocol):
|
| 267 |
+
STORE.reload()
|
| 268 |
+
return leaderboard_view(protocol)
|
| 269 |
+
|
| 270 |
+
|
| 271 |
+
INTRO = f"""
|
| 272 |
+
<div class="ah-heading"><div><p class="ah-eyebrow">SMALL MODELS. ZERO-SHOT TETRIS.</p>
|
| 273 |
+
<h1>SLM Tetris Arena<span class="ah-accent">.</span></h1>
|
| 274 |
+
<p class="ah-intro">Decoder-only language models ({short_params(MIN_PARAMS)}–{short_params(MAX_PARAMS)} parameters, custom architectures welcome) play Tetris
|
| 275 |
+
zero-shot: no fine-tuning, no game data, only what they learned from pre-training on text. Every player gets the same
|
| 276 |
+
piece sequence, and ranked matches update a public Elo leaderboard.</p></div>
|
| 277 |
+
<span class="ah-version">SEASON {SEASON} <span class="ah-dot"></span></span></div>
|
| 278 |
+
"""
|
| 279 |
+
|
| 280 |
+
HOW = f"""
|
| 281 |
+
### How a model plays
|
| 282 |
+
For every new piece the game lists all legal placements (rotation × column, hard drop), simulates each one and
|
| 283 |
+
describes the outcome in plain English. The model never sees the grid; it judges the descriptions:
|
| 284 |
+
|
| 285 |
+
```
|
| 286 |
+
{PROMPTS['guided'].format(desc='drops the piece into the lowest part of the board, clears one line, creates no new holes, keeps the stack low and leaves the surface flat')}
|
| 287 |
+
```
|
| 288 |
+
|
| 289 |
+
The model's value for a placement is **log P(" good move") − log P(" bad move")** after that prompt. The placement with the
|
| 290 |
+
highest value is played; exact ties are broken by a seeded coin that is identical for every player.
|
| 291 |
+
Because the value is a difference, a model's general bias towards "good" or "bad" cancels out.
|
| 292 |
+
|
| 293 |
+
### Protocols (separate leaderboards)
|
| 294 |
+
- **Guided**: the first line states the goal ("clear lines, avoid holes, keep the stack low"). Tests reading comprehension.
|
| 295 |
+
- **Blind**: `{PROMPTS['blind'].splitlines()[0]}` No rules; the model must already know what is good in Tetris.
|
| 296 |
+
|
| 297 |
+
### Rules of a match
|
| 298 |
+
- Same 7-bag piece sequence for everyone. The game ends at top-out or after {MAX_PIECES} pieces.
|
| 299 |
+
- Placement = score (100/300/500/800 for 1/2/3/4 lines), then lines, then pieces survived.
|
| 300 |
+
- **Match** tab (friendly): pick any 2+ players (up to {MAX_MODELS} language models of any size, plus optional baselines)
|
| 301 |
+
and the seed. Nothing is recorded.
|
| 302 |
+
- **Ranked** tab: press Play and the arena picks up to {MAX_MODELS} models at random from its pool of {len(POOL.ids)} models,
|
| 303 |
+
{SIZE_RULE}, with a random seed. Nobody chooses who plays, so Elo can't be farmed.
|
| 304 |
+
Models with fewer ranked games are more likely to be picked, so every model gets played. The match runs on the server and counts even if
|
| 305 |
+
you close the page; only one ranked match runs at a time, and pressing Play while one is running lets you watch it.
|
| 306 |
+
- Elo: K=32, multiplayer (every pair of players counts as a game, scaled by 1/(N−1)).
|
| 307 |
+
|
| 308 |
+
### Baselines
|
| 309 |
+
- **🎲 Random**: every placement ties, so it plays uniformly at random. This is the floor a model should beat.
|
| 310 |
+
- **📏 Oracle reader**: reads the same descriptions and ranks them with fixed common sense (holes > lines > height > surface > landing).
|
| 311 |
+
This is roughly the ceiling for a perfect reader of the text.
|
| 312 |
+
|
| 313 |
+
Baselines can join friendly matches for comparison. They never play ranked and never change anyone's Elo.
|
| 314 |
+
|
| 315 |
+
### Model requirements
|
| 316 |
+
Public, not gated, loads with `AutoModelForCausalLM` + `AutoTokenizer` (PyTorch or safetensors weights), between {fmt_params(MIN_PARAMS)} and {fmt_params(MAX_PARAMS)} parameters.
|
| 317 |
+
Models with custom code (`auto_map`) load with `trust_remote_code=True`. That code runs on this Space's CPU, so only
|
| 318 |
+
submit repos you trust. Prompts are in English (the language most pre-training corpora such as FineWeb-edu use).
|
| 319 |
+
|
| 320 |
+
Results and every match (seed, commit SHA of each model, scores) are published in
|
| 321 |
+
[`{RESULTS_REPO}`](https://huggingface.co/datasets/{RESULTS_REPO}).
|
| 322 |
+
"""
|
| 323 |
+
|
| 324 |
+
RANKED_INTRO = f"""<p class="ah-note">Press <b>Play</b> and the arena picks up to {MAX_MODELS} language models <b>at random</b>
|
| 325 |
+
from its pool of {len(POOL.ids)} models, {SIZE_RULE}, with a random seed.
|
| 326 |
+
The result updates the public Elo leaderboard. The match runs on the server: it finishes and counts even if you close the page.
|
| 327 |
+
Only one ranked match runs at a time; if one is already running, you watch it.</p>"""
|
| 328 |
+
|
| 329 |
+
with gr.Blocks(title="SLM Tetris Arena") as demo:
|
| 330 |
+
gr.HTML(INTRO, padding=False)
|
| 331 |
+
if not STORE.persistent:
|
| 332 |
+
gr.HTML('<div class="ah-warn">⚠️ Results are not being saved: add an <code>HF_TOKEN</code> secret with write access '
|
| 333 |
+
'to the results dataset.</div>', padding=False)
|
| 334 |
+
with gr.Tabs():
|
| 335 |
+
with gr.Tab("⚔️ Match"):
|
| 336 |
+
with gr.Row():
|
| 337 |
+
with gr.Column(scale=3):
|
| 338 |
+
models = gr.Dropdown(
|
| 339 |
+
choices=SUGGESTED, value=DEFAULT_MODELS, multiselect=True, allow_custom_value=True,
|
| 340 |
+
max_choices=MAX_MODELS, label=f"Language models (1–{MAX_MODELS})",
|
| 341 |
+
info="Pick from the list or type any Hub repo id (owner/name) and press Enter.",
|
| 342 |
+
)
|
| 343 |
+
baselines = gr.CheckboxGroup(BASELINE_CHOICES, value=[RANDOM_ID], label="Baselines (optional, never rated)")
|
| 344 |
+
with gr.Column(scale=2):
|
| 345 |
+
protocol = gr.Radio(PROTOCOL_CHOICES, value="guided", label="Protocol")
|
| 346 |
+
seed = gr.Number(value=42, precision=0, label="Seed (0 = random)",
|
| 347 |
+
info="Friendly match: any models, nothing is recorded. Elo only changes in the Ranked tab.")
|
| 348 |
+
delay = gr.Slider(0, 0.5, value=0.12, step=0.02, label="Seconds per piece (viewing speed)")
|
| 349 |
+
with gr.Row():
|
| 350 |
+
start = gr.Button("▶ Start match", variant="primary")
|
| 351 |
+
stop = gr.Button("■ Stop", variant="secondary")
|
| 352 |
+
status = gr.Markdown(_status("Ready.", "ok"))
|
| 353 |
+
boards = gr.HTML(empty_html())
|
| 354 |
+
results = gr.HTML()
|
| 355 |
+
with gr.Tab("🏅 Ranked"):
|
| 356 |
+
gr.HTML(RANKED_INTRO, padding=False)
|
| 357 |
+
with gr.Row(equal_height=True):
|
| 358 |
+
r_protocol = gr.Radio(PROTOCOL_CHOICES, value="guided", label="Protocol", scale=3)
|
| 359 |
+
r_play = gr.Button("▶ Play ranked match", variant="primary", scale=1)
|
| 360 |
+
r_status = gr.Markdown(_status("Ready. Press Play: the arena picks the models.", "ok"))
|
| 361 |
+
r_boards = gr.HTML(empty_html("Press <b>Play ranked match</b>. The arena picks the models at random."))
|
| 362 |
+
r_results = gr.HTML()
|
| 363 |
+
with gr.Tab("🏆 Leaderboard"):
|
| 364 |
+
lb_protocol = gr.Radio(PROTOCOL_CHOICES, value="guided", label="Protocol")
|
| 365 |
+
lb = gr.HTML(leaderboard_view("guided"), padding=False)
|
| 366 |
+
lb_refresh = gr.Button("↻ Refresh", variant="secondary")
|
| 367 |
+
with gr.Tab("📖 How it works"):
|
| 368 |
+
gr.Markdown(HOW)
|
| 369 |
+
|
| 370 |
+
match_event = start.click(
|
| 371 |
+
run_match, [models, baselines, protocol, seed, delay], [status, boards, results], concurrency_limit=1,
|
| 372 |
+
)
|
| 373 |
+
stop.click(stop_status, status, status, cancels=[match_event])
|
| 374 |
+
# viewers only watch; the ranked match itself runs in one background thread
|
| 375 |
+
r_play.click(ranked_play, r_protocol, [r_status, r_boards, r_results], concurrency_limit=16,
|
| 376 |
+
concurrency_id="ranked").then(leaderboard_view, lb_protocol, lb)
|
| 377 |
+
lb_protocol.change(leaderboard_view, lb_protocol, lb)
|
| 378 |
+
lb_refresh.click(refresh_leaderboard, lb_protocol, lb)
|
| 379 |
+
demo.load(leaderboard_view, lb_protocol, lb)
|
| 380 |
+
|
| 381 |
+
demo.queue(max_size=32)
|
| 382 |
+
|
| 383 |
+
if __name__ == "__main__":
|
| 384 |
+
demo.launch(css=APP_CSS + CSS + LB_CSS, theme=THEME, ssr_mode=False)
|