
使用Scala Play框架构建REST API
“当别人的强化学习环境还在 2D 迷宫里撞墙时,我们已经把智能体扔进了 720p 的 3D 开放世界——它用 30 秒学会攀岩、2 分钟偷走宝箱、5 分钟后开始‘调戏’NPC。”
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 在你的世界里跑起来。