6.8 KiB
Deep CFR v0 Gap vs Legacy coolrl
This document compares the current coolrl-lost-cities Deep CFR v0 smoke
pipeline with the legacy Lost Cities Deep CFR implementation in ../coolrl.
The current implementation proves that Cython traversal primitives, PyTorch networks, memory collection, and a one-iteration smoke run can work together. It is not yet equivalent to the legacy implementation.
Current v0
Implemented:
- Cython traversal primitives:
random_rollout_valueroot_action_values- direct
GameStateC API use for legal actions and push/pop restoration
- Minimal Cython information-state encoding.
- Small PyTorch MLP.
- Simple in-memory sample storage.
- Minimal trainer that:
- samples root action values with random rollouts
- builds advantage-like targets
- trains advantage networks and strategy network once
- Smoke tests for traversal restoration and trainer execution.
This is a scaffold, not a complete Deep CFR algorithm.
Major Algorithm Gaps
Recursive Deep CFR Traversal
Legacy coolrl has recursive outcome-sampling traversal. Current v0 does not.
Missing:
- Recursive
traverse(state, traverser, iteration, depth)logic. - Terminal value handling at every node.
- Traverser node vs opponent node behavior.
- Node value calculation from sampled actions.
- Instantaneous regret calculation at traverser nodes.
- Strategy-memory collection at traverser and/or opponent nodes.
- Depth cutoff and node-budget cutoff.
This is the highest-priority gap.
Network-driven Policies During Traversal
Current v0 does not use the advantage networks inside traversal. It estimates root action values with random rollouts.
Legacy flow:
encode information state
advantage network forward pass
regret matching over legal actions
sample action from policy
recurse
store regrets / strategy
Current flow:
enumerate root actions
random rollout from each child
train on resulting root targets
Outcome Sampling Controls
Legacy coolrl supports:
outcome_sampling_epsilon- sampled action probability correction
- optional sampled value clipping
- unsampled regret modes:
negative_node_valuezero
Current v0 has none of these.
Cutoff Values
Legacy traversal supports:
- score-diff cutoff values
- random rollout cutoff values
- safe-heuristic rollout cutoff values
- rollout max-step timeouts
- cutoff stats
Current v0 only uses random rollouts at the root-action helper level.
Training and Memory Gaps
Reservoir Memory
Legacy implementation has separate AdvantageMemory and StrategyMemory with:
- capacity limits
- reservoir sampling
- legal masks stored with each sample
- batch sampling
- sample merging from traversal workers
Current v0 stores simple TrainingSample objects in a list-like memory.
Legal-mask-aware Losses
Legacy advantage loss only trains legal action outputs:
masked MSE over legal actions
Legacy strategy loss uses masked policy learning:
masked logits -> log_softmax -> cross entropy against stored policy
Current v0 uses simple supervised MSE for both advantage and strategy targets. This is enough for smoke testing, but not the intended training objective.
Config System
Legacy config is split into:
- rules config
- network config
- encoding config
- traversal config
- optimization config
- memory config
- evaluation config
- checkpoint config
- run config
It also supports YAML loading and experiment-level overrides.
Current v0 has only DeepCFRConfig.
Runtime and Operations Gaps
Checkpointing
Legacy checkpoints include:
- config
- Lost Cities rules config
- iteration
- input/action dimensions
- advantage networks
- strategy network
- optimizer states
- self-play league snapshots
- latest and per-iteration checkpoint files
Current v0 has no checkpoint save/load.
Evaluation Integration
Legacy implementation can load a strategy checkpoint as a bot and evaluate it against supported opponents.
Supported legacy eval flow includes:
- random opponent
- safe heuristic opponent
- passive discard opponent
- noisy/safe variants through the evaluation layer
- many detailed gameplay metrics
Current v0 does not evaluate during training and does not expose a strategy-net bot adapter.
CLI
Legacy implementation has command-line tools for:
- training
- evaluation
- evaluation suites
- status/progress
- plotting and visualization
- traversal benchmarking
- imitation/pretraining experiments
- policy-gradient fine-tuning experiments
Current v0 has no CLI.
Multiprocessing Workers
Legacy traversal can run through multiprocessing worker batches:
- worker count resolution, including
auto - traversal chunking
- frozen network state dict transfer
- worker-local traversal
- result merging
- progress logging
- hotspot profiling
Current v0 runs in-process only.
Metrics and Logging
Legacy training writes:
metrics.jsonlruntime_progress.jsontrain.log- traversal nodes/sec
- cutoff rates
- endpoint depth buckets
- advantage and strategy losses
- evaluation metrics
- hotspot timing metrics
Current v0 returns a small IterationMetrics object.
Encoding Gaps
Legacy encoding is much richer. It includes:
- phase one-hot
- current-player indicator
- player id
- hand slots with card-type one-hot and empty-slot flag
- both players' expedition card counts
- expedition lengths
- last numeric rank per expedition
- discard pile card counts
- discard pile length
- discard pile top card
- public card counts
- deck ratio
- turn-count ratio
- pending-discard one-hot
- optional derived playability features
- optional slot-aware playability features
Current v0 includes only a minimal subset:
- phase flags
- current player
- encoded player
- deck ratio
- player hand slot features
- legal action mask
The current encoding should be expanded before serious training runs.
Self-play League Gap
Legacy implementation supports self-play league opponent selection:
- current networks
- recent snapshots
- older snapshots
- safe-heuristic anchor
- snapshot interval
- maximum snapshot count
Current v0 has no league or checkpoint-snapshot opponent sampling.
Practical Priority
Recommended implementation order:
- Implement real recursive Deep CFR traversal.
- Add legal-mask-aware advantage and strategy memories/losses.
- Expand encoding to include public board, discard, and score features.
- Add checkpoint save/load.
- Add strategy-net bot adapter and evaluation integration.
- Add CLI for train/eval/smoke.
- Add traversal stats and benchmark reporting.
- Add multiprocessing workers only after the single-process algorithm is correct.
The first three items are algorithm-critical. The rest are operationally useful but should not block proving that the learning loop is correct.