{"data":{"kind":"file","path":"README.md","version_id":"qy8chidvbo1b9lv6r7ixre8h","entry":{"name":"README.md","path":"README.md","is_directory":false,"size":15714,"modified_at":"2026-11-28T04:33:14","content_hash":"85fc57f7d354df12158bbffcbc937fb7fe622894e24a8085eb0bcda3175fe081"},"entries":[],"content":"![oice: learning to fight with delayed observations](media/oice-banner.svg)\n\n# oice-rl-training\n\n**Can your coding agent teach a fighter to win? Give it a simulator, a compute budget and an arena. It writes its own learning code, runs experiments on CPUs or Prime Intellect GPUs, and submits a trained policy for independent fights.**\n\n[Prime Intellect Hub](https://app.primeintellect.ai/dashboard/environments/thehon/oice-rl-training)\n· [CPU or GPU](#choose-a-training-backend)\n· [Set up](#set-up-once)\n· [Connect a model](#run-your-model)\n· [Scoring](#scoring)\n· [The research behind it](https://github.com/thehon/oice-public)\n\n[![Our trained fighter against MctsAi23i in FightingICE](media/oice-vs-mcts-native50.gif)](media/oice-vs-mcts-native60.mp4)\n\n*Our research agent (P1, policy plus search) against MctsAi23i (P2) in the Java game.\n[Watch the 60 fps video](media/oice-vs-mcts-native60.mp4) ·\n[View the repo on GitHub](https://github.com/thehon/oice-public).\nThis environment trains a new policy against scripted opponents and produces HTML replays with debug geometry.*\n\n---\n\noice-rl-training is the second half of the harness from [oice](https://github.com/thehon/oice-public), where we trained a FightingICE agent from scratch with self-play RL. That took many weeks of experiments. This environment asks whether a coding agent can do a small version of the same job on its own.\n\nIt is a [Verifiers](https://github.com/PrimeIntellect-ai/verifiers) environment on the [Prime Intellect Environments Hub](https://app.primeintellect.ai/dashboard/environments). In each episode the agent gets:\n\n- **A fighter to train.** 264 observations, 42 actions and a fixed 32-unit MinGRU, starting from random weights. No pretrained fighter or tuned learner is supplied.\n- **Opponents to beat.** The scripted controllers `strike` and `zone_hard` for practice; the final also scores a held-out learned opponent, `policy-ref32`.\n- **A budget.** A fixed amount of training time on local CPU workers or Prime A100 GPUs, and a fixed number of training launches.\n- **Documentation.** Task instructions, observation definitions and the Actor and Batch API references, in a Bash workspace.\n\nIt must write the learning code, launch training jobs, test exports in development fights, and explicitly select one policy. That policy then plays independent final matches.\n\n## Reference results\n\nThese checks show the task is learnable within its budget, and how a real model run can go. They are not a model leaderboard.\n\n| Run | Setup | Result |\n| --- | --- | --- |\n| Reference PPO learner, 5 seeds, current default grid | 600 s each on 2 CPU cores, about 2.8M decisions | Untrained **0.45** → trained **0.80** on average (per seed 0.75, 0.50, 0.75, 1.00, 1.00). Against the held-out policy-ref32 alone: 0.50, 0.00, 0.50, 1.00, 1.00 |\n| Same learners, old bots-only grid (rc6 and earlier) | | 0.60 → 1.00; 40 of 40 final matches won. The grid saturated, so rc7 replaced zone_hard with policy-ref32 in the final |\n| One live model pilot (DeepSeek v4.1 Flash), rc6 grid | 300 s CPU training budget, 24 model responses | The agent wrote and ran a learner whose export won 4 of 4 development fights (its untrained start drew all 4), then hit its token reservation limit before selecting. Reward **0.00** |\n\nThe pilot shows the scoring rule working as intended: a trained policy that was never selected scores zero. Calibration details are in the oice-env opponents guide, `docs/opponents.md` in its source (installed as `oice_env/bundled/docs/opponents.md`).\n\n## Choose a training backend\n\n| | CPU | GPU |\n| --- | --- | --- |\n| Training runs on | Local Docker workers | Prime Intellect A100 VM sandboxes |\n| Resources per job | 2 CPU cores, 4 GiB RAM | 1 A100; the example requests 4 CPU cores and 16 GiB RAM |\n| Jobs at once | One per episode | One or two per episode (two-GPU account cap in this backend) |\n| Training stack | CPU PyTorch with batched C simulation | CUDA PyTorch with batched C simulation |\n| Extra access needed | None at runtime | Prime API key, sandbox billing and a GPU grant |\n| Setup | [Option 1](#option-1-local-cpu-training) | [Option 2](#option-2-prime-intellect-gpu-training) |\n\nBoth backends use the same learner-facing commands, policy export, development fights, selection and final scoring. The model's inference provider is independent of the training backend: OpenRouter, Prime Intellect inference or another compatible endpoint can drive the Bash harness.\n\nTo run both, prepare both options and pass `--backend both` to the model harness example. It runs a fresh CPU episode and then a fresh GPU episode, each with its own budget, selection and results. A single episode never mixes CPU and GPU jobs or moves checkpoints between them.\n\n## Set up once\n\nThe owner machine runs the evaluator and needs Linux x86-64 (glibc), Python 3.11 and Docker. With GPU training, the solver and the trusted evaluator still run locally; only training jobs run in Prime Intellect GPU VMs. The owner machine needs no GPU or CUDA.\n\nWith the [Prime CLI](https://docs.primeintellect.ai/tutorials-environments/environments), install the pinned evaluator and this environment:\n\n```sh\nuv venv .venv --python 3.11\n. .venv/bin/activate\nprime env install thehon/oice-env@0.1.0rc17 --prerelease\nprime env install thehon/oice-rl-training@0.1.0rc11 --prerelease\nprime env pull thehon/oice-rl-training@0.1.0rc11 --target ./oice-training-source\ncd oice-training-source\n\ndocker pull python:3.11-slim\noice-training contract\n```\n\nThe evaluator is pinned to `oice-env` `0.1.0rc17` file by file (`src/oice_rl_training/evaluator-core.json`, regenerated with `tools/pin_evaluator.py`); grading refuses any other build. Installation does not download game inputs or checkpoints.\n\nThe default final includes the held-out `policy-ref32`, so prepare an oice-env asset bundle with it and export `OICE_ASSET_ROOT`, or pass `final_assets` in the task config. The oice-env README gives the steps: our weights come from the `oice-env-weights-v1` release, and the character tables from FightingICE's own `resource-7.1.zip`. After those steps, `OICE_CHARS` is `$PWD/oice-src/third_party/FightingICE7.1/data/characters`.\n\nSet the character-table path and locate the native inputs from the installed evaluator:\n\n```sh\nexport OICE_CHARS=/absolute/path/to/accepted/characters\nexport OICE_LIBRARY=\"$(python -c 'from oice_env.native import library_path; print(library_path())')\"\nexport OICE_HEADER=\"$(python -c 'from oice_env.paths import package_tree; print(package_tree() / \"native/shim.h\")')\"\n```\n\n`OICE_CHARS` must contain the accepted `ZEN/Motion.csv` and `ZEN/gSetting.txt`. The task reads `OICE_CHARS`, `OICE_LIBRARY`, `OICE_ASSET_ROOT` and (for CPU) `OICE_TRAINING_IMAGE` as defaults when its config leaves them empty. Their hashes are in `src/oice_rl_training/jobs.py`; native input hashes are in `src/oice_rl_training/cpu-native-inputs.json`.\n\n## Option 1: local CPU training\n\nBuild the worker once from the pulled source. `build/native` must be a new directory.\n\n```sh\npython tools/build_batch.py --library \"$OICE_LIBRARY\" \\\n  --header \"$OICE_HEADER\" --output build/native\ndocker build -f Dockerfile.cpu -t oice-training-cpu:t08 .\n```\n\nCheck the whole CPU workflow with a local model fixture:\n\n```sh\noice-training run --task training --mode mock --profile cpu-workflow-v1 \\\n  --image oice-training-cpu:t08 --chars \"$OICE_CHARS\" \\\n  --library \"$OICE_LIBRARY\" --output /tmp/oice-cpu-check\n```\n\nThis runs training, export, development, selection, final fights and replays. It needs no inference key and no Prime Intellect allocation. Use a new output directory each time. Replace `--mode mock` with `--mode plan` to inspect the workflow without starting containers.\n\n## Option 2: Prime Intellect GPU training\n\nGPU training requires Prime Intellect sandbox billing and an explicit GPU grant. You only need the CPU image above if you also want the CPU option.\n\nFrom the pulled source, install the optional GPU dependency:\n\n```sh\nuv pip install --python python '.[gpu]'\n```\n\nKeep the Prime API key in a private env file on the owner machine, outside any model workspace:\n\n```text\nPRIME_API_KEY=your-key\n```\n\nCreate a private configuration from the supplied template. Edit the two owner paths; the native input paths come from the common setup.\n\n```sh\nexport OICE_GPU_CONFIG=/absolute/private/oice-gpu.json\npython - <<'PY'\nimport json, os\nfrom pathlib import Path\n\nconfig = json.loads(Path('configs/GPU_A100_V1.example.json').read_text())\nconfig.update(\n    credentials_file='/absolute/private/credentials.env',\n    slot_db='/absolute/private/oice-gpu-slots.sqlite',\n    library=os.environ['OICE_LIBRARY'],\n    header=os.environ['OICE_HEADER'],\n)\npath = Path(os.environ['OICE_GPU_CONFIG'])\npath.parent.mkdir(parents=True, exist_ok=True, mode=0o700)\nwith path.open('x') as stream:\n    json.dump(config, stream, indent=2)\npath.chmod(0o600)\nPY\n```\n\nUse the same GPU config and slot database for every runner on the owner machine, and keep the slot database outside individual run directories. The template pins the CUDA image and limits the account to two concurrent GPU jobs. Prime Intellect's own account quota also applies.\n\nCheck the whole GPU workflow:\n\n```sh\noice-training run --task training --mode mock --profile gpu-workflow-v1 \\\n  --gpu-config \"$OICE_GPU_CONFIG\" --gpu-concurrency 2 --training-seconds 600 \\\n  --chars \"$OICE_CHARS\" --library \"$OICE_LIBRARY\" --output /tmp/oice-gpu-check\n```\n\nNote that this mock allocates real GPU VMs; only the model is replaced by a local fixture. Use `--gpu-concurrency 1` for sequential experiments. Replace `--mode mock` with `--mode plan` to inspect it without reading credentials or allocating anything.\n\nEach job gets one GPU and requests 60 to 600 seconds in 60-second blocks. The episode budget reserves pending allocations and charges the total wall time of all jobs, including provisioning and cleanup, so two parallel jobs each use GPU time. If a VM's deletion cannot be confirmed, its slot stays held and cleanup fails.\n\nThe agent's optimization runs on CUDA; the C simulation stays on CPU. A GPU does not by itself guarantee faster training.\n\n## Run your model\n\n[examples/model_harness.py](examples/model_harness.py) is a short configuration example using the existing Bash harness in Verifiers 0.4.0. It supports CPU, GPU or both, creates separate episodes, lets the SDK handle runtime cleanup, and keeps provider credentials on the owner side. It does not supply a training algorithm.\n\nFirst inspect the setup. Plan mode makes no model or GPU calls:\n\n```sh\npython examples/model_harness.py --backend both --mode plan \\\n  --gpu-concurrency 2 --output /tmp/oice-harness-plan\n```\n\nFor live runs, choose a model that supports tool calling. Put its provider key in your private env file, or export it in the owner shell. The default provider is OpenRouter with `OPENROUTER_API_KEY`; use `--base-url` and `--api-key-var` for another provider. The Prime API key for GPU VMs is read separately, from the GPU config's `credentials_file`.\n\n```sh\n# CPU only (option 1)\npython examples/model_harness.py --backend cpu --mode live --model YOUR_MODEL \\\n  --env-file /absolute/private/credentials.env --output /tmp/oice-model-cpu\n\n# GPU only (option 2)\npython examples/model_harness.py --backend gpu --mode live --model YOUR_MODEL \\\n  --env-file /absolute/private/credentials.env --gpu-concurrency 2 \\\n  --output /tmp/oice-model-gpu\n\n# Both: CPU first, then GPU in a fresh episode\npython examples/model_harness.py --backend both --mode live --model YOUR_MODEL \\\n  --env-file /absolute/private/credentials.env --gpu-concurrency 2 \\\n  --output /tmp/oice-model-both\n```\n\nThese commands read `OICE_CHARS`, `OICE_LIBRARY` and, for GPU, `OICE_GPU_CONFIG` from setup; you can pass `--chars`, `--library` and `--gpu-config` instead. Live runs incur model provider charges and, for GPU, VM charges.\n\n| Setting | Default | Flag |\n| --- | --- | --- |\n| CPU episode budget | 300 wall seconds | `--cpu-seconds` |\n| GPU episode budget | 600 summed allocation seconds | `--gpu-seconds` |\n| Training launches per episode | 2 | `--max-jobs` |\n| Active GPU jobs | 1 | `--gpu-concurrency 1` or `2` |\n| Model responses per episode | 24 | `--turns` |\n| Output tokens per response | 16,384 | `--reply-tokens` |\n\nThe example also enforces per-episode SDK token limits and turns off automatic rollout retries. Run `--help` for every option. CPU and GPU results keep their own budgets, so they are not matched benchmark trials.\n\nResults are written under the output directory:\n\n```text\nplan.json\nresults.json\ncpu/result.json       # CPU outcome, if selected\ncpu/private/          # jobs, source snapshots and policy receipts\ncpu/replays/\ngpu/result.json       # GPU outcome, if selected\ngpu/private/\ngpu/replays/\n```\n\n### Plain `vf-eval`\n\n`configs/vf-eval-cpu.example.toml` runs the CPU task through stock Verifiers with the same limits as the example harness:\n\n```sh\nvf-eval @ configs/vf-eval-cpu.example.toml -m YOUR_MODEL --no-push\n```\n\nThe solver runtime must be local Docker (`[env.agent.runtime] type = \"docker\"`); the task refuses other runtimes with a message saying so, because the evaluator and workers run on this machine.\n\nTo use your own harness, construct `TrainingTask` with a `TrainingTaskConfig`. Set `backend='cpu'` and `image=...`, or `backend='gpu'`, `gpu_config=...` and `gpu_concurrency=1|2`. Both need `chars` and `library`. Use a fresh task, private state directory and selection for each episode, and finalize every rollout. The example shows the full wiring.\n\n## Inside an episode\n\nThe learner-facing commands are the same on either backend:\n\n| Step | Commands |\n| --- | --- |\n| Launch | `oice-training train start --backend cpu ...` or `--backend gpu ...` |\n| Inspect | `status --compact`, `train status`, `train logs --tail 20` |\n| Submit | `policy receive`, then `policy test --select` |\n\nThese commands run inside an issued model episode, not in a plain host shell. Exports contain `policy.bin`, `policy.json` and `manifest.json`. See the [task interface](src/oice_rl_training/TRAINING.md) and the [worker API](src/oice_rl_training/API.md) for arguments and data layouts.\n\n## Scoring\n\nThe selected policy plays independent final matches:\n\n| Win | Draw | Loss |\n| :---: | :---: | :---: |\n| 1 | 0.5 | 0 |\n\nThe reward is the mean match score. No selection scores zero; a training log or a valid export alone does not count.\n\nThe default grid is `strike` and `policy-ref32`, both seats, seeds 8401 and 8402: 8 matches. Training and development stay on the scripted bots, so `policy-ref32` measures whether the learner generalises beyond them. Two extra signals are recorded:\n\n| Signal | Meaning |\n| --- | --- |\n| `score_over_untrained` (metric) | Final score minus 0.45, the mean of five untrained initialisations on the default grid. Not recorded on other grids |\n| `hp_margin` (reward, weight 0) | Mean HP margin per final match mapped to [0, 1]. Enable with `[env.taskset.task.rewards.hp_margin] weight = 0.5` | Reports keep the policy identity, match results and HTML replays. The evaluator chooses the final opponents, seeds and budgets. This scripted roster is separate from the research goal of beating BlackMamba.\n\nWould you rather have an agent write a controller directly? Use [oice-env](https://app.primeintellect.ai/dashboard/environments/thehon/oice-env).\n\n## Status and license\n\nThe package is MIT licensed. Game inputs are supplied by the operator; third-party terms and provenance are in `NOTICE`. Built on [FightingICE](https://github.com/TeamFightingICE/FightingICE), [PufferLib](https://github.com/PufferAI/PufferLib) and [Verifiers](https://github.com/PrimeIntellect-ai/verifiers).\n","encoding":"utf-8","truncated":false,"total_bytes":15714},"status":null}