Image-Text-to-Text
Transformers
English
gamescaling
game-agent
embodied-agent
keyboard-mouse
continued-pretraining
qwen3_5
Run this model with HF Jobs
Run THUSI-Lab/GameScaling on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs and TRL to fine-tune https://huggingface.co/THUSI-Lab/GameScaling. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/THUSI-Lab/GameScaling on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Evaluate on a benchmark
Use HF Jobs to evaluate https://huggingface.co/THUSI-Lab/GameScaling. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.
Quantize for lower memory use
Use HF Jobs to create a 4-bit version of https://huggingface.co/THUSI-Lab/GameScaling. Push it to a new model repo, then reload it from there and report its memory footprint. Run `hf jobs --help` first to learn the CLI.
Instructions to use THUSI-Lab/GameScaling with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use THUSI-Lab/GameScaling with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="THUSI-Lab/GameScaling")# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("THUSI-Lab/GameScaling", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use THUSI-Lab/GameScaling with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "THUSI-Lab/GameScaling" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "THUSI-Lab/GameScaling", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/THUSI-Lab/GameScaling
- SGLang
How to use THUSI-Lab/GameScaling with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "THUSI-Lab/GameScaling" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "THUSI-Lab/GameScaling", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "THUSI-Lab/GameScaling" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "THUSI-Lab/GameScaling", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use THUSI-Lab/GameScaling with Docker Model Runner:
docker model run hf.co/THUSI-Lab/GameScaling
Default: standard build_system_prompt (reasoning=True) + <think> prefill, any game frame
Browse filesFiles changed (6)
1234567892 unmodified lines1213149151617182 unmodified lines2122231819242526272825 unmodified lines5455565152535457585960616263646566676869706 unmodified lines777879676869708081828384858687151 unmodified lines239240241228229242243244245246---tags:- gamescaling- qwen3_5---
# GameScaling 推理模板
用 GameScaling checkpoint 玩游戏、或把它当 baseline 所需的全部**推理侧**代码:系统提示词2 unmodified lines
```gamescaling/ 核心包,只依赖 requests + Pillow prompt.py 系统提示词。默认是 TRAINING_SYSTEM_PROMPT(不写游戏名) prompt.py 系统提示词(标准 build_system_prompt + GameWorld 版式) policy.py 多轮客户端:历史窗口、图像编码、请求体 action.py 动作格式与反解(200 ms chunk -> 6 x 33 ms 键鼠) keymaps.py 训练词表 <-> 浏览器/Playwright 键名2 unmodified linestests/test_core.py 离线单测(不需要 GPU)```
默认推理是一帧游戏画面:`TRAINING_SYSTEM_PROMPT` 里没有游戏名,user 文本固定为`current game screen`。checkpoint 与起服务目录:默认推理:系统提示词用 `build_system_prompt` 标准格式,每轮 user 是 `current game screen` 加一帧游戏画面,assistant 预填 `<think>`。checkpoint 目录:
| 目录 | 规模 ||---|---|25 unmodified lines
```pythonfrom PIL import Imagefrom gamescaling import TRAINING_SYSTEM_PROMPT, GameScalingPolicy, PolicyConfig
# 默认:系统提示词不写游戏名,输入就是一帧游戏画面。画面按原尺寸送入,不预填 <think>。policy = GameScalingPolicy(TRAINING_SYSTEM_PROMPT, PolicyConfig())from gamescaling import GameScalingPolicy, PolicyConfig, build_system_prompt
# 任意游戏:标准系统提示词(游戏名 + 规则 + 训练词表键位 + think/action 输出格式)system = build_system_prompt( "Doom Battle-1", rules="Kill as many monsters as possible; collect health and ammo.", key_bindings={"W": "Move forward", "S": "Move backward", "A": "Strafe left", "D": "Strafe right", "LB": "Fire"}, mouse_aim=True, # 鼠标控视角的游戏) # reasoning 默认 True,与默认的 <think> 预填一致policy = GameScalingPolicy(system, PolicyConfig()) # 预填 <think>,画面按原尺寸送入policy.reset() # 每局开始调用decision = policy.act(Image.open("frame.png")) # 一次调用 = 一个 200 ms 决策a = decision.action6 unmodified lines不重新按下);鼠标位移 `X/1000*屏宽`、`Y/1000*屏高` 在 200 ms 内分摊或一次性下发均可,三个集成各自的做法见下文。
要写上游戏名和规则时,用 `build_system_prompt(游戏名, rules=..., key_bindings=...)`,客户端仍用`PolicyConfig()`。论文三张表用 `PolicyConfig.preset("omnigamearena" | "vizdoom" | "gameworld")`。`preset("omnigamearena")` 会把画面缩到 854×480,并预填 `<think>`,此时系统提示词要`reasoning=True`。默认口径不绑定某个 benchmark:任意游戏画面 + `build_system_prompt` 标准格式 + 预填 `<think>`。`TRAINING_SYSTEM_PROMPT` 是预训练的通用提示词,只有 action-only 输出格式,和 `<think>` 预填不匹配,只用于消融。复现论文三张表时再改用`PolicyConfig.preset("omnigamearena" | "vizdoom" | "gameworld")`:前两档把画面缩到 854×480;`gameworld` 不预填 `<think>`,提示词要用 `build_gameworld_system_prompt(..., reasoning=False)`。
## 3. 系统提示词规范
151 unmodified lines 时加 `mouse_aim=True`;`reasoning` 与 `think_prefill` 一致。2. 每 200 ms(或暂停时钟下每次决策)截一帧,调用 `policy.act(frame)`。3. 按 §4 执行 `Action`:6 个 33 ms 子步的按住键 + 鼠标位移 + 滚轮。4. 新游戏沿用默认客户端(原尺寸画面、不预填 `<think>`、`TRAINING_SYSTEM_PROMPT` 或 你自己的 `build_system_prompt`)。要对齐论文某一张表时,再改用4. 新游戏沿用默认客户端(原尺寸画面、预填 `<think>`、`build_system_prompt` 标准格式)。 要对齐论文某一张表时,再改用 `PolicyConfig.preset("omnigamearena" | "vizdoom" | "gameworld")`。
## 7. 与论文评测代码的差异59 unmodified lines606162636465666364656667686 unmodified lines75767779807879808183828384868586878859 unmodified lines image_format: str = "jpeg" # jpeg | png jpeg_quality: int = 90 resample: str = "bilinear" # Prefill "<think>" so the model reasons freely and closes it itself. # Off by default: the generic prompt asks for an action string. Turn it on # only together with a system prompt built with reasoning=True. think_prefill: bool = False # Prefill "<think>" so the model reasons freely and closes it itself. The # system prompt must then be built with reasoning=True. think_prefill: bool = True temperature: float = 1.0 max_tokens: int = 2048 stop: list[str] = field(default_factory=lambda: [ACTION_END])6 unmodified lines def preset(cls, benchmark: str, **overrides: Any) -> "PolicyConfig": """Paper-benchmark clients. The default constructor is not one of these.
Default ``PolicyConfig()`` sends the given game frame unchanged and does not prefill ``<think>``. Use a preset only when reproducing a paper table. Default ``PolicyConfig()`` prefills ``<think>`` and sends the given game frame unchanged. Use a preset only when reproducing a paper table. """ presets = { "omnigamearena": cls(image_size=(854, 480), think_prefill=True), "omnigamearena": cls(image_size=(854, 480)), # Free-form reasoning without a stop string: a model that quotes the # format inside <think> would otherwise be cut off mid-thought. "vizdoom": cls(image_size=(854, 480), think_prefill=True, stop=[]), "vizdoom": cls(image_size=(854, 480), stop=[]), "gameworld": cls( image_size=None, image_height=480, image_format="png", resample="lanczos", think_prefill=False, max_tokens=4096, stop=[ACTION_END],70 unmodified lines717273747574757677787923 unmodified lines10310410510510610710710810911011170 unmodified linesMOUSE_AIM_LINE = "- Mouse X Y -> aim / rotate the camera (X>0 right, Y>0 down)"_MOUSE_BUTTON_ALIASES = {"LMB": "LB", "RMB": "RB", "MMB": "MB"}
# Default inference prompt: no game name, no rules. The user turn is one game# frame labeled "current game screen". Named games use `build_system_prompt`.# The generic prompt of the pre-training mixture: no game information at all,# action-only Output Format. Kept for ablations; it does not match a <think># prefill. Inference uses `build_system_prompt`.TRAINING_SYSTEM_PROMPT = '''You are an experienced PC game player, proficient in keyboard and mouse operations. Based on the current game screen and the corresponding historical trajectory, plan the next 200ms of actions, consisting of 6 steps. Each step is spaced 33ms apart. Every step lasts 33ms from its start time until the next step begins.**Output Format**<|action_start|>X Y Z ; k1 k2 k3 ; k4 k5 ; k6 ; k7 ; k8 ; k9 k10<|action_end|>23 unmodified lines rules: str | None = None, key_bindings: Iterable[tuple[str, str]] | dict[str, str] | None = None, mouse_aim: bool = True, reasoning: bool = False, reasoning: bool = True,) -> str: """Key-list layout for a named game (ViZDoom, OmniGameArena, or a new game). """Standard key-list layout for any game (ViZDoom, OmniGameArena, or a new game).
``key_bindings`` maps training tokens to what they do, e.g. ``{"W": "Move forward", "LB": "Fire"}``; ``LMB``/``RMB``/``MMB`` are accepted60 unmodified lines616263646465666768697071727374717273747511 unmodified lines87888992939091929360 unmodified lines
def test_finalize_restores_prefill_and_stop(): cfg = PolicyConfig(think_prefill=True) cfg = PolicyConfig() out = finalize("\n\n</think>\n\n<|action_start|>0 0 0 ; W ; ; ; ; ; ", "stop", cfg) assert out.startswith("<think>") and out.endswith("<|action_end|>") assert parse_action(out).steps[0] == ["W"]
def test_request_shape(): plain = build_request([{"role": "user", "content": "current game screen"}], PolicyConfig()) assert plain["messages"][-1]["role"] == "user" assert "continue_final_message" not in plain cfg = PolicyConfig(model="m", think_prefill=True) cfg = PolicyConfig(model="m") assert cfg.image_size is None body = build_request([{"role": "system", "content": "s"}], cfg) assert body["messages"][-1] == {"role": "assistant", "content": "<think>"} assert body["continue_final_message"] and not body["add_generation_prompt"]11 unmodified lines
def test_prompt_sections_in_order(): p = build_system_prompt("Doom", rules="Kill monsters.", key_bindings={"W": "Forward", "LMB": "Fire"}, reasoning=True) p = build_system_prompt("Doom", rules="Kill monsters.", key_bindings={"W": "Forward", "LMB": "Fire"}) order = ["currently playing Doom", "**Game Rules**", "**Common Keys in Doom**", "- LB -> Fire", "**Action only (usual)**", "**Explanation**", "**Key Naming Rules**"] idx = [p.index(s) for s in order]README.md+27-13
gamescaling/__pycache__/policy.cpython-310.pyc
gamescaling/__pycache__/prompt.cpython-310.pyc
gamescaling/policy.py+7-8
gamescaling/prompt.py+5-4
tests/test_core.py+4-7