Spaces:
Running
Running
Download app/practice.py from imaan3/optorigbench-tools: direct link, hf CLI and curl.
- Browser
- Download file 1.67 kB
-
https://huggingface.co/spaces/imaan3/optorigbench-tools/resolve/main/app/practice.py
- Command line
-
hf download hf://spaces/imaan3/optorigbench-tools/app/practice.py
-
curl -L -o practice.py https://huggingface.co/spaces/imaan3/optorigbench-tools/resolve/main/app/practice.py
1.67 kB
| """Which seeds the culture bench may build a dish from: practice seeds only (PRACTICE_LO..PRACTICE_HI), a range | |
| no benchmark seed falls in, unless OWNER_MODE is set. Any other requested seed is mapped into the practice range. | |
| """ | |
| from __future__ import annotations | |
| import os | |
| import secrets | |
| PRACTICE_LO = 200_000 | |
| PRACTICE_HI = 299_999 | |
| SPAN = PRACTICE_HI - PRACTICE_LO + 1 | |
| def owner_mode() -> bool: | |
| return os.environ.get("OWNER_MODE", "").strip().lower() in ("1", "true", "yes", "on") | |
| def is_practice(seed: int) -> bool: | |
| return PRACTICE_LO <= seed <= PRACTICE_HI | |
| def practice_seed(seed=None) -> int: | |
| """The practice seed a requested seed becomes (anything not a whole number counts as none).""" | |
| try: | |
| s = int(seed) if seed is not None and not isinstance(seed, bool) and float(seed) == int(seed) else None | |
| except (TypeError, ValueError, OverflowError): | |
| s = None | |
| if s is None: | |
| return PRACTICE_LO + secrets.randbelow(SPAN) | |
| return s if is_practice(s) else PRACTICE_LO + s % SPAN | |
| def new_args(args: dict) -> dict: | |
| """A `new` request's arguments with the seed made safe (unchanged in owner mode).""" | |
| if owner_mode(): | |
| return args | |
| out = dict(args) | |
| out["seed"] = practice_seed(args.get("seed")) | |
| return out | |
| def scenario_menu(rows: list[dict]) -> list[dict]: | |
| """The scenario menu without the benchmark's seeds: each row's seed becomes a practice seed (held_out kept).""" | |
| if owner_mode(): | |
| return [dict(r, held_out=r.get("seed") is None) for r in rows] | |
| return [dict(r, held_out=r.get("seed") is None, | |
| seed=PRACTICE_LO + i + 1) for i, r in enumerate(rows)] | |