--- pretty_name: dijkwalk experiments tags: - reinforcement-learning - supervised-learning - graph-algorithms - dijkstra - reward-shaping - pufferlib - size-generalization --- # dijkwalk experiments This dataset holds the checkpoints, training curves, and evaluation results for the dijkwalk project. The project measures when directional reward shaping helps a learned agent walk a weighted graph to a hidden target. It also compares the same exact Dijkstra signal used as an RL reward and as a supervised training signal. Code, tests, paper sources, and the visualizer are in the GitHub repository . This dataset holds the files that the repository does not track: about 760 MB of `.pt` checkpoints and `.json` results from 183 paper training runs and 179 earlier exploratory runs. Console logs are not included. ## Task Each episode places an agent on a random connected weighted graph. At every node the agent sees at most the eight cheapest incident edges (K = 8) and must reach a hidden target node. Invalid actions are masked, and every reported evaluation has an invalid-action rate of exactly 0. The exact Dijkstra regret is Δ(u, v) = w(u, v) + φ(v) − φ(u), φ(x) = d(x, target) The two paradigms use it differently: - **Reinforcement learning** (PufferLib PPO) receives the per-step reward `−β·Δ / w_max`, where `w_max` is the largest edge weight. With β = 1 each move in the wrong direction costs its exact regret. - **Supervised learning** trains a decoder-only sequence model with teacher forcing. The `soft_kl` variant in this dataset uses Δ as a per-token teacher signal at temperature τ = 1.0. ## Headline results The GitHub repository has the full tables, gate audits, and figures under `paper/` and `paper-results/`. | Question | Gate | Outcome | |---|---|---| | Q1: Δ as reward versus as loss weight | >5-point success, >0.5 opt-gap, or different size degradation | Pass | | Q2: reward-shaping phase diagram | ≥15-point graded-minus-sparse success with non-overlapping seed ranges | Null result | | Q3: size generalization | >80% success at ≥8× training size while another architecture collapses | Pass | | Q4: rigor and controls | three seeds, deterministic seed path, classical baselines | Complete | **Q1, RL versus supervised.** At 25M matched training compute with sampled decoding, RL beats supervised learning in all six cells, and the gap widens as graphs get larger. | Scale | Suite | RL | Supervised | RL advantage | |---|---|---:|---:|---:| | small | train scale | 97.2% | 76.0% | +21.3 pp | | small | near OOD | 95.8% | 53.3% | +42.4 pp | | small | far OOD | 90.8% | 12.8% | +78.0 pp | | large | train scale | 96.4% | 90.9% | +5.5 pp | | large | near OOD | 92.5% | 62.7% | +29.9 pp | | large | far OOD | 87.6% | 31.3% | +56.2 pp | With greedy decoding, far-OOD success is 79.1% for RL and 4.7% for supervised at the small scale, and 69.2% and 6.3% at the large scale. Compute matches within 1.4%, and parameter counts differ by at most 1.2%. **Q2, phase diagram.** The strongest cell is cold-start graphs (n = 32 to 64) with a `1.25n` step horizon. Graded shaping beats sparse reward there by 11.5, 12.2, and 12.4 points at goal bonuses of 10, 1, and 0. The seed ranges separate, and no cell reaches the 15-point gate. A binary backward penalty matches graded shaping in the strongest main-grid cell. **Q3, size generalization.** Policies trained on graphs up to n = 32 are evaluated up to n = 768. At 24 times the maximum training size, sampled success is 90.9% for the MLP, 93.6% for the LSTM, and 56.1% for the Transformer. When the Transformer succeeds, its paths are cheaper (opt gap 22.5 against 50.1 for the MLP). More than 92% of sampled n = 768 episodes contain a two-cycle for every learned architecture. ## Repository layout ``` README.md experiments/ 179 exploratory training runs (early sweeps, ablations, smoke runs) viz-data/ experiments.json merged ablation curves used by the visualizer experiments-*.json per-run curve files behind that merge policy-mlp.{json,pt} policy-architecture comparison runs policy-transformer.{json,pt} q1-supervised/ supervised training runs and their evaluations q1-rl/ RL training runs at the 25M budget and their evaluations q1-eval/ aggregated Q1 tables (rl.json, supervised.json, rl-5m.json) q2/ 54 main-grid runs plus the goal-bonus extension (162 total) q3/ size-generalization runs and evaluations ``` File counts, excluding logs: `experiments/` 537, `q1-supervised/` 54, `q1-rl/` 24, `q1-eval/` 15, `q2/` 327, `q3/` 30. ## Experiment details ### Q1: cross-paradigm comparison (`q1-rl/`, `q1-supervised/`, `q1-eval/`) | Arm | Model | Parameters | Paired with | |---|---|---:|---| | RL | LSTM policy | 183,081 | supervised small | | RL | Transformer policy | 531,202 | supervised large | | Supervised | small sequence model | 185,192 | RL LSTM | | Supervised | large sequence model (d_model 72, 7 layers, 8 heads, vocab 113, max sequence 1024) | 532,152 | RL Transformer | Each arm trains with seeds 42, 43, and 44. The RL checkpoints are named `q1-25m-shaping-beta1-seed*.pt` (LSTM) and `q1-25m-policy-transformer-seed*.pt`. The supervised checkpoints are named `q1-soft-kl-{small,large}-train20000-seed*.pt`. Three frozen 1,000-graph suites test every checkpoint. Each suite is pinned by SHA-256, and every result row stores the hash in `suite_sha256`. | Suite | Node count range | |---|---| | `train-scale` | 16 to 32 | | `near-ood` | 33 to 48 | | `far-ood` | 64 to 96 | Each checkpoint is evaluated with greedy and sampled decoding under a step budget of `4n`. That gives 180 fixed-suite conditions: 72 RL and 108 supervised. ### Q2: shaping phase diagram (`q2/`) The main grid trains 54 five-million-step LSTM policies. It varies four factors: - reward mode: graded Δ (`shaping-beta1`), the β = 0 control (`shaping-sparse`), and a binary backward penalty (`shaping-binary`); - rollout horizon: `4n`, `2n`, and `1p25n` (1.25n); - graph regime: `small` (fixed n = 8 to 16) and `cold` (cold-start n = 32 to 64); - seeds 42, 43, and 44. The extension repeats the grid at goal bonuses of 1 and 0, which gives 162 runs. Every run uses the Muon optimizer at learning rate 0.015 with 1,024 parallel environments. Run names follow `q2-{regime}-{horizon}-g{goal_bonus}-{mode}-seed{seed}`, for example `q2-cold-1p25n-g0-shaping-beta1-seed42`. Each run has a `.json` curve file and a `.pt` checkpoint. The files `grid-manifest.json`, `grid-g0-manifest.json`, and `grid-g1-manifest.json` list every run with its final success rate. ### Q3: size generalization (`q3/`) Nine five-million-step policies (MLP, LSTM, and Transformer, three seeds each) train on graphs up to n = 32. They are evaluated on n = 32, 48, 96, 192, 384, and 768 with 1,000 graphs per condition, greedy and sampled decoding, and suite seed 20260726. The checkpoints are `q3-policy-mlp-seed*.pt`, `q3-policy-transformer-seed*.pt`, and `q3-shaping-beta1-seed*.pt` (the LSTM). ### Exploratory runs (`experiments/`) This folder holds the runs from early in the project: the first ablation sweeps behind the visualizer and several smoke and reproducibility runs. Each run has a directory named by a numeric run id (`178120009848`) and a sibling final policy file (`178120009848.pt`). Inside the directory, PufferLib writes intermediate checkpoints (`model_000025.pt`) and the optimizer state (`trainer_state.pt`). These runs use different settings from the paper runs. The paper results come from `viz-data/`. ## File formats **Training curve files** (`q2/*.json`, `q3/experiments-*.json`, `viz-data/experiments*.json`) hold `name`, `spec` (environment settings and recurrent wrapper), `n_params`, `seed`, `tag`, `artifact_stem`, `steps`, `num_envs`, and `curve`. Each `curve` entry records `agent_steps`, `epoch`, `SPS` (steps per second), `uptime`, and the PPO loss statistics (`losses/policy_loss`, `losses/value_loss`, `losses/entropy`, `losses/explained_variance`, `losses/approx_kl`). **Evaluation files** (`eval-*.json`) hold `config`, `runs`, and `summary`. Each row in `runs` describes one checkpoint on one suite and decoding mode: | Field | Meaning | |---|---| | `episodes`, `successes`, `success_rate` | episodes run and how many reached the target | | `episode_length` | mean steps per episode | | `opt_gap` | mean path cost of successful episodes divided by the optimal cost | | `backward_rate` | fraction of moves that increase φ | | `two_cycle_rate`, `two_cycle_episode_rate` | share of moves in A→B→A cycles, and share of episodes containing one | | `invalid_rate` | fraction of masked-invalid actions (0.0 everywhere) | | `paradigm`, `architecture`, `training_budget`, `training_steps`, `train_seed` | which model produced the row | | `suite`, `suite_sha256`, `n_min`, `n_max`, `decoding` | the evaluation conditions | | `checkpoint`, `n_params` | source checkpoint file and its parameter count | **Supervised run files** (`q1-supervised/q1-soft-kl-*.json`) hold the training configuration (`variant`, `size`, `seed`, `steps`, `batch_size`, `tau`, `model`), the final loss, a 200-point loss `curve`, and `captures`, a list of integer checkpoint steps. **Checkpoints** (`.pt`) are PyTorch files. `train.py eval --load-model-path ` in the GitHub repository loads the RL checkpoints, and the supervised scripts in the same repository load the supervised ones. ## Loading a file ```python from huggingface_hub import hf_hub_download import json path = hf_hub_download( "lilcheaty/dijkwalk-experiments", "viz-data/q1-eval/rl.json", repo_type="dataset", ) rows = json.load(open(path))["runs"] far = [r for r in rows if r["suite"] == "far-ood" and r["decoding"] == "sampled"] print(sum(r["success_rate"] for r in far) / len(far)) ``` ## Reproducing the runs Clone the GitHub repository and follow its `README.md`. It covers setup, `train.py`, the `scripts/q1_suite` verifier, and the per-question scripts under `scripts/`. The seed controls Python, NumPy, PyTorch, PufferLib, graph generation, policy initialization, and action sampling. Same-seed reruns produce tensor-identical checkpoints and identical non-timing curves. Every seed appears in its filename, so concurrent runs never overwrite each other. ## Caveats - Greedy policies fall into two-cycles, so the headline numbers use sampled decoding. Greedy numbers are listed next to them where the paper reports both. - The Q1 comparison matches compute and parameters closely. It does not separate the effect of the training signal from every optimizer and data-distribution difference between the two paradigms. - The Q2 result is a null against a predeclared 15-point gate. The strongest cells show an 8 to 12 point advantage for graded shaping. - The Q1 runs trained on a remote GPU box with the official CUDA 12.6 PyTorch wheel. `paper/EXPERIMENT-SUMMARY.md` in the GitHub repository lists every operational deviation. ## Citation No formal citation exists yet. Cite the GitHub repository: .