Upload README.md with huggingface_hub
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204123---language:- enlicense: otherlibrary_name: pytorchtags:- mtg- magic-the-gathering- reinforcement-learning- system-one- choice-model- distillation---
# Model card — System One Choice (`SystemOneChoice`)
**Hub:** [jedld/system-one-choice](https://huggingface.co/jedld/system-one-choice)(override with `MTGCARDS_HF_MODEL`). Download:
```bashpython -m mtgcards.fetch_assets --ckpt# or evaluate without a local tree:python -m mtgcards.rl.evaluate --ckpt hf:jedld/system-one-choice --vs greedy --games 10```
Local **JEV-shaped text Choice** student for Magic: The Gathering playinside this engine. Not an autoregressive chatbot: one forward passscores every legal action and returns `{choice, probabilities, confidence}`.
Canonical code: [`mtgcards/rl/model.py`](https://github.com/jedld/mtgcards/blob/master/mtgcards/rl/model.py)(`arch=choice_text_v1`). Training walkthrough:[`docs/SYSTEM_ONE.md`](https://github.com/jedld/mtgcards/blob/master/docs/SYSTEM_ONE.md). Self-improvement loop:[`mtgcards/rl/SELF_IMPROVE.md`](https://github.com/jedld/mtgcards/blob/master/mtgcards/rl/SELF_IMPROVE.md).
## Model details
| | || --- | --- || **Developed by** | mtgcards / System One stack || **Model type** | Bidirectional Transformer encoder + parallel criteria scorer + value head || **Language(s)** | English game text (engine `render_state` / `action_options`) || **License** | Code follows the repo MIT license. Weights are **not** MIT game content: FineWeb sample is ODC-By-1.0; Comprehensive Rules © Wizards of the Coast; card oracle text subject to Wizards terms. See repo [`NOTICE`](https://github.com/jedld/mtgcards/blob/master/NOTICE). || **Finetuned from** | Random init → causal LM warm-start on `data/systemone_corpus` → BC → PPO |
### Architecture (`choice_text_v1`)
1. **Byte-level `TextVocab`** — 5 specials + 256 UTF-8 bytes (size 261). Checkpoint `text_vocab.json` is a kind/size marker; the mapping is fixed in code.2. Shared **TransformerEncoder** trunk (`norm_first`, GELU FFN = 2×`d_model`).3. Encode **state** once → mean-pool → `state_proj`.4. Encode each criterion `"key: label"` with the same trunk → pool → `crit_proj`.5. Score `(state, crit, state⊙crit)` with a 2-layer MLP → logits over K options.6. Softmax → probabilities; **TypeSafe confidence** `(p_max − 1/n) / (1 − 1/n)`.7. **Value head** on the state pool (PPO baseline).
Legacy closed-vocab CAND policy remains loadable as`LegacySystemOnePolicy` (`--arch legacy`).
### Size presets
| Preset | `d_model` | layers | heads | ~params | state bytes || --- | ---: | ---: | ---: | ---: | ---: || Default CLI | 192 | 4 | 6 | ~1.4M | 8192 (CLI default) || **choice_fresh (this run)** | 384 | 6 | 6 | ~11.1M | 8192 || Smoke notebook | 64 | 2 | 4 | small | 384 |
Criteria are capped at `--max-crit` (default 64 bytes each).
## Intended use
- **In-scope:** Seat-balanced play inside this rules engine (TUI, Arena, Gym, evaluate harness); BC from greedy/JEV; PPO vs a league; soft-label distillation from captured `jev_request` / `probs`.- **Out-of-scope:** Real Magic Online / Arena clients; claiming parity with hosted TypeSafe JEV; Noul/Score/image inputs; legal advice or tournament rulings outside the engine’s known simplifications.
## Training data
### Text LM warm-start (`data/systemone_corpus`)
Built by `python -m mtgcards.rl.corpus build`. Manifest after the2026-11-20 rebuild (`--fineweb-docs 8000`): **13 953 docs / ~58M chars**.
| Source | Docs (approx.) | Notes || --- | ---: | --- || FineWeb `sample-10BT` | 8000 | ODC-By-1.0; bounded stream sample, not the full FineWeb || Card catalog + oracle JSON | ~5800 | Engine cards + Scryfall stubs under `data/cards` || Game logs | ~48 | `data/game_logs/**/*.jsonl` when present || Comprehensive Rules | 1 + chunks | Wizards plain-text CR |
Causal LM uses a **capped** window (`min(max_state, 2048)`) even whenChoice state budget is larger (attention is O(T²)).
### Decision training
- **BC teacher (default):** `GreedyAgent` rollouts recording `state_text` / `options` (JEV surface; distillation parity omits YAML strategy prose).- **Optional teachers:** - JEV Choice API (`--bc-source jev`) — soft `probs` + `jev_request`. - **Hybrid Strata+JEV** (`--bc-source hybrid` or `trajectory collect --teacher hybrid`) — Strata writes a main-phase plan; JEV executes with that plan (and optional combat advice) in the Choice state. Soft labels are JEV’s distribution; the stored state **includes** the strategist plan (strategist dataset).- **PPO:** self-play vs league (past checkpoints + scripted baselines); reward = terminal seat outcome ±1.- **Paraphrase augmentation:** `python -m mtgcards.rl.paraphrase` restates state/option text via Strata while freezing option keys + soft labels (`data/trajectories/*_para.pkl`).
**Hidden information:** the deciding seat never sees opponent handidentities, library order, or uncast cards([`tests/test_hidden_info.py`](https://github.com/jedld/mtgcards/blob/master/tests/test_hidden_info.py)).
## Training procedure (choice_fresh recipe)
```bashpython -m mtgcards.rl.corpus build --fineweb-docs 8000
python -m mtgcards.rl.train \ --arch choice --device cuda \ --out checkpoints/choice_fresh \ --bank data/trajectories/choice_fresh.pkl \ --d-model 384 --layers 6 --heads 6 \ --max-tokens 8192 --max-crit 64 \ --batch-size 2 --lr 1.5e-4 \ --pretrain-corpus data/systemone_corpus/corpus.jsonl \ --pretrain-epochs 2 \ --bc-games 16 --bc-epochs 6 \ --iters 20 --games 12 --epochs 3 \ --log-games 2 --log-dir data/game_logs/choice_fresh
# later: soft-label distill from hybrid bank onto a PPO ckptpython -m mtgcards.rl.train --resume checkpoints/choice_fresh/policy_NNNN \ --bc-source bank:data/trajectories/hybrid_strategist_plus_para.pkl \ --bc-epochs 8 --iters 10 --games 12 --device cuda ...```
See [`data/README.md`](https://github.com/jedld/mtgcards/blob/master/data/README.md) for the full dataset tree.
Stages: corpus LM → greedy BC → PPO league → hybrid soft distill(+ optional PPO). Checkpoints: `checkpoints/choice_fresh/policy_NNNN/`with `model.pt`, `text_vocab.json`, `meta.json`.
**Hub package (this card):** weights from **`policy_0023`** — hybridstrategist soft BC on top of the choice_fresh stack (~11.1M params,`d_model=384`, 6 layers). League `best.json` may point at a later PPOiter with a tiny N=12 win-rate spike; do not treat that as ladderevidence.
## Evaluation
Primary metric: **seat-balanced win rate** vs a fixed opponent.
```bashpython -m mtgcards.rl.evaluate \ --ckpt checkpoints/choice_fresh/policy_best \ --vs greedy --games 40 --device cuda```
Sparse-reward honesty: do not treat small-budget win rates as ladderevidence; always report game count. JEV soft-label agreement andjudge-LLM audits (`--log-games`) are secondary signals.
| Checkpoint | vs greedy (N games) | Soft agree (JEV-labelled) | Notes || --- | --- | --- | --- || `policy_0019` | 0.42 (12, PPO sample) | — | early PPO plateau; noisy || `policy_0022` | 0.36 (11 scored / 12) | train 0.63 / held-out 0.51 | first hybrid+para distill || `policy_0023` | *(pending ≥20-game eval)* | train 0.65 / held-out 0.53 | **Hub candidate**; larger hybrid bank BC || `policy_0024` | 1.00 (12, PPO sample) | — | league “best” after distill; **N=12 fluke** — not published |
## Limitations and risks
- Engine fidelity gaps (see README “Known simplifications”) transfer to the policy.- Long states are **byte-truncated** (tail-preferring); very long games still lose early history even at 8192.- Greedy BC alone clones a weak teacher; strength needs JEV distill and/or enough PPO.- Hosted JEV is stronger zero-shot; this student is the cheap local policy, not a drop-in API replacement.- Do not deploy as an authority on real-world Magic rules disputes.
## Environmental impact
Training is local GPU (e.g. single RTX 3090). Wall-clock for thechoice_fresh recipe is on the order of hours (LM + BC dominate beforePPO). Exact kWh not measured.
## Citation / links
If you use System One weights or this training stack in research, cite thesoftware via the repo [`CITATION.cff`](https://github.com/jedld/mtgcards/blob/master/CITATION.cff) /[`CITATION.bib`](https://github.com/jedld/mtgcards/blob/master/CITATION.bib) (and note training-data lineage in[`NOTICE`](https://github.com/jedld/mtgcards/blob/master/NOTICE)).
- Hugging Face model: https://huggingface.co/jedld/system-one-choice- TypeSafe System One concepts: https://docs.typesafe.ai/concepts/system-one- FineWeb: https://huggingface.co/datasets/HuggingFaceFW/fineweb- Repo docs: [`SYSTEM_ONE.md`](https://github.com/jedld/mtgcards/blob/master/docs/SYSTEM_ONE.md), [`SELF_IMPROVE.md`](https://github.com/jedld/mtgcards/blob/master/mtgcards/rl/SELF_IMPROVE.md)- Staging (maintainers): `checkpoints/hf_staging/jedld-system-one-choice/` (weights = `policy_0023` + this card as `README.md`). Upload: `huggingface-cli upload jedld/system-one-choice checkpoints/hf_staging/jedld-system-one-choice . --repo-type model`version https://git-lfs.github.com/spec/v1oid sha256:099b2b944e6602a8128581153b2788e3e49ced3799b8bfd9dfac6d5d71f3678fsize 9468README.md+3-204