MCPcopy Index your code
hub / github.com/RL-Align/RL-Kernel

github.com/RL-Align/RL-Kernel @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
1,486 symbols 5,984 edges 119 files 303 documented · 20%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

RL-Kernel Logo

RL-Kernel

Extreme Infrastructure for GRPO & Large-Scale Reinforcement Learning.

Documentation Discord WeChat WhatsApp Ask DeepWiki Hardware License

RL-Kernel is a high-performance, memory-efficient infrastructure for Reinforcement Learning post-training. It eliminates the memory and latency bottlenecks in Large Language Model alignment, This project targets AI infrastructure engineers, algorithm researchers, and enterprise-level large model alignment scenarios, providing specialized kernels for algorithms like GRPO, PPO, and DPO.


Our Core Philosophy

1. Operator-Level Train-Inference Consistency The biggest hidden barrier in large-scale RL is the subtle numerical divergence between rollout engines (e.g., vLLM) and training engines (e.g., Megatron/DeepSpeed). RL-Kernel provides mathematically rigorous, fused operators that lock down the computational graph. By guaranteeing absolute numerical consistency and deterministic reduction orders across the entire RL loop, we prevent reward hacking and distribution drift at the operator level.

2. Extreme Memory & Compute Efficiency We replace naive PyTorch paths—which suffer from $O(G \cdot L \cdot V)$ memory explosion—with specialized industrial-grade kernels (like prefix_shared_attention and fused_logp). This reduces VRAM consumption by up to 10x, unlocking massive batch sizes for GRPO workloads without triggering Out-Of-Memory (OOM) errors.


Global Architecture

RL-Kernel sits strictly at the operator layer, acting as a non-intrusive bridge between high-level alignment orchestration (e.g., vime, slime) and foundational execution engines. We ensure maximum throughput and rigorous numerical parity without modifying upstream framework source code.

RL-Kernel Global Architecture

Note: RL-Kernel integrates natively into Rollout Engines (vLLM, sglang, LMDeploy) and Training Engines (Megatron, DeepSpeed) via non-intrusive custom operator hooks, powered by underlying CUDA, Triton, and ROCm backends.


Performance Benchmarks: Breaking the Memory Wall

RL-Kernel is designed to solve the $O(G \cdot L \cdot V)$ memory explosion in DeepSeek-style GRPO training. A typical scenario is as follows:

1. Logprob Computation (Training Stability)

By implementing Pre-allocated Chunking, RL-Kernel maintains constant additional VRAM overhead regardless of the group size ($G$).

Testbed: NVIDIA A100 80GB | Model: Llama-3-8B | Vocab: 128,256 | SeqLen: 512

Group Size ($G$) TRL (Standard) PyTorch Native RL-Kernel (Ours) Status
G = 64 OOM 15.66 GB 16.15 GB Success
G = 128 OOM 31.31 GB 31.80 GB Success
G = 256 FAILED (OOM) 62.63 GB 63.12 GB Optimized

Note: RL-Kernel is the only solution that successfully scales G=256 on a single A100 by keeping extra VRAM usage to a constant ~0.5GB.

Logprob VRAM Benchmark

2. Sampling Latency (Rollout Speed)

Integrating FlashInfer fused kernels to accelerate the bottleneck of RL training: the sampling phase.

Batch Size ($G$) Native PyTorch RL-Kernel (Fused) Speedup
32 176.79 ms 1.08 ms 163x
64 10.54 ms 1.31 ms 8x
128 18.89 ms 1.86 ms 10x
256 36.23 ms 2.94 ms 12x

Sampling Latency Benchmark

3. Real Model Validation (Qwen3-30B-A3B MoE)

Testbed: NVIDIA A100 80GB | Model: Qwen3-30B-A3B | Vocab: 151,936 | dtype: fp16

Model weights consume 56.9 GB — only 23 GB headroom remaining for training computation.

Real Model MoE Benchmark

Key Features

  • Zero-Growth Memory Pool: Uses pre-allocated buffers and micro-chunking to prevent VRAM spikes during advantage calculation.
  • Fused Sampling Pipeline: Direct integration with FlashInfer and vLLM backends for sub-2ms sampling latency.
  • Universal Backend Abstraction: Unified API supporting both NVIDIA (CUDA/FlashInfer) and AMD (ROCm/AITER).
  • Post-Training Ready: Drop-in replacement for standard sampling and logprob operators in TRL or DeepSpeed-Chat.

Architecture

RL-Kernel sits between high-level alignment libraries and low-level GPU kernels, ensuring maximum throughput without sacrificing flexibility.


Quick Start

Installation

# Clone the repository
git clone https://github.com/RL-Align/RL-Kernel.git
cd RL-Kernel

# Install core dependencies (CUDA 12.4+ recommended)
pip install -e .

Contributions

Inspired by the kernel designs of vLLM and DeepSpeed. As an active contributor to the AI Infrastructure ecosystem, RL-Kernel aims to push the boundaries of RL efficiency.

Target: Building the most efficient RLHF toolchain for the open-source community.

Support

Don’t hesitate to ask!

Contact the developers and community on the Discord if you need any help.

Open an issue if you find a bug in RL-Kernel.

Documentation

The documentation of RL-Kernel is located on the website: https://rl-align.github.io/RL-Kernel or in the docs directory of the source code.

Acknowledgments

RL-Kernel builds on the shoulders of excellent open-source projects:

  • FlashInfer — We integrate FlashInfer's fused sampling kernels as the NVIDIA backend for our sampling pipeline. The sub-2ms sampling latency results are enabled by FlashInfer's highly optimized CUDA operators.
  • vLLM — Inspired by vLLM's kernel design philosophy and hardware-aware scheduling approach.
  • DeepSpeed — Inspired by DeepSpeed's approach to memory-efficient training infrastructure.

We are grateful to these teams for their contributions to the open-source AI infrastructure ecosystem.

Core symbols most depended-on inside this repo

publish
called by 30
rl_engine/executors/bridge.py
get_op
called by 29
rl_engine/kernels/registry.py
forward_fp32
called by 26
rl_engine/kernels/ops/pytorch/loss/logp.py
selected_logprobs_reference
called by 26
rl_engine/testing/reference_ops.py
import_update
called by 25
rl_engine/executors/bridge.py
forward_fp32
called by 23
rl_engine/kernels/ops/pytorch/rotary_embedding/rope.py
_floating_tensor
called by 22
rl_engine/kernels/gtest/operator_inputs.py
state_dict
called by 19
rl_engine/executors/deepspeed_trainer.py

Shape

Function 788
Method 502
Class 193
Route 3

Languages

Python100%
C++1%

Modules by API surface

rl_engine/executors/bridge.py150 symbols
tests/test_weight_sync_bridge.py73 symbols
rl_engine/executors/training_contract.py46 symbols
tests/test_deepspeed_training_worker.py43 symbols
rl_engine/executors/deepspeed_trainer.py42 symbols
tests/test_ray_actor_manager.py41 symbols
tests/test_linear_logp.py37 symbols
benchmarks/profiler.py37 symbols
rl_engine/executors/ray_actor_manager.py35 symbols
rl_engine/executors/stateless_executor.py34 symbols
tests/test_stateless_executor.py31 symbols
rl_engine/kernels/ops/cuda/loss/logp.py29 symbols

For agents

$ claude mcp add RL-Kernel \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact