Dreaming Bird 是一个 decoder-only transformer 世界模型(world model):它"就是" Flappy
Bird 的物理引擎。输入最近若干帧的量化状态(bird_y / pipe_dx / gap_y / status,每帧 4 个
token)加上玩家动作(flap / no-flap),自回归地生成下一帧状态。本仓适配其 small
版本(small_pipes.pt / model.onnx,约 11.3M 参数):
S_t, A_t, S_{t+1}, ...,
episode 以 <BOS> 开头);原始模型:https://huggingface.co/gmmeyer/gpt-bird (MIT License) 官方源码:https://github.com/gmmeyer/gptbird
适配内容:在华为昇腾 NPU 上重建 DreamGPT 并加载官方 checkpoint 权重(stub-unpickler 方式 绕开对原仓库 Python 包的运行时依赖),完成真实 npu:0 推理、与世界模型参考物理引擎的 一步预测精度验证、CPU-NPU 一致性验证与性能测试。
| 项目 | 值 |
|---|---|
| NPU | 2 × Ascend910(Ascend910_9362,单卡 64GB HBM),实际使用 npu:0 |
| torch | 2.9.0+cpu |
| torch_npu | 2.9.0.post1+gitee7ba04 |
| CANN | 8.5.1 |
| dtype | float32 |
| OS | Linux aarch64 |
设备证据:assets/npu_device_call.png(来自本次真实 npu-smi info 与
torch.npu.is_available() 输出)。
pip install -r requirements.txt权重下载(国内镜像):
HF_ENDPOINT=https://hf-mirror.com python3 -c \
"from huggingface_hub import snapshot_download; snapshot_download(repo_id='gmmeyer/gpt-bird', local_dir='./gptbird_cache/gpt-bird')"
export GPTBIRD_MODEL_DIR=./gptbird_cache/gpt-bird注意:本仓不包含权重文件;inference.py 通过环境变量 GPTBIRD_MODEL_DIR(默认
./gptbird_cache/gpt-bird)定位本地权重目录。
python inference.py # 默认 npu:0;--device cpu 可切换 CPU 对照默认执行四步:加载官方 small_pipes.pt 权重 → 参考物理引擎轨迹上的 teacher-forced
一步预测评测(24 局)→ 相同输入下 CPU vs NPU logits 一致性检查 → 固定动作序列回放的
自回归 rollout 对比与 cacheless dream 性能测试。任何一项失败退出码非 0。
以下数字为本次在 npu:0 上的真实输出(完整日志见 assets/model_result.png 渲染的
真实终端画面,来自 python inference.py --episodes 24 的 stdout):
params(tied-counted-once): 11.3M device: npu:0 dtype: fp32
=== one-step prediction vs reference physics engine ===
episodes: 24
frames_evaluated: 2174
bird_y_exact: 0.9885 # 官方 README: 98.6%
bird_y_within1: 1.0 # 官方 README: 100%
pipe_dx_exact: 1.0
gap_y_stable_exact: 0.9991 # 官方 README: 99.96%
gap_y_switch_validity: 1.0 # 官方 README: 100%
status_exact: 0.9963
collision_within1_rate: 0.917 # 官方 README: 94.9%
=== autoregressive rollout vs oracle ===
frames_compared: 63
malformed_tokens: 0
mean_bird_y_bin_error: 0.0476
max_bird_y_bin_error: 1
first_divergence_frame: 41
drift_gt3bin_first_frame: none(<3 bins)
RESULT: PASS (world-model one-step eval + CPU/NPU consistency + dream rollout, device="npu:0)"说明:这是固定种子、固定动作序列上的确定性验证(teacher-forced 一步预测 + 短程自回归 回放对比),不是对完整游戏分布的大规模评测;但指标口径与官方 README 报告值一致且吻合。
相同 8 个真实轨迹上下文窗口(最长 400 token),分别在前缀 CPU 模型与 npu:0 模型上前向, 比较末位 logits:
logits_max_abs_diff: 0.0446 # fp32 数值差异
logits_mean_abs_diff: 0.0284
greedy_slot_argmax_agreement: 1.0 # 32/32 个状态槽位贪心 token 完全一致即 NPU 与 CPU 在所有受约束生成槽位上的 argmax 决策 100% 一致。
cacheless dream(每帧 3 次 forward 生成 by/dx/gap,status 由几何判定),context 约 1200 token、batch 1、fp32:
warmup: 3, frames_timed: 30, torch.npu.synchronize() 前后计时
per_frame_ms_avg: 8.95 p50: 8.93 p90: 9.02 p95: 9.06
dream_fps: 111.7 (>60fps 实时线)
peak_npu_mem_mb: 127.6三张 PNG 均由本次真实日志渲染(raw 终端风格,含源日志 SHA-256):
assets/agent_workflow.png — 下载校验、侦察、checkpoint 检查、NPU 检查、端到端运行;assets/npu_device_call.png — npu-smi info、torch.npu.is_available()、设备名与参数设备;assets/model_result.png — python inference.py --episodes 24 完整任务输出与 PASS 判定。small 版(含管道完整玩法);nano_nopipes.pt 为无管道 Phase-2 模型,本仓
未单独验证。Hardware: NPU, NPU, Ascend, Ascend910, computer-vision, world-model, flappy-bird, reinforcement-learning, game