Ascend NPU adaptation of gmmeyer/gpt-bird ("Dreaming Bird"), a small GPT-2-style decoder transformer that plays Flappy Bird. Given a window of discretized game-state tokens it predicts the player's next action (flap / no-flap).
The checkpoint (small_pipes.pt, n_layer=6, d_model=384, n_head=6, block_size=1280, vocab 232)
is a nanoGPT-style decoder: token embedding + position embedding + 6 transformer blocks with
RMSNorm pre-norm + causal self-attention + GELU MLP, and a weight-tied LM head. Every frame is
4 tokens in slot order [bird_y, pipe_dx, gap_y, status] using the disjoint id ranges from
config.json (offsets by=4, dx=132, gap=196, status=228, action=230).
All inference runs on npu:0 via get_device(), with an automatic CPU fallback if the NPU
cannot be initialized. No accelerator device calls other than torch_npu.
pip install -i https://repo.huaweicloud.com/repository/pypi/simple/ -r requirements.txt
source /usr/local/Ascend/ascend-toolkit/set_env.sh
export ASCEND_RT_VISIBLE_DEVICES=0
export ASCEND_GLOBAL_LOG_LEVEL=3Weights auto-download from the HF mirror (hf-mirror.com) on first run and are cached at
./model_weights/gmmeyer/gpt-bird/ (config.json, small_pipes.pt, nano_nopipes.pt, model.onnx).
The cache is reused on subsequent runs; large weight files stay out of git.
# predict the next action for a token window (comma or space separated)
python inference.py --input "228,132,196,4"
# run a short autonomous Flappy Bird episode on NPU (engine physics + model policy)
python inference.py --play --frames 200 --seed 0--input prints next-action probabilities (noflap=230 / flap=231) + a sampled action.
--play runs the real physics engine, uses the model on npu:0 to choose flap/no-flap each
frame, and reports the score (frames survived) plus per-frame action probabilities.
python inference.py --serve # uvicorn 0.0.0.0:8000GET / -> HTML form (token-sequence text box + "play episode" button)POST /predict -> accepts JSON {"tokens": "228,132,196,4"} or a multipart form field;
returns action probabilities + sampled action. Use
{"tokens": "__PLAY__"} to run an autonomous episode.