LightRFT

opendilabApache-2.0活跃维护

轻量高效的全模态强化微调框架,支持 GRPO、DAPO 等算法,用奖励模型驱动 LLM 和多模态 VLM 训练。

LightRFT: Light, Efficient, Omni-modal & Reward-model Driven Reinforcement Fine-Tuning Framework

v0.1.1发布于 2026-01-23 07:02 UTC379star12fork同步于 2026-11-07 07:31 UTC

怎么上手

由 README 提炼,执行前请确认
git clone https://github.com/opendilab/LightRFT.git
cd LightRFT
pip install -e .
硬件要求按 README 说明

分布式训练需要支持 CUDA 的 NVIDIA GPU 环境;README 未给出具体显存要求,示例启动脚本按单机 8 卡模板配置。

需要 CUDA多卡 / 张量并行有 Docker 镜像
下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

面向 LLM 与多模态模型的强化微调框架,统一训练与 rollout 后端,覆盖 RLVR、RLHF 与奖励模型驱动优化

轻量高效的全模态强化微调框架,支持 GRPO、DAPO 等算法,用奖励模型驱动 LLM 和多模态 VLM 训练。

核心能力

  • 用统一 Strategy 接口对接 FSDP v2、DeepSpeed 与 SGLang、vLLM 后端
  • 训练与 rollout 分阶段复用同一组 GPU,rollout 引擎可休眠
  • 支持 GRPO、DAPO、Dr.GRPO、REINFORCE++、CPGD 等算法
  • 支持 LoRA、视觉前缀冻结、样本打包与梯度检查点
  • 内置奖励模型训练与 on-policy 蒸馏工作流

容易踩的坑

Python 需 >=3.12、PyTorch 需 >=2.9.1,且 CUDA、FlashAttention、SGLang、vLLM 存在二进制兼容约束,需按驱动选版本;示例启动脚本是 8 卡模板,减少 GPU 数时要同步调整张量并行、batch size 与序列长度;运行前需先跑数据预处理脚本生成数据集,并修改脚本里的模型与数据路径。

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

2 个版本v0.1.1
  1. v0.1.1v0.1.1 Release最新正式版2026-01-23 · 2026-01-23 07:02 UTC

    This release expands LightRFT into the video domain, optimizes evaluation pipelines for reward models, and ensures compatibility with the latest upstream inference and training libraries (specifically sglang).

    ✨ Multimodal & Advanced Training

    • Video Support: Expanded multimodal capabilities with the addition of Video reinforcement fine-tuning (#4).
    • Enhanced Evaluation: Implemented and optimized evaluation logic for SRM (Step-wise Reward Model) and GRM (Generative Reward Model) trainers.
    • Exploration: Added a high entropy token selection mechanism to improve generation diversity during training (#6).

    📊 Benchmarks & Metrics

    • New Eval Datasets: Added support for AIME24/25 and GPQA Diamond evaluations (#27), facilitating stronger reasoning capability assessment.
    • Trajectory Metrics: Added comprehensive analysis metrics to saved trajectories for deeper insight into training dynamics (#5).
    • T2I Benchmarks: Updated GRM on T2I (Text-to-Image) benchmark results and analysis in best practices.

    ⚙️ Core Optimization & Compatibility

    • Library Updates: Adapted framework to support the latest versions of sglang (#24) and ensured compatibility with upstream ecosystem updates.
    • Transformers Compatibility: Standardized configuration by renaming dtype to torch_dtype for seamless integration with Hugging Face Transformers.
    • Code Polish: Removed redundant tuple nesting in prepare_reward_model return values and polished return logic.

    🐛 Bug Fixes

    • Video Metadata: Resolved compatibility bugs related to video metadata handling (#25).
    • GRM Formatting: Fixed bugs in GRM dataset message formatting and evaluation logic.
    • General Fixes: Fixed file path handling bugs and resolved various linting/style issues (flake8, yapf).

    📚 Documentation & Community

    • Community Health: Added standard Issue and PR templates to streamline contributions (#20).
    • Docs Automation: Established automated documentation deployment actions (#18).
    • API Docs: Polished API docstrings and Python typing for better developer experience (#21).

    Full Changelog: https://github.com/opendilab/LightRFT/compare/v0.1.0...v0.1.1

    Contributors: OpenDILab, System Platform Center and Safe and Trustworthy AI Center at Shanghai AI Laboratory.

  2. v0.1.0v0.1.0: Initial Release2025-12-31 · 2025-12-31 04:50 UTC
    查看更新说明

    This is the initial release of LightRFT, a light, efficient, omni-modal & reward-model driven reinforcement fine-tuning framework.

    🧠 Rich Algorithm Ecosystem

    • Implemented PPO and GRPO algorithms for Large Language Models.
    • Added comprehensive interfaces for Reward Model training and inference.

    🎯 Innovative Resource Collaboration

    • Introduced "Colocate Anything" strategy to maximize GPU memory efficiency by colocating Actor, Critic, and Reward models.

    🔧 Flexible Training Strategies

    • Integrated DeepSpeed ZeRO and FSDP for scalable distributed training.
    • Added PEFT (LoRA) integration for lightweight fine-tuning.

    🌐 Environments & Models

    • Added support for GSM8K (Math reasoning) and Geo3K (Multimodal) environments and datasets.
    • Enabled support for Qwen and DeepSeek model families.

    📚 Documentation & Toolkit

    • Integrated Weights & Biases (W&B) for training metric logging.
    • Released initial Quick Start guide, architecture overview, and reproduction scripts.

    Full Changelog: https://github.com/opendilab/LightRFT/commits/v0.1.0

    Contributors: OpenDILab, System Platform Center and Safe and Trustworthy AI Center at Shanghai AI Laboratory.

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    LightRFT

    Light, Efficient, Omni-modal & Reward-model Driven Reinforcement Fine-Tuning Framework

    Version Python PyTorch License

    English | 简体中文

    Overview

    LightRFT (Light Reinforcement Fine-Tuning) is a reinforcement fine-tuning framework for large language models (LLMs) and vision-language or multimodal generative models (VLMs). It provides a structured and extensible workflow for reinforcement learning with verifiable rewards (RLVR), reinforcement learning from human feedback (RLHF), and model-reward-driven policy optimization, covering policy sampling, reward computation, advantage estimation, and policy updates. The repository also includes reward-model training and on-policy distillation workflows.

    LightRFT uses torchrun and PyTorch distributed communication as its runtime foundation. A unified Strategy interface connects FSDP v2 and DeepSpeed ZeRO training backends with SGLang and vLLM rollout backends. Current code paths and examples include text, image, video, and audio tasks. “Omni-modal” means that the repository contains dedicated model, data, or example paths for these modalities; it does not imply that every model and modality combination works without adaptation.

    This document describes repository version 0.1.1. Source code and runnable examples define the implemented feature boundary; roadmap items are not treated as released features.

    Contents

    Design highlights

    Unified Strategy abstraction and training–rollout loop

    • A common interface connects DeepSpeed/FSDP v2 training backends with SGLang/vLLM rollout backends, reducing backend-specific coupling in the upper-level training workflow.
    • Distributed jobs follow a single-program, multiple-data (SPMD) topology launched with torchrun; Ray is not required for scheduling, and standard PyTorch distributed tools remain applicable for debugging.
    • Training and rollout reuse the same GPU process set by phase. The rollout engine can sleep during policy updates and receives refreshed Actor weights before the next rollout.

    LightRFT calls this logical colocation and phase-oriented resource sharing model Colocate Anything. See Runtime Architecture and Resource Reuse for Strategy boundaries, evaluation flow, model placement, and weight synchronization.

    Distributed and parameter-efficient training

    • FSDP v2 and DeepSpeed ZeRO stages 1/2/3; DeepSpeed is selected when --fsdp is absent.
    • BF16, gradient checkpointing, Adam offload, and FSDP CPU offload.
    • LoRA, visual-prefix freezing, and sample packing.
    • Optional FlashAttention 2 and a fused log-probability path.

    Reward-model-driven optimization

    • Rule rewards, custom reward functions, local reward models, and remote reward services.
    • Multiple reward sources with task-specific aggregation.
    • Training entry points for vision scalar reward models (SRM), vision generative reward models (GRM), and audio SRMs.
    • On-policy distillation (OPD) with teacher log-probabilities, either as a distillation-only objective or combined with task rewards.

    Multimodal task paths

    • Text (ActorLanguage), vision-language (ActorVL), and audio-language (ActorAL) policy paths.
    • Image inputs are handled by the vision-language path; the experience-generation path also handles video fields.
    • Examples cover GSM8K text reasoning, Geo3K visual geometry reasoning, video reward-model RL, and audio question answering.

    Experiment tooling

    • Weights & Biases and TensorBoard logging.
    • Trajectory saving and analysis for repetition, reflection patterns, and policy entropy.
    • High-entropy-token annotation and local visualization.
    • Distributed checkpoints, optional Hugging Face checkpoints, and conversion utilities.

    Supported algorithm matrix

    LightRFT organizes policy optimization, advantage estimation, sampling, and knowledge distillation as composable modules. See the algorithm guide for principles and detailed configuration.

    AlgorithmTypeMain improvementCurrent implementation and entry pointReference
    GRPOPolicy OptimizationGroup-normalized advantage estimationSupported: use --advantage_estimator group_norm; requires multiple responses per promptarXiv:2402.03300
    GSPO (WIP)Policy OptimizationGroup sequence policy optimizationExperimental interface: --use_gspo and related options are available while integration is in progressarXiv:2507.18071
    GMPO (WIP)Policy OptimizationGeometric-mean policy optimizationIn development: the end-to-end training path is being completedarXiv:2507.20673
    Dr.GRPOPolicy OptimizationMitigation of length biasSupported: unbiased group-relative optimization reduces length bias and improves token efficiencyarXiv:2503.20783
    REINFORCE++Advantage EstimationImproved baseline estimationSupported: use --advantage_estimator reinforce++ for return and advantage estimationarXiv:2501.03262
    DAPOPolicy OptimizationDecoupled clipping and dynamic samplingSupported: includes --dynamic_sampling, --overlong_buffer, and related training mechanismsarXiv:2503.14476
    CPGDAdvantage EstimationKL-drift constraintSupported: use --advantage_estimator cpgd; --use_cpg_loss enables asymmetric clippingarXiv:2505.12504
    FIRE SamplingSampling StrategyHigh-temperature first-token sampling for greater diversitySupported: configure with --use_fire and --first_token_temperaturearXiv:2410.21236
    OPDKnowledge DistillationOn-policy teacher–student token-level distillationSupported: reads teacher log-probabilities from --teacher_model_url and supports pure or task-reward-hybrid distillationBlog

    The main training entry point, examples/gsm8k_geo3k/train_colocate.py, also provides the following foundational training paths:

    Method--advantage_estimatorCriticDescription
    PPO / GAEgaeRequiredComputes GAE from value estimates and trains with a value loss
    REINFORCEreinforceNoBuilds token-level returns from sequence rewards
    RLOOrlooNoUses a leave-one-out group baseline and requires multiple responses per prompt
    REINFORCE with baselinereinforce_baselineNoUses the group mean as the baseline without standard-deviation scaling

    These training paths can be combined with the following stability and efficiency mechanisms:

    • Sample filtering and length control: --dynamic_sampling masks groups with no reward variation, while --overlong_buffer adds a length-dependent penalty to overlong responses.
    • Token-level updates: --high_entropy_token_ratio restricts policy-gradient updates to a selected fraction of high-entropy tokens; 0.0 disables filtering.
    • Numerical stability: --reward_running_norm, --reward_clip, --advantages_norm, and --advantage_clip control reward normalization, reward clipping, advantage whitening, and advantage clipping.

    Implementation status: All algorithms in the matrix are supported except GSPO and GMPO, which remain WIP. WIP entries expose their corresponding designs or experimental interfaces but are not complete training paths in the current release.

    Runtime architecture

    A typical LightRFT training cycle is:

    data preparation → rollout generation → reward and experience construction
                     → advantage estimation and policy update → weight synchronization
    

    The Trainer organizes the iteration, Strategy provides the distributed training and rollout interfaces, and reward components evaluate generated responses. The relationships among Actor, Reference Model, Critic, and rollout policy—and the exact sequence of engine sleep/wake, model reload/offload, and weight synchronization—are documented in Runtime Architecture and Resource Reuse.

    Installation

    Requirements

    ComponentSource installation requirement or note
    Python>= 3.12
    PyTorch>= 2.9.1 in pyproject.toml
    GPUDistributed training requires a CUDA-capable NVIDIA GPU environment
    Default rollout backendSGLang >= 0.5.6.post2
    Optional rollout backendvLLM >= 0.18.1
    Training backendDeepSpeed >= 0.18.3, or PyTorch FSDP v2

    CUDA, PyTorch, FlashAttention, SGLang, and vLLM have binary compatibility constraints. Select versions compatible with the installed driver and CUDA runtime; the repository Dockerfile is one pinned reference environment.

    Source installation

    SGLang is included in the default dependency set:

    git clone https://github.com/opendilab/LightRFT.git
    cd LightRFT
    pip install -e .
    

    Install the optional vLLM backend with:

    pip install -e ".[vllm]"
    

    Alternatively, install a compatible vLLM release after the default installation:

    pip install "vllm>=0.18.1"
    

    Docker

    Running a GPU container requires Docker and NVIDIA Container Toolkit. The published example image is version v0.1.0:

    docker pull opendilab/lightrft:v0.1.0
    docker run --gpus all -it --rm \
      --ipc=host \
      -v /path/to/data:/app/data \
      -v /path/to/checkpoints:/app/checkpoints \
      opendilab/lightrft:v0.1.0 /bin/bash
    

    Build the repository Dockerfile with:

    make dbuild
    make dbuild IMAGE_NAME=your-custom-tag:latest
    

    The current Dockerfile starts from nvcr.io/nvidia/pytorch:25.01-py3 and explicitly installs a PyTorch 2.9.0 CUDA 12.8 wheel, DeepSpeed 0.18.3, vLLM 0.18.1, FlashAttention 2.8.3, and SGLang 0.5.6.post2. Its PyTorch version is lower than the >=2.9.1 source-package declaration. Verify the intended version set before treating the Dockerfile as a release reference.

    FlashAttention installation

    If a FlashAttention source build fails, select a wheel that exactly matches Python, PyTorch, CUDA, and the C++ ABI. For example, the repository Docker environment uses:

    pip install flash_attn-2.8.3+cu12torch2.9cxx11abiTRUE-cp312-cp312-linux_x86_64.whl
    

    When no matching wheel is available, build from source in an environment with the required compiler toolchain. See the installation guide and troubleshooting guide.

    Quick start

    The launchers in this repository are training templates. Before running them, review model and dataset paths, GPU count, rollout tensor parallelism, sequence lengths, batch sizes, and logging configuration.

    GSM8K with GRPO

    The example uses Qwen2.5-0.5B-Instruct, GSM8K, group-normalized advantages, and rule rewards.

    1. Prepare the dataset
    python examples/gsm8k_geo3k/data_preprocess/gsm8k.py \
      --local_save_dir /path/to/data/gsm8k
    

    The preprocessing script reads openai/gsm8k and writes training and test Parquet files. Each example contains the prompt, reference answer, and the gsm8k_rule reward label; the training recipe uses answer-correctness and output-format rules rather than a neural reward model.

    2. Review the launcher

    Edit examples/gsm8k_geo3k/run_grpo_gsm8k_qwen2.5_0.5b.sh and verify at least:

    PATH_TO_YOUR_BASE_MODEL="Qwen/Qwen2.5-0.5B-Instruct"
    PATH_TO_YOUR_GSM8K_DATASET="/path/to/data/gsm8k"
    
    export NNODES=1
    export GPUS_PER_NODE=8
    ENGINE_TP=2
    

    Also review W&B credentials, master address/port, batch sizes, and sequence lengths. ENGINE_TP must divide the total process count.

    If W&B is not required, leave WANDB_API_KEY empty and remove or adjust the corresponding launcher options. Multi-node execution also requires correct NODE_RANK, MASTER_ADDR, and MASTER_PORT values.

    3. Launch
    # Default SGLang backend
    ENGINE_TYPE=sglang \
      bash examples/gsm8k_geo3k/run_grpo_gsm8k_qwen2.5_0.5b.sh
    
    # Optional vLLM backend
    ENGINE_TYPE=vllm \
      bash examples/gsm8k_geo3k/run_grpo_gsm8k_qwen2.5_0.5b.sh
    

    The launcher uses torchrun to start train_colocate.py; its default recipe enables FSDP, BF16, FlashAttention, engine sleep/wake, rule rewards, and group-normalized advantages. It is an eight-GPU template. When reducing GPU count, also adjust tensor parallelism, global and micro batch sizes, sequence lengths, or model size.

    Geo3K visual reasoning

    Prepare Geo3K, review the model and dataset paths in the launcher, and then run:

    python examples/gsm8k_geo3k/data_preprocess/geo3k.py \
      --local_save_dir /path/to/data/geo3k
    
    ENGINE_TYPE=sglang \
      bash examples/gsm8k_geo3k/run_grpo_geo3k_qwen2.5_vl_7b.sh
    

    See the GSM8K/Geo3K tutorial for the complete workflow.

    Configuration

    Model, data, algorithm, distributed-backend, rollout-engine, logging, and checkpoint options are organized in the configuration guide. Entry points do not necessarily expose identical arguments, so also inspect the selected launcher and its command-line help:

    python examples/gsm8k_geo3k/train_colocate.py --help
    

    For reproducible experiments, use launchers, documentation, and argument parsers from the same repository revision, and treat the selected entry point's --help and source implementation as authoritative.

    Examples and applications

    DirectoryModality or taskPurpose
    examples/gsm8k_geo3k/Text and imageGRPO, PPO, LoRA, and rule-reward training
    examples/orm_rl_demo/ImageCombined format, general model, and accuracy rewards
    examples/grm_training/Image/video rewardVision GRM training
    examples/grm_vl_rl/VideoPolicy optimization with a vision reward model
    examples/srm_training/Image and audioVision/audio SRM training
    examples/r1_aqa/AudioAudio-question-answering GRPO
    examples/on_policy_distillation/TextTeacher service and OPD training
    examples/math_benchmarks/Text evaluationMath500, AIME, GPQA, and related benchmarks
    examples/entropy_viz/AnalysisLocal visualization of high-entropy tokens
    examples/chat/Interactive inferenceCheck exported model generation

    Example shell files contain cluster-specific paths, ports, and GPU settings and should be treated as templates.

    Monitoring, trajectories, and checkpoints

    LightRFT supports Weights & Biases, TensorBoard, trajectory recording and analysis, high-entropy-token visualization, distributed training-state recovery, and Hugging Face-format checkpoints. See the configuration guide for the relevant options, lightrft/utils/ckpt_scripts/README.md for checkpoint conversion, and examples/entropy_viz/render_trajectories.html for local trajectory visualization.

    Repository layout

    LightRFT/
    ├── lightrft/
    │   ├── datasets/                 # Text and multimodal datasets
    │   ├── evaluation/               # Evaluation and reward functions
    │   ├── models/                   # Text, vision, and audio Actors and reward models
    │   ├── strategy/
    │   │   ├── deepspeed/            # DeepSpeed strategy
    │   │   ├── fsdp/                 # FSDP v2 strategy
    │   │   ├── sglang_utils/         # SGLang engines and weight synchronization
    │   │   └── vllm_utils/           # vLLM engines and weight synchronization
    │   ├── trainer/                  # Advantage computation, experience generation, and trainers
    │   └── utils/                    # Logging, trajectory, and checkpoint utilities
    ├── examples/                     # Training, distillation, evaluation, and analysis examples
    ├── docs/                         # Sphinx documentation
    ├── tools/                        # Version and Docker helper tools
    ├── README.md
    └── README_zh.md
    

    Documentation and troubleshooting

    Documentation index

    For rollout-backend, GPU-memory, distributed-initialization, multimodal-data, and training-stability issues, consult the FAQ and troubleshooting guide.

    Build the documentation locally

    pip install -r requirements-doc.txt
    make docs
    

    The HTML output is written to docs/build/html/index.html. For live preview:

    make docs-live
    # Open http://localhost:8000 in a browser
    

    Roadmap

    Roadmap entries describe proposed work and are not guarantees of current functionality.

    Contributing

    Issues and pull requests are welcome. The recommended workflow is:

    1. Fork the repository and create a feature or documentation branch from main.
    2. Keep the change scoped and add the necessary tests or documentation checks.
    3. Use a Conventional Commits style commit message.
    4. Push the branch and open a pull request describing the motivation, changes, and validation.

    Common repository commit types include feature, fix, polish, docs, style, and refactor. Documentation branch names should contain doc when the documentation deployment workflow is required.

    Run the development checks with:

    pip install -r requirements-dev.txt
    make format   # YAPF
    make fcheck   # Flake8
    

    See the contribution guide for the repository workflow.

    Citation, license, and acknowledgements

    Citation

    If LightRFT supports your research or application, please cite:

    @misc{lightrft,
      title={LightRFT: Light, Efficient, Omni-modal & Reward-model Driven Reinforcement Fine-Tuning Framework},
      author={Niu, Yazhe and Pu, Yuan and Shi, Dongxing and Lu, Yudong and Xiong, Yingtong and Ge, Ruijun and Sun, Jiaxuan and Wan, Zunian and Zhang, Shaoang},
      publisher={GitHub},
      howpublished={\url{https://github.com/opendilab/LightRFT}},
      year={2025},
    }
    

    License

    LightRFT is licensed under the Apache License 2.0.

    Acknowledgements

    LightRFT is based on OpenRLHF, with some files and implementations adapted or reused. The project also builds on or learns from verl, SGLang, vLLM, DeepSpeed, and PyTorch FSDP.

    The project is developed in collaboration with colleagues from the System Platform Center and the AI Safety and Trustworthiness Center at Shanghai AI Laboratory.

    Contact