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.4.0.tar.gz (60.2 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.4.0-py3-none-any.whl (48.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: closed_loop_training-0.4.0.tar.gz
  • Upload date:
  • Size: 60.2 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.4.0.tar.gz
Algorithm Hash digest
SHA256 95841f157dc58059074cc3fcd8b6a2bfafcaf5aa37edd738f43b362b71be5480
MD5 ca0813b08dc3ea1be5386c7466d0a02d
BLAKE2b-256 8a7e26fb9f694c0507f93dd35f7abf96b7df8994ba5d8f561f96cf8358550792

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for closed_loop_training-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 13397b9452dd2b93ee0c4bb7b55a1e061490cbe9985213d39c06d8d2786cced7
MD5 a09028841b887a31f390f866084eaecd
BLAKE2b-256 a5687b823bd8574a64b65d53f747f4ab7557d0b1fd8943a328e0b94d174045b4

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