Skip to content

Back to the catalog

baidu-baige/LoongSage
github.comrepo

baidu-baige/LoongSage

LoongSage is Baidu's open-sourced, production-grade reinforcement learning framework for post-training LLMs, built on Ray for scheduling, Megatron-Core/Megatron-Bridge for training, and SGLang for inference. It targets agentic RL with a zero-intrusion AgentFlow module (automatic multi-turn context, loss masking, trajectory collection), multi-paradigm online distillation (PG-Style, GKD-Style, TopK/full-vocab/JSD KL), fully asynchronous training with partial rollout, and system-level training-inference consistency guarantees (Router Replay, TITO, M2PO, OPSM) that keep probability bias at 1e-4 in MoE/low-precision settings. Recipes are validated on Baidu's internal production runs of DeepSeek-V4-Flash and Qwen3-30B-A3B for math reasoning, agentic code repair, and distillation.

TL;DR Baidu's open-source agentic RL post-training framework (Ray + Megatron-Core + SGLang) with production-validated recipes for DeepSeek-V4-Flash and Qwen3-30B-A3B.
Document

What it claims

LoongSage is an Apache-2.0 RL post-training framework whose core code is derived from THUDM's slime, with design ideas from verl and Agent-Lightning. Its distinguishing claims beyond the summary:

  • Fully asynchronous training (partial rollout, oversampling, staleness and sliding-window controls) improves throughput by 39%. The page gives this as "in our experiments" and names no baseline, model or hardware.
  • Mixed training across data sources keeps each source's proportion exact on every rank and every mini-batch. Agent, reward, teacher and sampling settings can be set per source.
  • 12 plugin extension points can be added without touching the trunk.

How it works

A single controller orchestrates Ray actors in several roles. Agents talk to the framework only through a standard chat-completion endpoint. AgentFlow then reconstructs multi-turn trajectories, loss masks, and sandbox lifecycle on the framework side. This is how an unmodified black-box agent such as OpenCode is trained.

Weight sync between Megatron and SGLang chooses its transport by placement, and tensors are bucketed into a shared buffer:

flowchart LR
  T[Megatron trainer] --> P{Placement}
  P -->|colocated| I[CUDA IPC zero-copy]
  P -->|cross-node| N[NCCL broadcast]
  I --> S[SGLang engines]
  N --> S

A single flag switches placement between colocated and disaggregated, using Ray Placement Groups. Colocated mode coordinates training and inference VRAM.

The 12 extension points cover:

  • agents, reward models and sandboxes
  • advantage estimation, policy loss and KL
  • routing middleware and data filtering
  • async scheduling, among others

New implementations go in coda/custom/ and are referenced from config.

The consistency stack adds an FP32 output layer and importance-sampling correction alongside R3, TITO, M2PO and OPSM. It is monitored live through train/is_approx_k3_kl, a K3 estimate of the train–inference probability gap.

Evidence

The page shows training curves from single real runs, but its text states no numeric results. The named configs indicate the hardware scale used:

  • DeepSeek-V4-Flash SWE: dsv4_flash_bf16/swe_h20_8node
  • DeepSeek-V4-Flash DAPO: dsv4_flash_bf16/dapo_h20_6node
  • Qwen3-30B-A3B multi-teacher full-vocab distillation (MOPD): qwen3_30b_a3b/mopd_h20_1node
  • Qwen3-Coder-30B-A3B OpenCode agent: qwen3_coder_30b_a3b/opencode_h20_4node

How to use it

Use the container. It pins CUDA, PyTorch, Megatron-Core, Megatron-Bridge, SGLang and Ray, and it applies required SGLang patches.

docker pull loongsage/loongsage:latest
docker run -it --gpus all --ipc=host --network=host \
  -v /path/to/workspace:/root loongsage/loongsage:latest bash

Every task uses one entry point: a Hydra config name under conf/, followed by overrides. Logs go to log/trainer_<timestamp>.log.

bash examples/start.sh <config-name> [key=value ...]

Smallest example, single node with 8 GPUs (H800), Qwen3-4B on DAPO-Math-17k:

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-unique
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-unique

Tests are run with bash build.sh test. Model support follows Megatron-Bridge. Chinese docs are in docs/zh/.

Limits

Listed on the roadmap, meaning not yet supported:

  • PPO, SFT and LoRA
  • low-precision training
  • MTP/DSpark
  • omni-modal support
  • distributed storage for multi-teacher weights
  • multi-data-source and multi-agent training in fully asynchronous mode

The last item means the async speedup and mixed-source training cannot currently be combined.

The project was open-sourced in August 2026. Recipes are tuned for Baidu's H20/H800 setups, and the 39% figure has no stated baseline.

Organisations named here

  • Baidu
  • THUDM
  • DAPO-Math-17k
  • DeepSeek-V4-Flash
  • OpenCode
  • SGLang

Technologies named here

  • DeepSeek V4 Flash
  • LoongSage
  • Qwen3-30B-A3B
  • Ray
  • Qwen3-4B
  • Megatron-Core
  • Qwen3-Coder-30B-A3B
  • Megatron-LM
  • Megatron-Bridge
  • SGLang
  • Slime
  • Verl
  • Agent-Lightning
  • Hydra
  • AgentFlow
  • Docker
  • Qwen3
  • CUDA
  • Hugging Face
  • OpenCode

Techniques named here

  • Zero-Intrusion Agent Access
  • Multi-Paradigm Online Distillation
  • Multi-Data-Source Mixed Training
  • System-Level Training-Inference Consistency Guarantee
  • Fully Asynchronous Training
  • Adaptive Weight Synchronization
  • Flexible Resource Placement
  • Highly Extensible Plugin System