百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
K

KernelGYM

> 编程语言
开源

[KernelGYM & Dr. Kernel] 一个分布式 GPU 环境和一系列 RL 训练方法,用于支持 Kernel 世代的 RL [ICML 2026]

199 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

[KernelGYM & Dr. Kernel] 一个分布式 GPU 环境和一系列 RL 训练方法,用于支持 Kernel 世代的 RL [ICML 2026]

KernelGYM: A Gym for Kernel Generations

KernelGYM is a GPU-distributed environment designed for evaluating and training AI models on GPU kernel generation tasks. This repository also includes our validated RL training methods from our paper:

Dr.Kernel: Reinforcement Learning Done Right for Triton Kernel Generations

See drkernel/ for training implementation details and recipe.

What Can You Do with KernelGYM?

  • Long-Horizon RL Training - Train kernel generation models with multi-turn rollouts, reward hacking detection, and detailed profiling metrics
  • Agentic Trajectory Collection - Collect high-quality training data from agent interactions with the kernel evaluation environment
  • Large-Scale Kernel Optimization - Deploy your own agents to optimize kernel implementations across thousands of tasks in parallel
  • Parallel Kernel Evaluation - Evaluate kernel correctness and performance across distributed GPU clusters with automatic error recovery
  • Extend to New GPU Tasks - Build on our abstractions to support custom GPU workloads beyond kernel generation (physics simulation, rendering, etc.)

Table of Contents

  • Overview
  • Key Challenges & Highlights
  • Architecture
  • Installation
  • Quick Start
    • Fastest Path (Single Node)
    • Single-Node Deployment
    • Multi-Node Distributed Deployment
  • Usage Examples
    • Example 1: Kernel Simple Task
    • Example 2: KernelBench Evaluation
  • Supported Backends & Toolkits
  • Extending KernelGYM
    • Adding New GPU Tasks
    • Tutorial: Kernel Simple as Extension Example
  • Training Recipe
  • API Reference

Overview

Training AI models to generate optimized GPU kernels presents unique challenges that standard code generation environments cannot address. KernelGYM provides:

  • GPU-Distributed Task Scheduling: Efficiently manage and distribute kernel evaluation tasks across multiple GPUs and nodes
  • Subprocess Isolation: CUDA error isolation through subprocess worker pools prevents GPU crashes from affecting the main evaluation pipeline
  • Multi-Backend Support: Evaluate kernels written in CUDA, Triton, and other frameworks
  • RL Training Integration: Seamlessly integrate with RL training pipelines (VERL framework) for reward computation
  • Extensible Architecture: Abstract interfaces for backends, toolkits, and workflows enable easy extension to new GPU tasks

Key Challenges & Highlights

Challenges in Kernel Generation Evaluation

  1. GPU Resource Management: Unlike CPU-bound code execution, kernel evaluation requires careful GPU memory management and device isolation. A single CUDA error can crash an entire evaluation pipeline.

  2. Performance Measurement Complexity: Accurate kernel timing requires proper warmup, multiple trials, and CUDA event synchronization - not just wall-clock timing.

  3. Correctness Verification: Kernels must produce numerically correct results within floating-point tolerances, requiring reference implementations for comparison.

  4. Scalability: Training requires evaluating thousands of kernel samples per batch, necessitating distributed evaluation across multiple GPUs and nodes.

KernelGYM's Solutions

  • Subprocess Worker Pool: Each GPU worker maintains a pool of subprocess workers. CUDA errors are isolated to subprocesses and automatically recovered, preventing cascading failures.

  • Precise Timing Infrastructure: Built-in CUDA event-based timing with configurable warmup and trial counts ensures accurate performance measurements.

  • Flexible Correctness Checking: Support for custom tolerance levels (rtol/atol), multiple test cases, and decoy kernel detection.

  • Horizontal Scalability: Redis-based task queue enables seamless scaling from single-GPU to multi-node deployments.

Architecture

High-level architecture of KernelGYM: API server + task manager + distributed GPU workers with subprocess isolation.

…

Core Components

Component Description
Backend Handles kernel compilation, loading, and execution. Abstracts different kernel frameworks (CUDA, Triton).
Toolkit Implements evaluation logic - correctness checking, performance measurement, profiling.
Workflow Controller Orchestrates multi-step evaluation workflows (e.g., reference timing + kernel evaluation).
Task Manager Redis-based queue management with priority scheduling and worker assignment.
GPU Worker Manages task execution on a specific GPU with subprocess isolation for error recovery.

Installation

Prerequisites

  • Python 3.10+
  • CUDA 11.8+ with compatible GPU
  • Redis server
  • Linux (Ubuntu 20.04+ recommended)

Setup

bash
# Clone the repository
git clone https://github.com/hkust-nlp/KernelGYM.git
cd kernelgym

# Run the setup script
bash setup.sh

The setup script will:

  1. Install Python dependencies from requirements.txt
  2. Install additional packages (pydantic-settings)
  3. Install system utilities (iproute2)
  4. Install Redis for local deployment

Configuration

You have two options:

  1. Recommended: let KernelGYM auto-generate .env on first startup.
  2. Manual: create .env yourself with explicit values.

Manual .env example:

bash
# Redis Configuration
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=  # Optional

# API Server Configuration
API_HOST=0.0.0.0
API_PORT=10907

# GPU Configuration
GPU_DEVICES=[0,1,2,3,4,5,6,7]  # List of GPU indices to use

# Optional: Node identification for multi-node setup
NODE_ID=node-1

Quick Start

Fastest Path (Single Node)

If your goal is to get a local KernelGYM service up quickly:

bash
# 1) Install dependencies
bash setup.sh

# 2) Auto-configure .env (or skip; start script can do this automatically)
bash scripts/auto_configure.sh

# 3) Start API + workers
./start_all_with_monitor.sh

# 4) Verify service
curl http://localhost:10907/health
curl http://localhost:10907/workers/status

scripts/auto_configure.sh includes a practical example strategy for fast setup:

  • Detect host/IP and GPU list
  • Find available ports for Redis/API/Metrics from candidate port pools

Treat this as a reference implementation, not a fixed policy. If your machine or cluster has different networking constraints, edit the port-selection logic in scripts/auto_configure.sh (for example, custom port ranges, reserved ports, or service-specific pinning) to match your environment.

Single-Node Deployment

For single-node deployments with all components on one machine:

bash
# Start the API server and workers
./start_all_with_monitor.sh

This script starts:

  • The FastAPI server on the configured port
  • GPU workers for each configured device
  • A monitoring process for worker health checks

Notes:

  • If .env does not exist, start_all_with_monitor.sh triggers scripts/auto_configure.sh.
  • If Redis is configured as local (localhost/127.0.0.1) and not running, the startup script launches Redis automatically.

Multi-Node Distributed Deployment

For distributed setups across multiple machines:

On the main node (API server + Redis):

bash
# Ensure Redis is accessible from worker nodes
redis-server --bind 0.0.0.0

# Start API server
python -m kernelgym.server.api.server

On worker nodes:

  1. Create a .env file pointing to the main node:
bash
API_HOST=
API_PORT=10907
REDIS_HOST=
REDIS_PORT=6379
NODE_ID=worker-node-1  # Unique identifier for this node
GPU_DEVICES=[0,1,2,3]  # GPUs available on this node
  1. Start the worker:
bash
./start_worker_multinode.sh

The worker will:

  1. Connect to the main node's API server
  2. Register itself and allocate a node ID
  3. Start GPU workers that pull tasks from the shared Redis queue

Deployment Scripts Reference

For more details on deployment configuration and options, refer to these scripts:

Script Description
scripts/auto_configure.sh Auto-generates .env configuration with detected IP, available ports, and GPU devices
start_all_with_monitor.sh Single-node deployment: starts Redis, API server, worker monitor, and GPU workers
start_worker_multinode.sh Multi-node worker startup: connects worker nodes to remote API/Redis server

Useful auto_configure.sh options:

  • bash scripts/auto_configure.sh --force to overwrite existing .env
  • bash scripts/auto_configure.sh --use-indexed-ports to use PORT0, PORT1, ... as candidates

Usage Examples

Example 1: Kernel Simple Task

The kernel_simple workflow evaluates a standalone kernel with provided test cases:

…

Example 2: KernelBench Evaluation

The kernelbench workflow compares a generated kernel against a reference implementation:

…

Supported Backends & Toolkits

Backends

Backend Description Use Case
kernelbench Full KernelBench evaluation backend Reference-based kernel evaluation with CUDA/Triton support

The KernelBench backend supports two sub-backends:

  • CUDA: For kernels using PyTorch's CUDA extensions or inline CUDA code
  • Triton: For kernels using OpenAI's Triton language

KernelBench evaluation also supports two execution modes:

  • Eager Mode: Direct execution without compilation optimization (default)
  • Compile Mode: Uses torch.compile() for optimized execution and fair comparison with compiled references

To select execution mode, use the reference_backend parameter:

python
# Eager mode (default) - compare against eager PyTorch reference
payload = {
    "backend": "triton",
    "reference_backend": "pytorch",  # or omit for default
    # ...
}

# Compile mode - compare against torch.compile() optimized reference
payload = {
    "backend": "triton",
    "reference_backend": "compile",
    # ...
}

Toolkits

Toolkit Description Workflow
kernelbench Full evaluation with reference comparison kernelbench
kernel_simple Standalone kernel evaluation with test cases kernel_simple

Using Different Backends

python
# For Triton kernels
payload = {
    "backend": "triton",
    # ...
}

# For CUDA kernels
payload = {
    "backend": "cuda",
    # ...
}

Extending KernelGYM

KernelGYM is designed to be extensible. You can add new GPU tasks by implementing the core abstractions.

Adding New GPU Tasks

To add support for a new type of GPU task, implement these components:

1. Define a Backend (if needed)

…

Register your backend:

python
from kernelgym.backend import register_backend
register_backend("my_backend", MyBackend)

2. Define a Toolkit

…

Register your toolkit:

python
from kernelgym.toolkit import register_toolkit
register_toolkit("my_toolkit", MyToolkit)

3. Define a Workflow Controller (optional)

…

Tutorial: Kernel Simple as Extension Example

The kernel_simple module demonstrates how to extend KernelGYM for custom evaluation logic. Here's how it's structured:

1. Schema Definition (kernelgym/schema/simple_task.py):

python
@dataclass
class KernelSimpleTask:
    task_id: str
    kernel_code: str
    entry_point: str = "ModelNew"
    device: str = "cuda:0"
    backend: str = "triton"
    cases: Optional[List[Dict]] = None  # Test cases

Issues· 5 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Python

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言