Skill Tracer
Skills › Scientific Agent Skills › pufferlib › native-5.md

native-5.md

146 lines · skills/pufferlib/references/native-5.md at 5f2bc03

Open on GitHub
1# Native PufferLib 5.0
2
3Reviewed 2026-10-01 against official live docs and source commit
4`6ffa5b10dbbbe4d1e8288367c7d9d3acd3bad4a2`. This is a source profile, not a
5PyPI 5.0 package. Commands below are source-reviewed examples, not an executed
6native build or training benchmark. The bundled Python planners support only
7historical 3.0/4.0 schemas and must not generate 5.0 commands.
8

Native PufferLib 5.0

Reviewed 2026-10-01 against official live docs and source commit 6ffa5b10dbbbe4d1e8288367c7d9d3acd3bad4a2. This is a source profile, not a PyPI 5.0 package. Commands below are source-reviewed examples, not an executed native build or training benchmark. The bundled Python planners support only historical 3.0/4.0 schemas and must not generate 5.0 commands.

Raw lines 1 to 8
9## Build one environment
11Pin the source commit and record the compiler, platform, build flags, source
12diff, environment config, dependencies and asset hashes. `build.sh` can download
13Raylib 5.5 release archives and, for relevant environments, Box2D from a mutable
14`latest` release URL. Those downloads are not checksum-locked by the script.
15Review/pin them for reproducible builds. The official PufferTank installer is
16an installation convenience; do not treat the moving installer as a lockfile.
18- CUDA training requires NVIDIA hardware plus a CUDA development toolchain,
19 including `nvcc`, cuBLAS, cuSOLVER, cuRAND, NCCL and NVML at this revision.
20 The native trainer is C/CUDA, not a pip-installed Torch trainer.
21- `--cpu` builds standalone evaluation/play. **There is no CPU training mode.**
22- The build script has Linux and macOS paths (macOS uses Homebrew `libomp` and
23 system frameworks). Its Linux Raylib archive is amd64. Native Windows and
24 Linux ARM compatibility are not established by these paths; WSL/native builds
25 need separate validation. This review did not build either platform.
26- `--debug` adds ASan/UBSan flags on the Linux CPU path; the inspected macOS path
27 leaves sanitizer flags empty. Do not assume the docs' sanitizer claim holds
28 on every platform.
29- GPU-only environments such as `robot_arm` reject CPU/web builds. `--cu`
30 selects a CUDA environment implementation; an ordinary CPU environment can
31 still be used by the CUDA trainer.
33Illustrative CPU development commands from the repository root:
35```bash
36./build.sh breakout --cpu --debug
37./breakout --headless
38```
40At the pinned revision, standalone headless execution without an explicit
41`eval_episodes` override runs 1024 steps. With no checkpoint it is an untrained
42environment smoke test. With `--base.eval_episodes=N`, it runs until the
43environment's `log.n` reaches N; impose an external wall-time cap because the
44meaning/rate of that counter is environment-specific.
46Illustrative CUDA training and exact-checkpoint evaluation:
48```bash
49./build.sh breakout --cu
50./puffer train --base.seed=42 --train.total_timesteps=100000
51./puffer eval checkpoints/breakout/RUN/EXACT.bin --headless --base.eval_episodes=10
52```
54`RUN/EXACT.bin` is a placeholder, not a shipped checkpoint. The selected environment
55is compiled into the binary. Do not add an environment positional argument to
56`./puffer train`. The current parser supports `train`, `eval`, `match`, `sweep`,
57`--headless`, and section-qualified `--section.key=value` overrides. Use
58underscores exactly as in the INI keys; historical Python CLI hyphenated flags
59are a different parser. There is no `--slowly`, `--wandb`, or `--neptune` path in
60the reviewed native trainer.

Build one environment

Pin the source commit and record the compiler, platform, build flags, source diff, environment config, dependencies and asset hashes. build.sh can download Raylib 5.5 release archives and, for relevant environments, Box2D from a mutable latest release URL. Those downloads are not checksum-locked by the script. Review/pin them for reproducible builds. The official PufferTank installer is an installation convenience; do not treat the moving installer as a lockfile.

  • CUDA training requires NVIDIA hardware plus a CUDA development toolchain, including nvcc, cuBLAS, cuSOLVER, cuRAND, NCCL and NVML at this revision. The native trainer is C/CUDA, not a pip-installed Torch trainer.
  • --cpu builds standalone evaluation/play. There is no CPU training mode.
  • The build script has Linux and macOS paths (macOS uses Homebrew libomp and system frameworks). Its Linux Raylib archive is amd64. Native Windows and Linux ARM compatibility are not established by these paths; WSL/native builds need separate validation. This review did not build either platform.
  • --debug adds ASan/UBSan flags on the Linux CPU path; the inspected macOS path leaves sanitizer flags empty. Do not assume the docs' sanitizer claim holds on every platform.
  • GPU-only environments such as robot_arm reject CPU/web builds. --cu selects a CUDA environment implementation; an ordinary CPU environment can still be used by the CUDA trainer.

Illustrative CPU development commands from the repository root:

./build.sh breakout --cpu --debug
./breakout --headless

At the pinned revision, standalone headless execution without an explicit eval_episodes override runs 1024 steps. With no checkpoint it is an untrained environment smoke test. With --base.eval_episodes=N, it runs until the environment's log.n reaches N; impose an external wall-time cap because the meaning/rate of that counter is environment-specific.

Illustrative CUDA training and exact-checkpoint evaluation:

./build.sh breakout --cu
./puffer train --base.seed=42 --train.total_timesteps=100000
./puffer eval checkpoints/breakout/RUN/EXACT.bin --headless --base.eval_episodes=10

RUN/EXACT.bin is a placeholder, not a shipped checkpoint. The selected environment is compiled into the binary. Do not add an environment positional argument to ./puffer train. The current parser supports train, eval, match, sweep, --headless, and section-qualified --section.key=value overrides. Use underscores exactly as in the INI keys; historical Python CLI hyphenated flags are a different parser. There is no --slowly, --wandb, or --neptune path in the reviewed native trainer.

Raw lines 9 to 61
62## Environment contract: inspect the pinned header
64The live docs still mention a `binding.c` checklist. At the reviewed 5.0 revision,
65`ocean/minimal/minimal.h` and `src/pufferenv.h` are authoritative: Minimal defines
66`obs_t`, `OBS_SIZE`, `NUM_ATNS`, `ACT_SIZES`, `struct Env`, and `struct Log`.
67It implements:
69```c
70void puf_init(Env* env, Dict* kwargs);
71void puf_reset(Env* env);
72void puf_step(Env* env);
73void puf_render(Env* env);
74void puf_close(Env* env);
75void puf_log(Log* log, Dict* out);
76```
78This is not the 4.0 `c_step`/`binding.c` interface. Each `Agent` holds observation,
79action, reward and terminal pointers, an optional action mask and a policy index.
80Environment-owned state includes agent count and RNG state. Logs contain floats,
81with `n` last in the template. Inspect allocation ownership and metadata against
82every buffer write. `OBS_SIZE` is per agent; actions can have multiple branches.
83CPU implementations step one `Env`; GPU implementations step a device batch and
84have additional stream/vector-creation hooks. Porting requires more than renaming
85functions.
87There is a terminal buffer but **no separate truncation buffer** in this interface.
88Do not claim Gymnasium time-limit bootstrapping semantics automatically survive a
89port. Define how time limits, terminal transitions, immediate reset, final
90observations and recurrent-state reset are represented, and verify the learner's
91target calculation. The Minimal example is continuing coordination; `log.n`
92counts logged task events and is not automatically an episode count. Use an
93episodic environment/test when evaluating end-of-episode behavior.

Environment contract: inspect the pinned header

The live docs still mention a binding.c checklist. At the reviewed 5.0 revision, ocean/minimal/minimal.h and src/pufferenv.h are authoritative: Minimal defines obs_t, OBS_SIZE, NUM_ATNS, ACT_SIZES, struct Env, and struct Log. It implements:

void puf_init(Env* env, Dict* kwargs);
void puf_reset(Env* env);
void puf_step(Env* env);
void puf_render(Env* env);
void puf_close(Env* env);
void puf_log(Log* log, Dict* out);

This is not the 4.0 c_step/binding.c interface. Each Agent holds observation, action, reward and terminal pointers, an optional action mask and a policy index. Environment-owned state includes agent count and RNG state. Logs contain floats, with n last in the template. Inspect allocation ownership and metadata against every buffer write. OBS_SIZE is per agent; actions can have multiple branches. CPU implementations step one Env; GPU implementations step a device batch and have additional stream/vector-creation hooks. Porting requires more than renaming functions.

There is a terminal buffer but no separate truncation buffer in this interface. Do not claim Gymnasium time-limit bootstrapping semantics automatically survive a port. Define how time limits, terminal transitions, immediate reset, final observations and recurrent-state reset are represented, and verify the learner's target calculation. The Minimal example is continuing coordination; log.n counts logged task events and is not automatically an episode count. Use an episodic environment/test when evaluating end-of-episode behavior.

Raw lines 62 to 94
95## Vectorization, policy and PPO
97Current configuration uses `[vec] total_agents`, `num_buffers`, `num_threads`;
98`[policy] hidden_size`, `num_layers`; and `[train] horizon`, `minibatch_size`,
99`total_timesteps`. CPU environment buffers coordinate OpenMP workers and CUDA
100streams; the reviewed GPU environment path asserts `num_buffers == 1`. Record
101resolved environment overrides rather than copying default.ini blindly.
103The trainer implements a PPO variant. Record `[base] async` (one-epoch actor/learner
104pipelining), `reset_every_horizon`, `cudagraphs`, seed, the policy architecture,
105GAE/V-trace settings, replay ratio, reward transformation and precision.
106The reviewed defaults use asynchronous execution and carry recurrent state across
107horizons, resetting it on terminal signals. Compare synchronous/asynchronous and
108float/default precision only with the same environment workload and evaluation
109protocol. The default precision is bf16; `--float` is a build-time comparison.
110The historical Python `Policy(encoder, decoder, network)` API does not apply.

Vectorization, policy and PPO

Current configuration uses [vec] total_agents, num_buffers, num_threads; [policy] hidden_size, num_layers; and [train] horizon, minibatch_size, total_timesteps. CPU environment buffers coordinate OpenMP workers and CUDA streams; the reviewed GPU environment path asserts num_buffers == 1. Record resolved environment overrides rather than copying default.ini blindly.

The trainer implements a PPO variant. Record [base] async (one-epoch actor/learner pipelining), reset_every_horizon, cudagraphs, seed, the policy architecture, GAE/V-trace settings, replay ratio, reward transformation and precision. The reviewed defaults use asynchronous execution and carry recurrent state across horizons, resetting it on terminal signals. Compare synchronous/asynchronous and float/default precision only with the same environment workload and evaluation protocol. The default precision is bf16; --float is a build-time comparison. The historical Python Policy(encoder, decoder, network) API does not apply.

Raw lines 95 to 111
112## Evaluation and checkpoints
114For CPU evaluation, build the matching environment and pass an explicit model:
116```bash
117./build.sh breakout --cpu
118./breakout checkpoints/breakout/RUN/EXACT.bin --headless --base.eval_episodes=10
119```
121Keep the matching environment INI and policy dimensions. Native `.bin` files
122are raw weight data, not self-describing training checkpoints. The trainer
123reads a number of float bytes derived from the current architecture; a successful
124size check cannot prove that architecture/action ordering matches. Record exact
125path, SHA-256, byte size, source/build revision and complete config. The bundled
126`inspect_checkpoint.py` only hashes/classifies bytes; it cannot validate weights.
127`latest` recursively selects a file by filesystem times and is unsuitable for
128reproducible evaluation. Model weights do not restore optimizer/RNG/environment
129state for an exact resume.
131A seed config entry alone is insufficient: inspect the selected environment's
132RNG and the standalone runner's initialization. In particular, the reviewed
133standalone runner does not consume `base.seed` to initialize the environment RNG;
134do not claim independent evaluation seeds simply by changing that flag. Implement
135and test explicit seed wiring before reporting a multi-seed CPU evaluation.
136Report held-out environment instances, completed episodes/events, action-sampling
137protocol, recurrent resets and per-seed uncertainty separately from training
138metrics. Constellation consumes local logs; no authenticated service or REST
139request is needed for this native workflow.

Evaluation and checkpoints

For CPU evaluation, build the matching environment and pass an explicit model:

./build.sh breakout --cpu
./breakout checkpoints/breakout/RUN/EXACT.bin --headless --base.eval_episodes=10

Keep the matching environment INI and policy dimensions. Native .bin files are raw weight data, not self-describing training checkpoints. The trainer reads a number of float bytes derived from the current architecture; a successful size check cannot prove that architecture/action ordering matches. Record exact path, SHA-256, byte size, source/build revision and complete config. The bundled inspect_checkpoint.py only hashes/classifies bytes; it cannot validate weights. latest recursively selects a file by filesystem times and is unsuitable for reproducible evaluation. Model weights do not restore optimizer/RNG/environment state for an exact resume.

A seed config entry alone is insufficient: inspect the selected environment's RNG and the standalone runner's initialization. In particular, the reviewed standalone runner does not consume base.seed to initialize the environment RNG; do not claim independent evaluation seeds simply by changing that flag. Implement and test explicit seed wiring before reporting a multi-seed CPU evaluation. Report held-out environment instances, completed episodes/events, action-sampling protocol, recurrent resets and per-seed uncertainty separately from training metrics. Constellation consumes local logs; no authenticated service or REST request is needed for this native workflow.

Raw lines 112 to 140
141## Official evidence
143- [Live documentation](https://puffer.ai/docs.html): build/CLI and CPU-eval-only policy.
144- [Pinned build script](https://github.com/PufferAI/PufferLib/blob/6ffa5b10dbbbe4d1e8288367c7d9d3acd3bad4a2/build.sh): platform and dependency paths.
145- [Pinned environment header](https://github.com/PufferAI/PufferLib/blob/6ffa5b10dbbbe4d1e8288367c7d9d3acd3bad4a2/src/pufferenv.h) and [Minimal](https://github.com/PufferAI/PufferLib/blob/6ffa5b10dbbbe4d1e8288367c7d9d3acd3bad4a2/ocean/minimal/minimal.h): native contracts.
146- [Pinned trainer](https://github.com/PufferAI/PufferLib/blob/6ffa5b10dbbbe4d1e8288367c7d9d3acd3bad4a2/src/pufferl.cu), [CPU runner](https://github.com/PufferAI/PufferLib/blob/6ffa5b10dbbbe4d1e8288367c7d9d3acd3bad4a2/src/puffercpu.c), and [config](https://github.com/PufferAI/PufferLib/blob/6ffa5b10dbbbe4d1e8288367c7d9d3acd3bad4a2/config/default.ini): parser, weight loading, evaluation and algorithm settings.

Official evidence

Raw lines 141 to 146