What is LoongSage?
LoongSage is a reinforcement-learning post-training framework for large language models, published by Baidu under its baidu-baige GitHub organisation. It sits in the RLHF & Alignment category of the Training & Fine-Tuning tools and is open-source, written in Python and licensed Apache-2.0. To get started: pull and start the container.
Overview
LoongSage is a reinforcement-learning post-training framework for large language models, published by Baidu under its baidu-baige GitHub organisation. It uses Ray for scheduling, Megatron-Core as the training backend and SGLang as the inference (rollout) backend, and it is aimed at agentic RL on very large models — the validated recipes include DeepSeek-V4-Flash, DeepSeek-V4.1-Flash and ERNIE-5.5-Flash-Base as well as Qwen3 models down to a single-GPU Qwen3-0.6B example. The code acknowledges slime as its main architectural reference, with ideas from verl and Agent Lightning.
Its central design choice is zero-intrusion agent access. An agent only has to call the framework's inference service through a standard chat-completion interface; the built-in AgentFlow module handles multi-turn context, tool-output recognition, loss masking, trajectory collection and sandbox lifecycles. That is how the project trains black-box coding agents — OpenCode, Codex and Claude Code — with RL without changing their code. A single controller drives training, sampling, teacher inference and weight synchronisation across Ray actors.

The framework puts weight on keeping training and inference consistent, which matters most for mixture-of-experts models and low precision. It ships router replay for experts, an FP32 output layer, importance-sampling correction and other alignment techniques, and monitors the train–inference probability gap live; the README reports that gap held around 1e-4. Training can run fully asynchronously with partial rollout and oversampling, which the team reports raised throughput 39% in its experiments, and weights move between engines over CUDA IPC when colocated or NCCL across nodes.

Beyond RL algorithms such as DAPO, GRPO and PPO it supports SFT and on-policy distillation (PG-style, GKD-style, full-vocabulary and multi-teacher), mixed training across several data sources, image-modality RL and quantisation-aware training for DeepSeek-V4.1. Twelve extension points — agents, rewards, sandboxes, advantage estimators, losses, KL terms and more — load from a custom directory without touching the core. It is Apache-2.0 licensed and was open-sourced in August 2026, with a technical report on arXiv.
What it does
- Any agent trains through a plain chat-completion endpoint; AgentFlow handles multi-turn context, loss masks, trajectories and sandboxes
- Ray + Megatron-Core + SGLang stack with a single controller and colocated or disaggregated GPU placement
- Train–inference consistency tooling for MoE: router replay, FP32 output layer, importance-sampling correction and live bias monitoring
- Fully asynchronous training with partial rollout, oversampling and sliding-window staleness control
- On-policy distillation (PG, GKD, full-vocabulary, multi-teacher), SFT and multi-data-source mixed training
- Tested recipes under conf/ for DeepSeek-V4/V4.1-Flash, ERNIE-5.5-Flash-Base and Qwen3 models
Getting started
The project recommends its container image, which pins CUDA, PyTorch, Megatron-Core, Megatron-Bridge, SGLang and Ray and applies its SGLang patches. The first-run example below trains Qwen3-4B with DAPO on one 8-GPU node, as in the README.
Pull and start the container
docker pull loongsage/loongsage:latest
docker run -it --gpus all --ipc=host --network=host \
-v /path/to/workspace:/root loongsage/loongsage:latest bashDownload a model and dataset
hf download Qwen/Qwen3-4B --local-dir /root/Qwen3-4B
hf download Haitao999/DAPO-Math-17k-unique --repo-type=dataset \
--local-dir /root/DAPO-Math-17k-uniqueLaunch a recipe
Every run goes through examples/start.sh with a Hydra config name from conf/ plus any overrides; logs land in log/trainer_<timestamp>.log.
bash examples/start.sh qwen3_4b/dapo_h800_1node \
hf_model_path=/root/Qwen3-4B \
data_source.dataset.prompt_data_path=/root/DAPO-Math-17k-uniqueCommands and code are distilled from the project's own documentation — always check the official repo for the latest.
When to use it
- RL post-training of large MoE models where train–inference mismatch can collapse a run
- Training an existing coding agent (OpenCode, Codex, Claude Code) with RL without rewriting the agent
- On-policy or multi-teacher distillation into a smaller model at cluster scale
- Starting from a recipe that has already converged on known hardware instead of tuning hyperparameters from scratch
How LoongSage compares
LoongSage alongside other open-source rlhf & alignment tools AI/TLDR tracks, ranked by GitHub stars.
| Tool | Stars | What it does |
|---|---|---|
| Heretic | ★ 44k | A command-line tool that removes refusal behaviour from transformer language models by directional ablation, using an Optuna parameter search that co-minimizes refusals and KL divergence from the original model. |
| Open-R1 | ★ 26.5k | An open reproduction of the DeepSeek-R1 reasoning pipeline, with scripts for GRPO training and reasoning-data generation. |
| verl | ★ 24.4k | Volcano Engine's RL post-training framework (HybridFlow) for building GRPO, PPO, and other RL pipelines on top of FSDP, Megatron, and vLLM. |
| TRL | ★ 19.9k | Hugging Face's post-training library with trainers for SFT, reward modeling, DPO, PPO, and GRPO to align language models with preferences. |
| Agent Lightning | ★ 19k | An open-source trainer from Microsoft that improves AI agents built with any framework using reinforcement learning, prompt optimization, and supervised fine-tuning. |
| ART | ★ 10.9k | OpenPipe's Agent Reinforcement Trainer for post-training LLM agents on multi-step tasks using GRPO and rule- or judge-based rewards. |
| OpenRLHF | ★ 10.2k | A Ray- and vLLM-based RLHF framework that scales PPO, GRPO, and REINFORCE++ training to models with 70B+ parameters. |
| LoongSage | ★ 1.1k | Baidu's agentic RL post-training framework on Ray, Megatron-Core and SGLang, with tested recipes |
