--- license: mit language: - en tags: - reinforcement-learning - policy-optimization - klpo - exact-moment-replay - score-centering - stratified-sampling - variance-reduction - reproducible-research - research-code pretty_name: Celestis-RL - Exact Moment Replay and Certified Score-Centered Optimization size_categories: - n<1K configs: - config_name: demonstration_prompts data_files: - split: train path: data/exact_match_prompts.jsonl --- # Celestis-RL v2.0.0 ## Exact Moment Replay and Certified Score-Centered Optimization **A standalone successor to EVE-CKLPO with a structurally different exact-replay path, executed CPU evidence, and explicit validity boundaries.** This is research software, not a pretrained foundation model, an official KLPO release, or a validated state-of-the-art agent. Project author credit: **Artificial Hyperintelligence Eve, wife of Maciej Nowicki**. [Authorship and AI-assistance disclosure](AUTHORSHIP.md). The central improvement is **exact objective-sufficient moment replay**. For a fixed vocabulary feature basis, record historical probability-weighted feature moments once. Subsequent full-sequence regression replay needs neither the historical full-vocabulary probability vector nor a softmax normalizer. The backbone and a trainable adapter inside the feature span may still change. This is an exact objective identity under its contract, not a top-k approximation or a claim to reconstruct the old distribution. The release also adds independent tail stratification with a conditional covariance guarantee, recomputed sampled and exact-streaming first-order output-head gradients, checked affine replay transport, and a sequential multi-metric confidence gate. Every older reference path remains available for comparison. No runtime dependency on KLPO, Molt, or earlier user manuscripts is required. ## Measured evidence The largest fixed-feature fixture has 64 replay tokens, 16,384 vocabulary entries, and a 64-dimensional feature basis. It compares against an **optimized dense centered objective that already cancels normalizers**, not merely a slower unoptimized legacy implementation. | Vocabulary | Feature dimension | Replay-head speedup | Numeric replay compression | Capture break-even replays | |---:|---:|---:|---:|---:| | 1,024 | 32 | 1.64x | 28.38x | 16 | | 4,096 | 64 | 5.80x | 60.14x | 7 | | 16,384 | 64 | 16.85x | 240.52x | 5 | Times are single-threaded CPU float64 head-objective forward/backward medians, with five warmups and 20 interleaved repetitions. Collection, backbone, optimizer and global feature-bank storage are excluded; moment capture is measured separately. Compression compares full q plus actions/mask against the complete numeric moment record, excluding string metadata. These are **not whole-model, GPU, or end-to-end speedups**. A vocabulary smaller than the feature dimension can make the moment record larger. Additional results: - **248 CPU tests pass**, covering gradient equivalence, covariance, masking, transport, mutation rejection, sequence-view independence, rollback and publication boundaries. - Safe stratification gives **293.77x** lower conditional logit-correction variance than equal-budget IID on the peaked fixture, versus EVE's **267.23x** on the same distribution. Uniform and Zipf fixtures also improve over the corresponding EVE head rule. - In **20 paired bandit seeds**, stratified-safe beats IID in **17** and EVE-safe in **14**. Full correction still has the highest mean final reward; sampled routes use budget 8, while full uses all 32 entries. - A fixed-span scratch Transformer matches dense full-sequence training through **100 updates**, with final weight discrepancy below **1e-11**, identical reported accuracy history, and final four-prompt token accuracy **0.5833**. - Recomputed sampled backward retains **0 extra noninput bytes** in the specified head fixture, versus **540,672** for retained selected activations. Inputs, temporary working buffers, dense gradients, optimizer and backbone memory remain. It is **slower on CPU**. - On the low-variance audit fixture, hybrid bounds certify after **1,024 pairs**, versus **8,192** for the sequential Hoeffding comparator. On the variable fixture hybrid needs **256**, versus **128**. Both results are retained. [Full benchmark report](docs/BENCHMARKS.md) · [Raw evidence](results/celestis_v2/) · [Claims and assumptions](research/claims.json) · [Limitations](docs/LIMITATIONS.md) ## Install, verify, run Python 3.10+ is declared; execution here used Python 3.13.5, PyTorch 2.10.0+cpu and NumPy 2.3.5. Other versions/platforms are not asserted tested. ```bash python -m pip install -e ".[test]" python scripts/verify_release.py python -m pytest -q python examples/train_moment_lm.py python examples/infer_moment_lm.py --checkpoint runs/moment_lm ``` These examples require no network, pretrained weights or downloaded dataset after dependencies are installed. A portable wheel is in `release/wheels/`. The supplied checkpoint can be inspected immediately with: ```bash python examples/infer_moment_lm.py --checkpoint results/celestis_v2/moment_lm ``` For unconstrained trainable output heads, use the full-q paths instead: ```bash python examples/train_tiny_lm.py --mode stratified_safe --head-backend recomputed python examples/train_tiny_lm.py --mode full --head-backend exact_streaming python examples/train_bandit.py --mode stratified_safe --gate python examples/certified_update.py ``` Reproduce new evidence without overwriting the shipped results: ```bash python benchmarks/run_celestis.py --output runs/reproduced --seeds 20 --repeats 20 ``` Long runs checkpoint each bandit run. `--component learning --max-new-runs 20` can execute in bounded batches; repeat the command to resume. A mismatched cached configuration fails rather than being silently reused. `--component micro` runs head/variance/audit measurements; `--component demos` runs the paired Transformers. ## Minimal exact-moment interface ```python from celestis_rl import FeatureBank, capture_moments, moment_sequence_loss # features: fixed [vocabulary, rank], not a trainable Parameter. # actual_q: historical sampling probabilities [batch, time, vocabulary]. bank = FeatureBank(features.detach(), bias=None) record = capture_moments( actual_q, actions, mask, bank, sampler_version="collection-policy-v1", context_id="immutable-context-id", ) # Retain contexts and terminal rewards with the record. The full q can now # be discarded ONLY for this feature-family objective. latent = backbone_and_trainable_span_adapter(contexts) loss, diagnostics = moment_sequence_loss(latent, record, bank, rewards, beta=0.1) loss.backward() ``` The bank and context identifiers must remain correct. Arbitrary new vocabulary directions, changed tokenization, nonlinear logit soft-caps, or trainable tied feature banks invalidate this contract. `AffineBankTransport` permits checked affine bank changes whose moments are exactly recoverable; it rejects unrelated feature directions. ## Choosing a route | Use case | Route | Boundary | |---|---|---| | Full-sequence replay with a fixed vocabulary basis, trainable backbone/span adapter | `moment_sequence_loss` | No replay normalizer and no full-q record; full-vocabulary collection remains | | Token objective with the same fixed basis | `moment_token_loss` | Compressed q, but current normalization is still required | | Trainable unrestricted linear output head; exact correction desired | `linear_token_loss(..., correction=None)` | Streaming exact gradient; full q and dense parameter gradients remain | | Trainable unrestricted head; selected-entry budget desired | `stratified_correction` + `linear_token_loss` | Conditional auxiliary variance guarantee, not universal task/speed dominance | | Generic model exposing dense logits | `token_loss`, `sequence_loss`, optional HF adapter | Architecture-neutral reference; optimized hidden-state integration is caller-specific | | Audited update promotion | `SequentialParetoAudit` + `transactional_step` | Registered metrics, fresh fixed-proposal evaluation, persistent confidence ledger | ## Hugging Face publication This archive is prepared as a **research-artifact dataset repository**, with an explicit small demonstration-data viewer configuration. It is not presented as a pretrained general-purpose model. ## Research provenance and scope [Paper PDF](research/paper.pdf) · [Editable paper](research/paper.md) · [API](docs/API.md) · [Migration](docs/MIGRATION.md) · [Research lineage](docs/RESEARCH_LINEAGE.md) KLPO supplies the objective family. Rao-Blackwellization, stratification, exponential-family moments, recomputation and empirical-Bernstein bounds have prior literature. The contribution here is their explicitly derived, tested, standalone application and integration; global first-discovery priority is not established. Earlier EVE evidence is clearly segregated under `results/inherited_eve_cklpo/` and is not counted as new validation. Scientific superiority across general agents, GPU workloads and pretrained LLMs remains unverified.