{"data":{"kind":"file","path":"README.md","version_id":"hy0u7vnqj6alddev1a7cqz9a","entry":{"name":"README.md","path":"README.md","is_directory":false,"size":8210,"modified_at":"2026-11-25T16:19:47.160000","content_hash":"c61252ce7ca2dbefac2518bf8b751dc680f915f09429cad219dd5b5839ffe137"},"entries":[],"content":"# Circuit RLVR\n\n**Train LLMs to write neural networks that actually compute.** Circuit RLVR provides executable rewards for constructing dense ReLU circuits, counterexample-guided repair, and functionally disjoint train/validation tasks.\n\nBuilt on [Prime Intellect `verifiers` v1](https://github.com/PrimeIntellect-ai/verifiers). **Research preview: `0.1.x`.**\n\n## Why use it?\n\n- **RL with verifiable rewards:** train on full-domain functional correctness, not an LLM judge.\n- **Counterexample repair:** let the policy revise malformed or incorrect networks using grader feedback.\n- **Evaluation and synthetic data:** compare direct synthesis, feedback-assisted synthesis, and family-level generalization while saving structured traces.\n\nEvery task is solvable by a compact reference network under the same limits imposed on the model.\n\n## Quickstart\n\nRequires Python 3.11+ and a [Prime Intellect account](https://app.primeintellect.ai/).\n\n```bash\nuv tool install prime\nprime login\nprime env install githubpradeep/circuit-rlvr@latest\n```\n\nRun three real rollouts on Prime-managed infrastructure:\n\n```bash\nprime eval run githubpradeep/circuit-rlvr \\\n    --hosted -m openai/gpt-6-luna -n 3 -r 1 --follow\n```\n\nHosted evaluation and Prime Inference require available account funds. To use another OpenAI-compatible provider, see [custom endpoints](#custom-endpoints).\n\n### Local rollout\n\nAfter installing the environment into your project, use the subprocess runtime without a hosted sandbox:\n\n```bash\nexport PRIME_API_KEY=...\nuv run vf-run circuit-rlvr \\\n    -m openai/gpt-6-luna -n 3 -r 1 \\\n    --env.agent.runtime.type subprocess\n```\n\n### Model-free validation\n\nNo credentials, model calls, dataset downloads, or containers are required for the reference and untouched-submission checks:\n\n```bash\nuv run vf-validate circuit-rlvr --runtime.type subprocess -n 2\n```\n\n## What the model does\n\nThe model returns one JSON network. For example, XOR can be constructed as:\n\n```json\n{\n  \"layers\": [\n    {\n      \"weight\": [[1, 1], [1, 1]],\n      \"bias\": [0, -1],\n      \"activation\": \"relu\"\n    },\n    {\n      \"weight\": [[1, -2]],\n      \"bias\": [0],\n      \"activation\": \"none\"\n    }\n  ]\n}\n```\n\nThe grader parses the network and evaluates **every input in the finite domain** in float64. With `env.attempts > 1`, an incorrect answer produces another user turn containing the grading error and up to three counterexamples.\n\nA deterministic two-turn smoke episode using a mock endpoint produces:\n\n```text\nattempt 1: no_network\nattempt 2: exact pass\nexact_pass=1\npass_at_1=0\nbest_case_accuracy=1.0\nattempts_used=2\nreward=1.1\n```\n\nThis verifies the full Prime interaction lifecycle; it is not a model-performance baseline.\n\n## Reward\n\nFor attempts within one episode:\n\n```text\nreward = exact_pass + progress_weight * best_case_accuracy\n```\n\n- `exact_pass` is 1 only when every output in the full domain has absolute error strictly less than 0.25 from the expected integer; otherwise 0.\n- `best_case_accuracy` is the best fraction of domain rows passing that tolerance across attempts. Nonfinite rows fail without erasing valid rows.\n- `progress_weight` defaults to 0.1 for RL. Set it to 0 for exact-only evaluation.\n- Malformed, oversized, nonfinite, or missing networks receive zero exact reward.\n\nRecorded metrics include `exact_pass`, `pass_at_1`, `valid_response`, `best_case_accuracy`, `attempts_used`, and, for valid responses, layers, parameters, and worst error.\n\n## Tasks and splits\n\nTen procedural families:\n\n| Family | Examples |\n|---|---|\n| Boolean aggregation | parity, threshold/majority |\n| Arithmetic | addition, multiplication, modulo |\n| Ordering and values | sorting, maximum, absolute difference |\n| Stateful dynamics | door transitions, battery use/charging |\n\nThe default task space has **149 variants** with exhaustive domains capped at 256 rows. Degenerate functions are removed. Train and validation are:\n\n- Family-stratified, with every family represented in both default splits.\n- Functionally disjoint using complete domain-and-target signatures, not just different parameter names.\n- Deterministic: changing `seed` changes ordering, not split membership.\n\nEvery variant has a constructive reference that passes the production limits: **32 layers, width 512, and 50,000 parameters**.\n\n## Evaluate exact synthesis\n\nUse the disjoint validation split with no repair and no partial-reward shaping:\n\n```bash\nuv run vf-run circuit-rlvr \\\n    --env.taskset.split validation \\\n    --env.taskset.task.progress_weight 0 \\\n    --env.attempts 1\n```\n\nFor a family-level holdout, exclude that family from training and evaluate separately with `env.taskset.families` containing only the held-out family. Different seeds alone do not establish family-level generalization.\n\n## Train with `prime-rl`\n\n[`configs/rl.toml`](configs/rl.toml) is a small starting configuration using Qwen3-4B-Instruct, LoRA, groups of 8, three repair attempts for training, and exact one-attempt validation. It begins with `parity`, `majority`, `max`, and `absdiff` at `max_domain = 64` to keep JSON rollouts manageable. Expand the curriculum after establishing a baseline.\n\nThe configuration was checked locally with `prime train validate`; no training result is claimed. Installed wheels also include it as `circuit_rlvr/configs/rl.toml`.\n\n```bash\n# Validate the config without submitting a run\nprime train validate configs/rl.toml\n\n# From a prime-rl checkout with the environment installed\nuv run rl @ configs/rl.toml --dry-run\n\n# Optional Hosted Training; requires funds and a checkpoint volume\nprime train configs/rl.toml --volume <your-volume>\n```\n\nSee the [`prime-rl` training guide](https://docs.primeintellect.ai/prime-rl/training) for self-hosted training and the [Hosted Training guide](https://docs.primeintellect.ai/hosted-training/end-to-end-run) for managed runs.\n\n## Agent integration\n\n| Field | Value |\n|---|---|\n| Taskset ID | `circuit-rlvr` |\n| Verifiers API | `v1` |\n| Environment | `CircuitEnv` |\n| Default harness | `null` |\n| Action | One JSON network in a fenced `json` block |\n| Rollout output | Structured traces, rewards, and named metrics |\n| Default attempts | 1; later attempts receive feedback when increased |\n\n| Setting | Default | Purpose |\n|---|---:|---|\n| `env.taskset.split` | `train` | `train` or disjoint `validation` |\n| `env.taskset.num_tasks` | 128 | Maximum tasks emitted from the selected split |\n| `env.taskset.seed` | 0 | Deterministic task ordering |\n| `env.taskset.max_domain` | 256 | Exhaustive domain cap, from 4 to 256 |\n| `env.taskset.families` | all ten | Families included in task generation |\n| `env.taskset.task.progress_weight` | 0.1 | Partial-accuracy reward shaping; 0 disables it |\n| `env.attempts` | 1 | Submissions per episode; later attempts receive feedback |\n\n### Custom endpoints\n\nAny OpenAI-compatible endpoint can be selected without changing the environment:\n\n```bash\nuv run vf-run circuit-rlvr -n 1 -r 1 \\\n    --client.base-url https://openrouter.ai/api/v1 \\\n    --client.api-key-var OPENROUTER_API_KEY \\\n    --env.agent.runtime.type subprocess\n```\n\n## Current validation and limitations\n\nVerified for this release:\n\n- Procedural references pass under production limits.\n- Train/validation functions are disjoint and every family has validation coverage.\n- Prime gold/no-op validation passes.\n- A clean wheel install and deterministic two-turn Prime rollout pass.\n\nResearch-preview limitations:\n\n- Tasks are small, synthetic, finite functions—not general hardware design.\n- This release trains direct dense-ReLU JSON synthesis only. The repository's heavyweight CPU, transformer, and code-generator tracks are outside the RL loop.\n- Public validation tasks are not contamination-proof. Use private or newly generated variants for high-stakes evaluation.\n- No model-performance baseline or RL improvement is claimed yet. Run the quickstart to establish a baseline before scaling.\n- The 0.25 tolerance is a functional grading threshold, not a proof of mathematical exactness.\n\n## Development and license\n\nSource setup, tests, publishing, and the original Circuit Bench are documented in [`docs/development.md`](docs/development.md). Distributed under the MIT License.\n","encoding":"utf-8","truncated":false,"total_bytes":8210},"status":null}