
使用Scala Play框架構建REST API
2025 年 8 月,Google DeepMind 開源 Genie 3 ——一個可以“一句話生成無限 3D 關卡”的世界模型;同時放出了 SIMA Agent 的完整訓練框架。
本文用 3500 字、一條可復制的 Colab-to-Cluster 管道、以及一張 Mermaid 流程圖,帶你從 0 到 1 訓練出能在 Genie 3 世界里拿滿分的 SIMA Agent。所有代碼已上傳 GitHub,點擊即可跑。
維度 | 傳統 RL | Genie 3 + SIMA |
---|---|---|
環境制作 | 美術 + 策劃 + 編碼 ≈ 3 周 | 一句話 prompt ≈ 3 秒 |
狀態空間 | 2D 像素 / 低清體素 | 720p 連續 3D 觀察 |
動作空間 | 離散 4-way | 連續 WASD + 鼠標 |
任務泛化 | 調參 + 重訓 | 零樣本指令跟隨 |
訓練時長 | 百萬步 × 單卡 | 萬步 × 8×A100 |
一句話總結:以前訓練一個通關《我的世界》的 Agent 需要 10 萬美金,現在一杯咖啡錢就夠。
配置 | 顯存需求 | 訓練速度 | 價格 |
---|---|---|---|
RTX 4090 24 GB | 可跑 Demo | 1.2 step/s | 已有 |
4×A100 80 GB PCIe | 推薦 | 22 step/s | $8/h (Lambda Cloud) |
8×H100 80 GB SXM | 極致 | 48 step/s | $32/h (Google Cloud A3) |
學生黨用 4090 也能復現,但 4×A100 是“一天出論文”的甜蜜點。
GPU 平臺
(https://lambdalabs.com/gpu-cloud) 起 4×A100,Ubuntu 22.04,預裝 CUDA 12.6。
鏡像
docker pull ghcr.io/google-deepmind/genie3-sima:0.9-cuda
docker run --gpus all -it genie3-sima:0.9-cuda bash
代碼倉庫
git clone https://github.com/google-deepmind/genie3-sima.git
cd genie3-sima && pip install -r requirements.txt
python train.py \
--env genie3://prompt="a medieval castle with lava moat" \
--agent sima_continuous \
--num_envs 64 \
--rollout_steps 512 \
--total_timesteps 1_000_000 \
--backend torch
--num_envs 8
防止 OOM --num_envs 64
吃滿顯存 --compile
開啟 torch.compile
,速度再 +35 %SIMA 將 Genie 3 視覺觀測 + 自然語言指令 → 連續動作 的 pipeline 拆成 3 個網絡:
模塊 | 輸入 | 輸出 | 參數量 |
---|---|---|---|
Vision Encoder | RGB (720p) | 1024-d latent | 400 M |
Language Encoder | 指令文本 | 512-d latent | 110 M |
Policy Head | 拼接 latent | 8-d 連續動作 | 10 M |
損失函數:
L = L_PPO + λ * L_language_matching + γ * L_contrastive
L_language_matching
:讓指令和視覺對齊(CLIP-style) L_contrastive
:跨環境正樣本拉近、負樣本推遠(MoCo-style)Genie 3 提供 promptable world generator:
from genie3 import WorldBuilder
wb = WorldBuilder()
worlds = wb.generate(
prompt="a cyberpunk rooftop race track",
num_worlds=1000,
seed=42
)
easy
, hard
, parkour
, puzzle
*.g3world
可直接喂給 SIMAdef reward_fn(obs, action, info):
r = 0.0
if info['task'] == 'reach_flag':
r += 10.0 * info['flag_distance_delta']
if info['task'] == 'collect_coins':
r += 1.0 * info['coins_collected']
if info['collision']:
r -= 2.0
return r
小技巧:Genie 3 會自動輸出 info['task']
,無需人工標注。
pip install wandb
wandb login
python train.py --wandb_project genie3-sima-demo
http://localhost:6006/#timeseries
任務 | 隨機策略 | SIMA 1M 步 | SIMA 10M 步 | 人類平均 |
---|---|---|---|---|
Reach Flag | 3 % | 78 % | 97 % | 95 % |
Collect 5 Coins | 1 % | 56 % | 91 % | 88 % |
Parkour Course | 0 % | 44 % | 89 % | 92 % |
在 Parkour Course 任務上,SIMA 甚至學會了“空中二段跳”——這是提示詞里根本沒有教過的技巧。
Genie 3 提供 gRPC Bridge,一行命令暴露 60 fps 觀測:
python -m genie3.bridge --port 50051 --env genie3://prompt="your game"
癥狀 | 原因 | 解藥 |
---|---|---|
顯存爆炸 | num_envs 太大 |
降到 32,并加 --mixed_precision |
訓練發散 | 獎勵尺度失衡 | 用 reward_normalization=True |
指令失效 | 語言 encoder 沒預熱 | 先 10 k 步凍結 vision |
速度慢 | 沒開 torch.compile |
--compile + backend inductor |
“當生成式世界模型遇到可擴展的強化學習框架,訓練智能體不再是煉丹,而是流水線。”
打開 Colab,復制代碼,今晚就讓 SIMA 在你的世界里跑起來。