๐งต Slime: The Most Elegant & Comfortable RL Training Framework Ever
A deep dive into why Slime redefines LLM RL training with clean architecture & production-grade engineering โจ
Insights from Zhihu contributor Xavier
๐ What Is Slime In One Sentence?
Slime is a streamlined RL training framework built on SGLang (Inference) + Megatron (Training) + Ray (Orchestration).Itโs not just a simple stackโit stitches top-tier open-source projects together with perfectly polished interfaces.Core design philosophy: Fully decouple training & inference, connected via streamlined data flow.
Compared to veRL / OpenRLHF:
โ
Native SGLang backend โ high concurrency, continuous batching, prefix caching (no messy vLLM wrapper)
โ
Native Megatron backend โ full TP/PP/EP/CP parallelism, seamless MoE training
โ
Lightweight Ray scheduling โ Placement Group + Remote Actor (no bloated Ray Train)
๐๏ธ Global Architecture: 3 Modules, One Pipeline
๐ฅ๏ธ Ray Cluster Core Workflow:Data Buffer (Prompt Manager โ Buffer & Filter)โ๏ธ Rollout (SGLang โ Sampling + RM Scoring + Filtering)โ๏ธ Training (Megatron โ Actor/Critic + PPO/GRPO)
๐ Simplified Core Training Loop
1.Allocate GPU resources via Placement Group
2.Launch SGLang rollout engine
3.Initialize Megatron Actor/Critic models
4.Sync initial weights to SGLang
5.Repeat 3-beat cycle:
Generate (SGLang) โ Train (Megatron) โ Sync Weights
๐ฏElegance = ultra-simple top-level logic, all complexity encapsulated inside modules
๐๏ธ 4 Core Design Flexibilities
โ๏ธ Resource Scheduling: Colocate (shared GPU) / Disaggregate (separate GPU pools)
๐ Training Mode: Synchronous / Asynchronous training
๐งช Sampling Logic: Standard sampling / Over-sampling / Multi-turn tool calling
๐ค Model Type: Dense / MoE, full tensor/pipeline/context parallel support
๐ง Plug & Play Customization (All Extensible)
Slime lets you customize every component via CLI paramsโno need to fork the repo ๐ ๏ธ
Key Customization Points
โ
Custom Reward Model: Write an async func to define your own reward logic (easiest entry)
โ
Custom Generate Func: Control multi-turn dialogue, tool calling & external API integration
โ
Custom Rollout Func: Fully take over sampling concurrency & filtering logic
โ
Custom DataSource: Fetch prompts from API / local files / dynamic data streams
โ
Dynamic Filter: Discard low-value sample groups (e.g., zero-variance GRPO samples)
โ
Custom Loss Function: Rewrite PPO/GRPO loss calculation freely
All custom code loads dynamically via --custom-xxx-path config ๐
๐ Ray GPU Scheduling Magic
Two deployment modes for all cluster scales:
๐น Colocate Mode: Train & inference share GPUs โ high utilization, ideal for small 8-card servers
๐น Disaggregate Mode: Independent GPU pools โ train-infer overlap, perfect for multi-node clusters
Slime stabilizes Ray Placement Group GPU mapping via IP/GPU ID sorting to guarantee reproducibility ๐
โก SGLang Rollout Engine Internals
3-layer abstraction:RolloutManager โ RolloutServer โ ServerGroup โ SGLangEngine
Standout design highlights:
๐ธ Over-sampling + Dynamic Filter: Pre-sample extra data, filter invalid groups on the fly
๐ธ Async Concurrent Sampling: Process completed groups immediately with FIRST_COMPLETED
๐ธ Abort Mechanism: Stop redundant sampling once target data size is met, save compute
๐ธ Singleton GenerateState: One-time tokenizer & connection initialization
๐ง Megatron Training Backend
Native support for mainstream RL algorithms:
โ
GRPO: No Critic needed, group-wise reward normalization (most popular)
โ
PPO: Classic Actor-Critic with GAE advantage estimation
โ
REINFORCE++: Token-level baseline optimization
Seamless support for Dense & large MoE models with full parallelism ๐
๐ Weight Sync: The Hard Engineering Solved
Two high-performance sync paths:
๐น Colocate: IPC + Gloo โ intra-node low-latency weight transfer
๐น Disaggregate: NCCL Broadcast โ cross-node distributed sync
MoE OOM prevention: Chunked Bucket Weight Update โ sync parameters in small batches, release memory instantly ๐งฉ
๐ก Core Takeaways
โจ Slimeโs elegance lies in integrating mature top-tier stacks with clean decoupled design
โจ Minimal top-level logic, maximal internal engineering depth
โจ Fully pluggable customization for all RL scenarios (Math / Code / Agent / MoE)
โจ Optimized for both small single-node & large multi-node clusters
๐Full article๏ผ
#
LLM# #
RLTraining# #
SGLang# #
AIInfrastructure# #
MoE# #
MachineLearning#