Training#

Training needs no dataset on disk — random walks are generated on the GPU inside the loop. All you supply is a puzzle (--group_id), a target (--target_id) and a budget.

python train.py --group_id <id> --target_id 0 --epochs <epochs> \
  --hd1 <N_1> --hd2 <N_2> --nrd <N_r> --batch_size 10000 --K_max <K_max> --device_id 0

Example — the 24-puzzle:

python train.py --group_id 28 --target_id 0 --epochs 16 \
  --hd1 1024 --hd2 512 --nrd 1 --batch_size 10000 --K_max 100 --device_id 0

Hyperparameters#

FlagDefaultMeaning
--hd11024Width of the first hidden layer (\( N_1 \))
--hd2256Width of the second hidden layer (\( N_2 \)); 0 disables it
--nrd4Number of residual blocks (\( N_r \)); 0 disables them
--batch_size10000SGD batch size
--lr0.001Adam learning rate
--dropout0.0Dropout rate
--epochs256Random-walk regression epochs
--K_min / --K_max1 / 30Random-walk length range
--weights—Checkpoint name in weights/ to warm-start from

The paper’s headline results use \( N_1 = 1024 \), \( N_2 = 256 \), \( N_r = 1 \) for every puzzle — so the architecture flags are usually not what you should be tuning.

--K_max is the one genuinely per-puzzle knob. It bounds the random-walk length, so it must exceed the graph’s diameter — too small and the model never sees deep states; too large and epochs are wasted on states that are all equally far away. The values used per puzzle are tabulated in Reference → Groups. Note that epoch size is 1_000_000 // K_max walkers per length, i.e. ~10⁶ states per epoch regardless of K_max.

Bellman (Modified DQN) refinement#

After the random-walk phase you can refine the value estimates with a Bellman update on the Cayley graph (method). The phase implements the Modified DQN of the CayleyPy RL paper (arXiv:2502.18663):

FlagDefaultMeaning
--epochs_dqn0Number of Modified DQN epochs; 0 disables the phase
--dqn_walkers0Walkers per DQN epoch; 0 means 1/10 of the warm-up walkers
--dqn_roundoffRound DQN targets to integers

--dqn_round is reported in that paper as giving no improvement; it is there for reproduction.

Run this phase on top of a diffusion-distance warm-up, not instead of one. The paper finds that DQN epochs reliably improve the warm-up model — shorter solutions and a higher solve rate — but by a modest margin, whereas DQN from scratch (a large --epochs_dqn with no warm-up epochs) performs poorly. In practice a short DQN phase after the main run is a refinement, not a substitute for it.

Finding your model afterwards#

Training assigns model_id = int(time.time()) at start and prints it. Checkpoints land in weights/ and metrics in logs/. Pass that id back to test.py:

python test.py --group_id 28 --target_id 0 --tests_num 3 --dataset rnd \
  --num_steps 300 --num_attempts 1 --verbose 1 \
  --epoch 16 --model_id {MODEL_ID} --B 65536 --device_id 0

Replace {MODEL_ID} with the numeric identifier from the logs, and make sure --epoch names a checkpoint that was actually written. You do not re-specify the architecture: test.py reads hd1/hd2/nrd back from logs/model_pXXX-tXXX_<model_id>.json, so keep that file next to the checkpoint.

Next: Multi-agent evaluation to train an ensemble, or Testing for the search flags.