Skip to main content

ReMiT + RLPT closed-loop flywheel: continuous self-improving LLM training

Project description

Closed-Loop Training System — ReMiT + RLPT Flywheel

╔══════════════════════════════════════════════════════════╗
║     ██████╗██╗     ██████╗ ███████╗██████╗ ██╗          ║
║    ██╔════╝██║    ██╔═══██╗██╔════╝██╔══██╗██║          ║
║    ██║     ██║    ██║   ██║█████╗  ██║  ██║██║          ║
║    ██║     ██║    ██║   ██║██╔══╝  ██║  ██║██║          ║
║    ╚██████╗██████╗╚██████╔╝███████╗██████╔╝███████╗     ║
║     ╚═════╝╚═════╝ ╚═════╝ ╚══════╝╚═════╝ ╚══════╝     ║
║                                                          ║
║         L  O  O  P        T  R  A  I  N  I  N  G         ║
║                                                          ║
║         ReMiT + RLPT  |  Continuous Self-Improvement    ║
╚══════════════════════════════════════════════════════════╝

Author: KingLabsA
GitHub: https://github.com/KingLabsA/llm-training-platform
HuggingFace: https://huggingface.co/King3Djbl | https://huggingface.co/fableforge-ai
Ollama: https://ollama.com/FableForge-AI
License: Apache 2.0

Continuous self-improving training: ReMiT token reweighting + RLPT next-segment reasoning, chained in iterative flywheel.


Quickstart

pip install closed-loop-training  # or: pip install -e .
closedloop train --model meta-llama/Llama-3.2-1B --corpus data.jsonl
# Try dummy mode first:
closedloop train --model dummy --corpus data.json --iterations 3 --tui

Features

  • ReMiT Mid-Training — Dynamic token reweighting using frozen RL reference. Tokens where the RL model assigns higher probability get upweighted. Soft sigmoid weighting clipped to [0.8, 1.2]. No token discarding.
  • RLPT Post-Training — Next-segment reasoning on pre-training data. GRPO-style optimization with generative reward model (GRM). No human annotations needed.
  • Closed-Loop Flywheel — Post-trained model becomes the RL reference for the next cycle. Each iteration bootstraps from the previous. Convergence detection stops when improvement < 0.5%.
  • Live TUI — Rich terminal dashboard with real-time ReMiT/RLPT metrics, progress bars, and iteration history table.
  • Dummy Mode — Test the full pipeline without GPU or real models. Use --model dummy.
  • Checkpoint & Resume — Save & resume from any iteration. History saved as JSON.
  • Convergence Detection — Automatic early stopping when per-iteration improvement falls below threshold.

Architecture: Closed-Loop Flywheel

                    ┌─────────────────────────────────────┐
                    │         Closed-Loop Iteration        │
                    │                                     │
                    │  ┌──────────┐    ┌──────────────┐   │
                    │  │  ReMiT   │    │     RLPT     │   │
                    │  │  Mid-    │───>│  Post-       │   │
                    │  │ Training │    │  Training    │   │
                    │  └────┬─────┘    └──────┬───────┘   │
                    │       │                 │           │
                    │       v                 v           │
                    │  ┌─────────────────────────────┐    │
                    │  │     RL Reference Model      │    │
                    │  │  (becomes teacher next cycle)│    │
                    │  └──────────────┬──────────────┘    │
                    │                 │                   │
                    │                 v                   │
                    │  ┌─────────────────────────────┐    │
                    │  │     Gap Analysis +          │    │
                    │  │     Domain Targeting        │    │
                    │  └─────────────────────────────┘    │
                    │                 │                   │
                    └─────────────────┼───────────────────┘
                                      │
                                      v
                          ┌─────────────────────┐
                          │  Improved Base Model │
                          │  (fed to next cycle) │
                          └─────────────────────┘

How It Works

  1. Initialize — Load a base model and training corpus. If no RL reference exists yet, skip ReMiT weighting on the first iteration.
  2. ReMiT Mid-Training — For each batch, compute per-token loss discrepancy between the base model and the frozen RL reference. Generate importance weights via centered sigmoid clipped to [0.8, 1.2]. Train on weighted NLL.
  3. RLPT Post-Training — Segment corpus text into sentence units. For each segment, prompt the model to predict the next segment. Score predictions with a Generative Reward Model (GRM). Optimize via GRPO (group-relative advantages with KL penalty).
  4. Reference Update — Set the post-trained model as the new RL reference (frozen). The next ReMiT cycle will compare against this improved reference.
  5. Convergence Check — Measure ReMiT loss improvement. If below threshold, stop.
  6. Iterate — Repeat. Each cycle the model learns from its own improvements.

CLI Reference

closedloop train

Flag Default Description
--model meta-llama/Llama-3.2-1B HuggingFace model name or dummy
--corpus (required) Path to JSON, JSONL, or text corpus
--iterations 3 Number of closed-loop flywheel iterations
--mid-train-steps 500 ReMiT steps per iteration
--rl-train-steps 500 RLPT steps per iteration
--remit-batch-size 8 Batch size for ReMiT
--rlpt-batch-size 4 Batch size for RLPT
--max-samples 10000 Max corpus samples to load
--domain None Target domain name
--max-seq-length 2048 Maximum sequence length
--lr 3e-4 Base learning rate
--remit-lr 3e-4 ReMiT learning rate
--rlpt-lr 1e-6 RLPT learning rate
--output-dir ./closed_loop_output Output directory
--log-interval 10 Steps between logging
--device auto auto, cuda, or cpu
--tui (flag) Enable live TUI display

closedloop resume

Flag Default Description
--checkpoint (required) Path to .pt checkpoint
--output-dir checkpoint dir Output directory
--iterations from checkpoint Override remaining iterations
--tui (flag) Enable live TUI display

TUI Mode vs Non-TUI Mode

  • TUI mode (--tui): Rich live dashboard with real-time ReMiT/RLPT metrics, progress bars, iteration history table, phase indicators, and elapsed time. Ideal for demos, monitoring, and debugging.
  • Non-TUI mode (default): Print-based logging. Each step logs loss/metrics. Compact output suitable for scripts, CI/CD, and headless environments.

Environment Variables

Variable Purpose
PYTHONPATH Should include project root for imports

Citation

@misc{kinglabsa2026closedloop,
  author = {KingLabsA},
  title = {Closed-Loop Training System: ReMiT + RLPT Flywheel},
  year = {2026},
  publisher = {GitHub},
  url = {https://github.com/KingLabsA/llm-training-platform}
}

@article{huang2026remit,
  title={ReMiT: Reinforcement Learning Guided Mid-Training for Large Language Models},
  author={Huang et al.},
  journal={arXiv preprint arXiv:2602.03075},
  year={2026}
}

@inproceedings{li2026rlpt,
  title={RLPT: Reinforcement Learning on Pre-Training Data for Next-Segment Reasoning},
  author={Li et al.},
  booktitle={ACL 2026},
  year={2026}
}

License

Apache 2.0 — See LICENSE file.


Built by KingLabsA. ReMiT paper: arXiv 2602.03075. RLPT paper: ACL 2026.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

closed_loop_training-0.3.0.tar.gz (58.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

closed_loop_training-0.3.0-py3-none-any.whl (46.6 kB view details)

Uploaded Python 3

File details

Details for the file closed_loop_training-0.3.0.tar.gz.

File metadata

  • Download URL: closed_loop_training-0.3.0.tar.gz
  • Upload date:
  • Size: 58.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for closed_loop_training-0.3.0.tar.gz
Algorithm Hash digest
SHA256 043e85e9415f22b366b32ca2e0458fc35d40be5433241ec63ceba0e4ba3766f5
MD5 49269589dbadde2331959939e7380b56
BLAKE2b-256 3820f6606e136555a0999bd1ce892abb02e8bd193e3c15c4e90010110f1cad03

See more details on using hashes here.

File details

Details for the file closed_loop_training-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for closed_loop_training-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ce669a118336a34c455279d006ef9d9be7a58274895e7add40ef22da4a3ef01a
MD5 6c0ba242510135302b77c7c96157008b
BLAKE2b-256 4064ec920c855781c2d53ae83074b4b6884208c294ef5b4dc97b71a5944fdbc3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page