Methodology
How the environment, learner and self-play fit together, and what they produced.
16 min read
How our bots are trained: the ideas we borrowed, the code that does the training, the results so far, and how training was made faster. New to RL? Read the ML primer first.
Prior art#
Two community references shaped the design. We read them for ideas and constants; neither is run as code. More on both: External projects.
Necto#
The community bot that won the RLBot Championship 2022; its successor Nexto is in the same repo
(.external/Necto @ 2e6ed7d). It trained by PPO with self-play in the real game, on many
distributed workers, with an attention network over every car, the ball and the boost pads.
We took: the 90-action table, past-version opponents 20% of the time, its random, kickoff-like and goalie starting states, the score-difference clip, the team goal reward of 10, and team spirit.
We didn't take: the attention network (we use a plain MLP), distributed real-game workers (RocketSim runs in-process), replay starting states (no dataset), or its reward. Its flip-reset detector is noted for mechanics work.
As opponents: Necto's and Nexto's released models now play inside our environment (results).
Lucy-SKG#
A 2023 paper (Moschopoulos et al., arXiv:2305.15801) that kept Necto's network and PPO and redesigned the reward. At 1 B steps each, its bot beat Necto 300–54 and Nexto 300–4 in single-goal 2v2 games.
Its main ideas: rewards that multiply their parts (KRC), parameterised distance rewards, potential-based shaping, a smaller observation with the last 5 actions, and two auxiliary prediction tasks. We implemented almost all of them and A/B-tested each rather than taking it on faith:
| Idea | Result here |
|---|---|
| The paper's reward table | Reached 0.8 vs ball_chaser in half the steps of a simple dense reward (52.4 M vs 104.9 M), and won 0.76–0.79 head to head |
| Potential shaping | Works as the math predicts (tested on real episodes) |
| Last 5 actions in the observation | No measurable difference (0.510 head to head) |
| Reward-prediction auxiliary task | Broke 1v1 training (0.002 head to head); off by default |
| State-representation auxiliary task | No difference, 1.8× update time; off by default |
| Half-life discounting, starting states (no replays), end conditions | Implemented as in the paper |
Not adopted: the attention network, device-alternating PPO and the paper's Win % metric. Every item with its tests: Lucy-SKG coverage.
The training stack#
- the environment: RocketSim arenas stepped in batches (Rust)
- crates/rlenv-py/ Python bindings, built as
physlab_rl._native - the learner (PyTorch, uv)
- tasks/ training task files (JSON)
- runs/ run outputs (gitignored)
Environment (crates/rlenv)#
BatchEnv steps many independent RocketSim arenas per call, in parallel on all CPU threads.
Deterministic. An episode depends only on its task file, seed and actions; results are identical for any thread count.
Separate seeds. Evaluation seeds have bit 63 set and training seeds never do, so training never sees an evaluation episode.
Events come from physics. A touch is RocketSim's
CarHitBallevent, never a distance check.Every episode is a scenario. Any episode can be exported and replayed exactly with
physlab run, demolitions included.Two task kinds. Single-agent tasks have one car and a success test. Match tasks run 1v1 to 3v3 with every car an agent, and end at the first goal or a timeout. Each car sees the field rotated so it attacks +Y.
No input latency. An action applies from the next tick, which keeps exports replayable. A bot run through RLBot would see one tick more.
Details: Environment conventions, Match mode.
Task files#
A task is a JSON file in tasks/. Unknown fields are rejected and every shipped task is tested. A
trimmed example, the last stage of the single-agent curriculum:
{
"task_schema_version": 1,
"id": "aerial-touch-v1",
"tick_skip": 8,
"episode_seconds": 5,
"obs": { "action_stack": 5 },
"initializer": {
"car": { "position_uu": [[-2000, 2000], [-3000, 3000], [17, 17]],
"yaw_rad": [-3.14159265, 3.14159265], "boost": [50, 100] },
"ball": {
"placement": { "kind": "near_car", "distance_uu": [600, 1600],
"bearing_rad": [-3.14159265, 3.14159265], "z_uu": [500, 1200] },
"linear_velocity_uu_s": [[-250, 250], [-250, 250], [200, 500]]
}
},
"success": { "kind": "touch", "min_ball_z_uu": 250, "require_car_airborne": true },
"failure": { "ball_hits_ground": true },
"utilities": { "approach": { "krc": ["face_ball", "distance_to_ball", "velocity_to_ball"] } },
"rewards": { "success": 10, "failure": -2, "time": -0.01 },
"potentials": { "approach": 2.0 },
"shaping_gamma": 1.0,
"eval": { "seed_base": 3000000, "episodes": 256 }
}| Task | Kind | Purpose |
|---|---|---|
ground-touch-v1 | single agent | Curriculum stage 0: touch a resting ball |
aerial-touch-easy-v1, aerial-touch-v1 | single agent | Curriculum stages 1–2: touch a rising ball in the air before it lands |
ground-touch-dense-v1, ground-touch-nostack-v1 | single agent | A/B variants |
match-1v1-v1, match-2v2-v1 | match | The full Lucy-SKG reward |
match-1v1-simple-v1, match-1v1-nostack-v1 | match | A/B variants: simple reward; no action stack |
All fields: Task file format.
Learner (python/physlab_rl)#
PPO over the 90 actions, in the style of CleanRL. The Python bindings release the GIL and copy into fresh numpy arrays; through Python the environment still runs about 1.44 M steps/s.
| Setting | Single-agent | Match |
|---|---|---|
| Steps per update | 131,072 (4096 envs × 32) | 131,072 (4096 car rows × 32) |
| Minibatches × epochs | 8 × 4 | 8 × 3 |
| Network | actor and critic MLPs, 256-256 | 512-512-256 (0.93 M parameters, 1v1) |
| Learning rate | 3e-4, annealed | 2e-4, constant (self-play has no natural end) |
| Discount half-life | scales with episode length, 1.5–4 s | 5 s (1v1), 10 s (2v2) |
| GAE λ, clip, entropy, value coef. | 0.95, 0.2, 0.01, 0.5 | same |
Untuned; the source of every value is in Defaults and their sources.
The training loop#
just train / just train-match (python -m physlab_rl.train):
Set up: load the task, build the environment on all CPU threads, write the run record (manifest), seed every random generator.
Play 32 steps in every game. The learner picks actions on the GPU; frozen past versions run in one batched pass; scripted bots run in Rust.
Score each step's advantage, separately per car, adding the critic's estimate where a time limit cut an episode short.
Update the policy with PPO, on the learner's own cars only.
Log one line to
metrics.jsonlper update.Every so often: save a past version into the opponent pool (every 10 M steps), evaluate on held-out seeds and refit ratings (about every 21 M steps for matches), and checkpoint.
Stop at
--total-steps, at--target-eval-success, or when aSTOPfile appears in the run directory. The final evaluation and checkpoint are still written.
A test (python/tests/test_selfplay.py) checks the learner's stored data against what the
environment actually did, at every update.
Self-play and the opponent pool#
One policy drives every car. Blue is always the learner. Each episode, Orange is:
a frozen past version with probability 0.2;
the scripted
ball_chaserwith probability--opponent-scripted-prob(default 0);otherwise the learner itself, so both cars produce training data.
The pool keeps 20 past versions, one every 10 M steps, picked with weight 0.9^age (recent ones more
often, not by rating). All of them run in one batched pass, which cut opponent inference from 0.50 s
to 0.16 s per update with 6 in play. A warm start (--init-checkpoint) carries the pool over. In
the main run, 90.3% of samples were the learner's. Details:
Self-play learner.
Evaluation and ratings#
Single-agent tasks: all 256 held-out seeds, best action each step, success rate with a Wilson 95% interval.
Match tasks: single-goal games from held-out kickoffs. Win = Blue scores, loss = Orange scores, draw = timeout. Actions are sampled with a fixed seed; with the best action on both sides, each of the 5 kickoff spots would replay the same game.
Opponents:
ball_chaser, Necto and Nexto (--eval-bots, on by default), and earlier checkpoints 1, 2, 4, 8 and 16 evaluations back.Ratings: Bradley–Terry on the Elo scale over every game,
ball_chaserfixed at 1000.just league-matchruns a round robin over a run's checkpoints afterwards.
Results and caveats: Bot standings.
A run, end to end#
The main 1v1 run (runs/selfplay/main-1v1-s11/):
python -m physlab_rl.train --task tasks/match-1v1-v1.json --total-steps 1_500_000_000 \
--eval-every 80 --seed 11 --run-dir runs/selfplay/main-1v1-s11 # STOP file at 90 min
python -m physlab_rl.league runs/selfplay/main-1v1-s11 --every 10 --episodes 128
python -m physlab_rl.evaluate runs/selfplay/main-1v1-s11/final.pt --opponents ball_chaser idle \
runs/selfplay/main-1v1-s11/checkpoints/step_{104857600,524288000,838860800,943718400}.pt \
--export 1| File | Contents |
|---|---|
manifest.json | Written before training, then read-only: command line, a hash of all source code (the repo has no commits yet), the task, every setting, seeds, library versions, GPU state |
metrics.jsonl | One line per update, evaluation and rating refit (Telemetry) |
checkpoints/step_<n>.pt, best.pt, final.pt | Model, optimiser and normaliser state, config, task, random-generator states |
pool/, pool.json, ratings.json | Past versions and the rating table |
summary.json | Stop reason, steps, wall time, final evaluation, steps to 0.5/0.8/0.9 |
eval/, eval_scenarios/ | Standalone evaluations and exported games (as scenarios) |
league/ | The round robin's results and ratings |
The local Command Center shows all of this live, for every run.
Results so far#
Single-agent curriculum#
Held-out success on 256 seeds, seed 1, each stage starting from the previous stage's best
checkpoint (runs/t1/):
| Stage | Task | Steps | Wall | Steps to 50 / 80 / 90 / 95% | Final held-out success |
|---|---|---|---|---|---|
| 0 | ground-touch-v1 (from scratch) | 19.9 M | 1.2 min | 2.6 / 2.6 / 3.3 / 3.3 M | 256/256 [0.985, 1.000] |
| 1 | aerial-touch-easy-v1 | 87.7 M | 4.7 min | 15.7 / 18.4 / 18.4 / 21.0 M | 256/256 [0.985, 1.000] |
| 2 | aerial-touch-v1 | 499.9 M | 27.1 min | 5.2 / 18.4 / 138.9 / 191.4 M | 246/256 = 0.961 [0.930, 0.979] |
- eval/success_ratelast 0.961
- eval/ci95_lolast 0.93
- eval/ci95_hilast 0.979
Data
| Series | Steps range | First | Last | Min | Max | Points |
|---|---|---|---|---|---|---|
| eval/success_rate | 2.62M – 500M | 0.469 | 0.961 | 0.469 | 0.965 | 191 |
| eval/ci95_lo | 2.62M – 500M | 0.409 | 0.93 | 0.409 | 0.935 | 191 |
| eval/ci95_hi | 2.62M – 500M | 0.53 | 0.979 | 0.53 | 0.981 | 191 |
The remaining failures are mostly balls behind the car or low and slowly rising; some may be impossible. More: Capabilities.
Main 1v1 self-play run#
runs/selfplay/main-1v1-s11/: the full Lucy-SKG reward, seed 11, stopped at 90 minutes.
Scale: 1.024 B steps in 90 minutes, 189.6 k steps/s including evaluations.
Healthy: no NaNs in 7,809 updates; entropy fell from 4.50 to 2.84 and stayed stable.
Behaviour: touches took off at 25–35 M steps and levelled at about 60 per car-minute by 200 M. Shots kept rising, from 4.0 to 10.1 per car-minute between 105 M and 1024 M.
Final bot (256 held-out kickoffs): 241/0/15 vs
ball_chaser(0.941 [0.906, 0.964]); 0.949, 0.641 and 0.537 against its own 105 M, 524 M and 943 M checkpoints.League: ratings rose from 830 to 1669 over 11 checkpoints and 7,040 games.
eval/ball_chaser/score, last 0.961
Data
| Series | Steps range | First | Last | Min | Max | Points |
|---|---|---|---|---|---|---|
| eval/ball_chaser/score | 10.5M – 1.02B | 0.438 | 0.961 | 0.438 | 0.992 | 98 |
- match/touch_steps_per_car_minutelast 59.3
- match/shots_per_car_minutelast 10.1
Data
| Series | Steps range | First | Last | Min | Max | Points |
|---|---|---|---|---|---|---|
| match/touch_steps_per_car_minute | 131k – 1.02B | 0 | 59.3 | 0 | 69.9 | 300 |
| match/shots_per_car_minute | 131k – 1.02B | 0 | 10.1 | 0 | 10.9 | 300 |
The in-run ratings went flat mid-run because each checkpoint was only compared with near neighbours. That led to wider opponent spacing and the league tool (Bot standings).
Flip-preserving 1v1 run (10 B steps)#
Pure self-play: the bot never played Necto or Nexto in training. One lineage of warm starts under
runs/selfplay/: flip-1v1-s14 (from scratch, 210 M steps), fork210/drill-s15 (300 M),
main2-1v1-s16 (63 M), main10b-1v1-s17 (1.01 B) and main10b-1v1-s18 (8.42 B). The task was
match-1v1-flip-v1 (Necto's ang_vel and touch_grass terms from step 0), then
match-1v1-flip-kickoff-v1 (plus a 5 s kickoff drill) from 210 M on.
| 256 held-out kickoffs | Old main bot (1 B) | This run at 1.58 B | This run at 10 B |
|---|---|---|---|
| vs Necto | 0.164 | 0.348 | 0.719 [0.661, 0.770] |
| vs Nexto | 0.023 | 0.148 | 0.242 [0.194, 0.298] |
| vs old main bot | – | 0.859 | 0.980 |
What made the difference: the flip terms keep dodges alive (the old run stopped dodging by 115 M steps), the kickoff drill breaks the 50/50 of mirror-image kickoffs, and scale.
A false plateau at 1.9 B steps#
At 1.9 B cumulative steps the bot was exactly even with its 1.58 B starting checkpoint (0.50 after 335 M steps), and about 0.4 against Necto. We called that a plateau and proposed changing the setup. The run kept going while that was being decided, and it was wrong:
| Cumulative steps | 1.7 B | 2.1 B | 2.9 B | 3.3 B | 3.8 B | 6.7 B | 10 B |
|---|---|---|---|---|---|---|---|
| vs Necto (128 kickoffs) | 0.37 | 0.42 | 0.49 | 0.52 | 0.66 | 0.71 | 0.66 |
The genuine flattening came only in the last ~3 B steps (about 0.6–0.75 against Necto, and about 0.5 against the bot's own recent checkpoints).
Lesson: self-play progress comes in steps, and a few hundred million flat steps is not a plateau. Before changing a run, let the flat stretch last at least as long as the gain before it (here, billions of steps, not 335 M), and judge it against long-range and fixed opponents (older checkpoints, the league, Necto and Nexto), not against near neighbours.
A/B experiments#
One to three seeds each, so treat small differences as noise.
| Question | Runs | Result |
|---|---|---|
| Potential vs dense shaping, action stack, RP head on ground touch | runs/ab-ground/, 3 seeds × 8 M | All reached 80% in 2.4–4.2 M steps, within the seed spread. RP cut throughput 2.3× |
| RP head on aerial-touch-easy | runs/ab-aerial-easy/, 2 seeds × 50 M | 80% at 14.8 M ± 1.4 M with RP vs 13.1 M ± 0.9 M without, at 2.8× the wall time |
| Lucy-SKG vs a dense linear reward (1v1) | runs/selfplay/ab/, seed 21, 120 M | 0.5 / 0.8 / 0.9 vs ball_chaser at 31.5 / 52.4 / 78.6 M vs 73.4 / 104.9 M / not reached. Head to head 0.762 and 0.789 for Lucy-SKG |
| Auxiliary tasks and action stack (1v1) | runs/selfplay/ab/, seed 21 | RP collapses training (0.002 head to head). SR neutral (0.52–0.54). No action stack: 0.510 |
Full tables: Lucy-SKG A/B experiments, Reward A/B, Lucy-SKG ablations.
Making training fast#
The goal is less wall-clock time to a skill, not just more steps per second: doubling steps/s is no win if it takes twice the steps. So:
Options that only change float rounding are on by default.
Options that change the learning itself needed a training A/B before becoming defaults.
Every option is a flag, recorded in the run's manifest.
The environment is not the bottleneck#
One BatchEnv holds thousands of arenas in one process: no game client, no sockets. Two settings
matter: RocketSim's Balanced memory mode (12.29 M vs 6.99 M ticks/s on 28 threads; Heavy arenas
thrash the cache) and a link-time-optimised build (release-lto, 8–12% faster).
BatchEnv, 28 threads, random actions, full reward | Steps/s |
|---|---|
ground-touch-v1 (1 car) | 1.93 M |
match-1v1-v1 (2 cars) | 2.20 M |
match-2v2-v1 (4 cars) | 2.57 M |
Even in the single-agent curriculum, playing 131 k steps took 0.09 s against 0.24 s for the PPO update, so the learner was the bottleneck, and most speed work went there. More: Benchmarks.
Learner throughput#
Median milliseconds per 131,072-step update on match-1v1-v1 (just bench-learner, Rocket League
running on the same GPU):
| Arm | Cycle | Env | Rollout | Update | Steps/s | vs legacy |
|---|---|---|---|---|---|---|
| legacy (before this work) | 632 | 98 | 125 | 409 | 207 k | 1.00× |
| default: fused Adam, pinned memory, deferred bootstrap | 598 | 97 | 94 | 408 | 219 k | 1.06× |
| + bf16 autocast | 451 | 99 | 106 | 246 | 291 k | 1.40× |
| + CUDA graphs for the update | 411 | 99 | 104 | 209 | 319 k | 1.54× |
| + CUDA graph for rollout inference | 369 | 96 | 64 | 209 | 355 k | 1.71× |
| + overlapped update, decoupled correction (the match default) | 239 | 94 | 128 | 241 (hidden) | 549 k | 2.65× |
bf16 autocast (
--amp bf16) runs forward passes in bfloat16 in both rollout and update: the biggest single gain.CUDA graphs (
--cuda-graphs,--cuda-graph-act) replay recorded GPU work instead of launching each kernel, cutting launch overhead from about 50 ms to 4 ms per update.Overlapped update (
--overlap-update) learns on a second thread while the next rollout plays with the previous weights, so the cycle is about the longer of the two instead of their sum.Decoupled correction (Hilton et al., 2021) makes the overlap safe. With classic PPO on the one-update-old data, learning stalled for about 60 M steps: don't use
--overlap-correction none.torch.compilegave nothing over CUDA graphs and stays optional.
Every flag and the remaining rows: Learner speed.
Fixed wall-clock A/B#
The deciding test gave each arm the same budget, about 1200 s of training on match-1v1-v1
(evaluations excluded), evaluating every 40 updates on 256 kickoffs against ball_chaser
(runs/perf/ab/):
| Arm | Seed | Steps in budget | Steps to 0.5 / 0.8 / 0.9 | Training s to 0.8 | Wall s to 0.8 (with evals) | Final score vs ball_chaser |
|---|---|---|---|---|---|---|
base: legacy flags | 11 | 242 M | 26.2 / 52.4 / 68.2 M | 266 | 331 | 224/0/32 = 0.875 |
base | 12 | 223 M | 36.7 / 52.4 / 78.6 M | 284 | 351 | 254/0/2 = 0.992 |
fast: the fast set | 11 | 536 M | 31.5 / 52.4 / 89.1 M | 120 | 189 | 249/0/7 = 0.973 |
fast | 12 | 538 M | 31.5 / 47.2 / 78.6 M | 101 | 157 | 251/0/5 = 0.980 |
fastep2: fast + --update-epochs 2 | 11 | 548 M | 36.7 / 68.2 / 99.6 M | 146 | 242 | 255/0/1 = 0.996 |
gact: bf16 + both CUDA graphs, no overlap | 11 | 388 M | 31.5 / 57.7 / 62.9 M | 172 | 239 | 252/0/4 = 0.984 |
eval/success_rate, last 0.875
Data
| Series | Time range | First | Last | Min | Max | Points |
|---|---|---|---|---|---|---|
| eval/success_rate | 0.511 min – 23.6 min | 0.418 | 0.875 | 0.418 | 0.977 | 47 |
eval/success_rate, last 0.973
Data
| Series | Time range | First | Last | Min | Max | Points |
|---|---|---|---|---|---|---|
| eval/success_rate | 0.265 min – 26.8 min | 0.441 | 0.973 | 0.404 | 1 | 103 |
Head to head (runs/perf/ab/h2h/, 256 kickoffs from each side; the first-named arm's score):
| Pairing | Seed | As Blue | As Orange |
|---|---|---|---|
fast final (536 M) vs base final (242 M) | 11 | 0.734 | 0.742 |
fast final (538 M) vs base final (223 M) | 12 | 0.781 | 0.799 |
fast at 241 M vs base at 242 M (equal steps) | 11 | 0.625 | 0.537 |
fast at 220 M vs base at 223 M (equal steps) | 12 | 0.535 | 0.535 |
fastep2 final vs fast final | 11 | 0.441 | 0.463 |
The fast set fits about 2.2× the steps into the same time and reached 0.8 in 2.2× (seed 11) and 2.8× (seed 12) less training time (1.75× and 2.24× counting evaluations).
At equal steps it's no worse (0.535–0.625 head to head), so at equal time it wins 0.73–0.80.
Two epochs instead of three reached 0.8 later and lost slightly (0.44–0.46), within one seed's noise.
So since train.py 14:31 the fast set is the default for match tasks on CUDA. Single-agent
tasks keep it off, as they had no A/B. To opt out:
--amp off --no-cuda-graphs --no-cuda-graph-act --no-overlap-updateCaveats#
Seeds: two per arm for
baseandfast, one for the others. The switch was made on seed 11, before seed 12 finished.Shared GPU: Rocket League held about 45% of the GPU during the benchmarks, so timings are pessimistic and noisy.
Short runs: fast-learner runs have reached about 550 M steps; the 1 B-step main run used the old learner.
Evaluations now cost: one evaluation (about 10 s) takes as long as 40 updates, so the default cadence went to every 160 updates.
The environment is now about 40% of the cycle (94 of 239 ms), so further gains need both sides faster.