NVIDIA-NeMo/Gym

GitHub: NVIDIA-NeMo/Gym

NVIDIA 推出的用于构建大型语言模型强化学习训练环境的库,专注于环境开发、Rollout 采集与可验证奖励支持。

Stars: 707 | Forks: 81

# NeMo Gym **[需求](#-requirements)** • **[快速开始](#-quick-start)** • **[可用环境](#-available-environments)** • **[文档与资源](#-documentation--resources)** • **[社区与支持](#-community--support)** • **[引用](#-citations)** NeMo Gym 是一个用于构建大型语言模型 (LLM) 强化学习 (RL) 训练环境的库。它提供了开发环境、扩展 rollout 收集以及与您首选的训练框架无缝集成的基础设施。 ## 🏆 为什么选择 NeMo Gym? - 用于加速环境开发的脚手架和模式:多步、多轮和用户建模场景 - 无需专家级的 RL 训练循环知识即可贡献环境 - 独立于 RL 训练循环,端到端测试环境和吞吐量 - 与现有的环境、系统和 RL 训练框架互操作 - 不断增长的训练环境和数据集集合,用于可验证奖励强化学习 (RLVR) ## 🔗 生态系统 NeMo Gym 是 [NVIDIA NeMo](https://docs.nvidia.com/nemo/gym/latest/about/ecosystem.html#related-nemo-libraries) 的一部分,后者是 NVIDIA 用于构建和训练生成式 AI 模型的 GPU 加速平台。NeMo Gym 与越来越多的 RL 训练框架和环境库集成;有关完整详细信息和教程,请参阅 [生态系统](https://docs.nvidia.com/nemo/gym/latest/about/ecosystem.html) 页面。 **训练框架:** [NeMo RL](https://docs.nvidia.com/nemo/gym/latest/training-tutorials/nemo-rl-grpo/index.html) • [OpenRLHF](https://github.com/OpenRLHF/OpenRLHF/blob/main/examples/python/agent_func_nemogym_executor.py) • [Unsloth](https://docs.nvidia.com/nemo/gym/latest/training-tutorials/unsloth-training.html) • [更多 →](https://docs.nvidia.com/nemo/gym/latest/about/ecosystem.html#training-framework-integrations) **环境库:** [Reasoning Gym](https://github.com/NVIDIA-NeMo/Gym/tree/main/resources_servers/reasoning_gym) • [Aviary](https://github.com/NVIDIA-NeMo/Gym/tree/main/resources_servers/aviary) • [更多 →](https://docs.nvidia.com/nemo/gym/latest/about/ecosystem.html#environment-library-integrations) ## 📋 需求 NeMo Gym 旨在标准开发机器上运行: | 硬件需求 | 软件需求 | | --------------------- | --------------------- | | **GPU**:NeMo Gym 库运行不需要
• 特定资源服务器或模型推理可能需要 GPU(请参阅各个服务器文档) | **操作系统**:
• Linux (Ubuntu 20.04+ 或同等版本)
• macOS (x86_64 为 11.0+,Apple Silicon 为 12.0+)
• Windows (通过 WSL2) | | **CPU**:任何现代 x86_64 或 ARM64 处理器(例如 Intel、AMD、Apple Silicon) | **Python**:3.12 或更高版本 | | **RAM**:最低 8 GB(对于较大的环境建议 16 GB+) | **Git**:用于克隆仓库 | | **存储**:安装和基本使用至少需要 5 GB 可用磁盘空间 | **互联网连接**:下载依赖项和 API 访问所需 | **其他需求** - **API Keys**:具有可用额度的 OpenAI API key(用于快速入门示例) - 支持其他模型提供商(Azure OpenAI、通过 vLLM 的自托管模型) - **Ray**:作为依赖项自动安装(无需单独设置) ## 🚀 快速开始 安装 NeMo Gym,启动服务器,并为 RL 训练收集您的第一批已验证 rollout。 ### 设置 ``` # 克隆仓库 git clone git@github.com:NVIDIA-NeMo/Gym.git cd Gym # 安装 UV (Python 包管理器) curl -LsSf https://astral.sh/uv/install.sh | sh source $HOME/.local/bin/env # 创建虚拟环境 uv venv --python 3.12 source .venv/bin/activate # 安装 NeMo Gym uv sync --extra dev --group docs ``` ### 配置您的 API Key 创建一个包含您的 OpenAI API key 和您想使用的 [策略模型](https://docs.nvidia.com/nemo/gym/latest/about/concepts/key-terminology.html#term-Policy-Model) 的 `env.yaml` 文件。将 `your-openai-api-key` 替换为您的实际密钥。此文件有助于将您的密钥排除在版本控制之外,同时仍使其可供 NeMo Gym 使用。 ``` echo "policy_base_url: https://api.openai.com/v1 policy_api_key: your-openai-api-key policy_model_name: gpt-4.1-2025-04-14" > env.yaml ``` ### 启动服务器 **终端 1(启动服务器)**: ``` # 启动服务器 (这将保持运行) config_paths="resources_servers/example_single_tool_call/configs/example_single_tool_call.yaml,\ responses_api_models/openai_model/configs/openai_model.yaml" ng_run "+config_paths=[${config_paths}]" ``` **终端 2(与 Agent 交互)**: ``` # 在一个新终端中,激活环境 source .venv/bin/activate # 与你的 Agent 交互 python responses_api_agents/simple_agent/client.py ``` ### 收集 Rollout **终端 2**(保持终端 1 中的服务器运行): ``` # 创建一个包含单个查询的简单数据集 echo '{"responses_create_params":{"input":[{"role":"developer","content":"You are a helpful assistant."},{"role":"user","content":"What is the weather in Seattle?"}]}}' > weather_query.jsonl # 收集已验证的 rollouts ng_collect_rollouts \ +agent_name=example_single_tool_call_simple_agent \ +input_jsonl_fpath=weather_query.jsonl \ +output_jsonl_fpath=weather_rollouts.jsonl # 查看结果 cat weather_rollouts.jsonl | python -m json.tool ``` 这将生成带有验证分数的训练数据! ### 清理服务器 **终端 1** 中运行的服务器:按 Ctrl+C 停止 ng_run 进程。 ### 后续步骤 既然您可以生成 rollout,请选择您的路径: - **开始训练** — 使用 NeMo Gym 结合您首选的 RL 框架训练模型。请参阅 [训练教程](https://docs.nvidia.com/nemo/gym/latest/training-tutorials/index.html)。 - **使用现有环境** — 浏览下方的 [可用环境](#-available-environments) 以找到符合您目标的环境。 - **构建自定义环境** — 实施或集成现有工具并定义任务验证逻辑。从 [创建训练环境](https://docs.nvidia.com/nemo/gym/latest/environment-tutorials/creating-training-environment.html) 教程开始。 ## 📦 可用环境 NeMo Gym 包含一组经过精选的环境,用于跨多个领域进行训练和评估: ### 示例环境模式 目的:展示 NeMo Gym 模式和概念。 | 名称 | 演示内容 | 配置 | README | | ------------------ | ------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------- | | Multi Step | 多步工具调用 | example_multi_step.yaml | README | | Session State Mgmt | 会话状态管理 (内存中) | example_session_state_mgmt.yaml | README | | Single Tool Call | 基本单步工具调用 | example_single_tool_call.yaml | README | ### 用于训练和评估的环境 目的:具有精选数据集的训练就绪环境。 | Resources Server | 领域 | 描述 | 价值 | 训练 | 验证 | 许可证 | 配置 | 数据集 | | --------------------------------------------- | --------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- | ----- | ---------- | --------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Arc Agi | knowledge | 解决旨在测试智力的谜题。参见 https://arcprize.org/arc-agi。 | 提高解谜能力。 | - | ✓ | - | arc_agi.yaml | - | | Aviary | agent | 基于 HotPotQA 数据集和 Wikipedia 搜索的多跳问答 | 提高知识和 Agent 能力 | ✓ | ✓ | Apache 2.0 | hotpotqa_aviary.yaml | - | | Aviary | math | 带计算器工具的 GSM8k 基准 | 测试数学和 Agent 能力 | ✓ | ✓ | Apache 2.0 | gsm8k_aviary.yaml | - | | Calendar | agent | 多轮日历调度数据集。用户以自然语言陈述事件和约束;模型调度事件以满足所有约束。 | 提高多轮指令遵循能力 | ✓ | ✓ | Apache 2.0 | calendar.yaml | Nemotron-RL-agent-calendar_scheduling | | Calendar | agent | 多轮日历调度数据集。用户以自然语言陈述事件和约束;模型调度事件以满足所有约束。 | 提高多轮指令遵循能力 | ✓ | ✓ | Creative Commons Attribution 4.0 International | calendar_v2.yaml | Nemotron-RL-Instruction-Following-Calendar-v2 | | Circle Click | other | 点击图像中的圆圈 | - | - | - | - | circle_click.yaml | - | | Code Gen | coding | 模型必须提交正确的代码来解决问题 | 提高竞赛编程能力 | ✓ | ✓ | Apache 2.0 | code_gen.yaml | nemotron-RL-coding-competitive_coding | | Equivalence Llm Judge | agent | 带 LLM-as-a-judge 的简短 bash 命令生成问题 | 提高基础 bash 和指令遵循 (IF) 能力 | ✓ | ✓ | GNU General Public License v3.0 | nl2bash-equivalency.yaml | - | | Equivalence Llm Judge | knowledge | 带 LLM-as-a-judge 的简短回答问题 | 提高 GPQA / HLE 等知识相关基准 | - | - | - | equivalence_llm_judge.yaml | - | | Ether0 | knowledge | ether0 化学基准验证器 | 使用 ether0 基准评估化学知识和推理 | - | ✓ | - | ether0.yaml | - | | Finance Sec Search | agent | 针对财务分析问题的 SEC EDGAR 文件搜索 | 使 LLM 能够搜索和分析 SEC 文件 | - | - | - | finance_sec_search.yaml | - | | Genrm Compare | rlhf | 用于 RLHF 训练的 GenRM 成对比较 | 使用 GenRM 模型比较多个候选响应 | ✓ | - | Creative Commons Attribution 4.0 International | genrm_compare.yaml | Nemotron-RL-Identity-Following-v1 | | Google Search | agent | 集成搜索工具的多选题问答问题 | 使用搜索工具提高知识相关基准 | ✓ | - | Apache 2.0 | google_search.yaml | Nemotron-RL-knowledge-web_search-mcqa | | Gpqa Diamond | knowledge | GPQA Diamond 多选题问答问题 | 通过 MCQ 验证评估研究生水平的科学推理 | ✓ | - | MIT | gpqa_diamond.yaml | - | | Instruction Following | instruction_following | 针对 IFEval 和 IFBench 风格指令遵循能力的指令遵循数据集 | 提高 IFEval 和 IFBench | ✓ | - | Apache 2.0 | instruction_following.yaml | Nemotron-RL-instruction_following | | Jailbreak Detection | safety | 使用 Nemotron judge + 组合奖励的越狱检测 | - | - | ✓ | - | jailbreak_detection_nemotron_combined_reward_tp8.yaml | - | | Math Advanced Calculations | agent | 有反直觉计算器的指令遵循数学环境 | 提高特定数学环境中的指令遵循能力 | ✓ | - | Apache 2.0 | math_advanced_calculations.yaml | Nemotron-RL-math-advanced_calculations | | Math Formal Lean | math | Lean4 形式化证明验证环境 | 提高形式化定理证明能力 | ✓ | - | Apache 2.0 | nemotron_clean_easy.yaml | - | | Math Formal Lean | math | Lean4 形式化证明验证环境 | 提高形式化定理证明能力 | ✓ | - | Apache 2.0 | nemotron_first_try_hard.yaml | - | | Math Formal Lean | math | Lean4 形式化证明验证环境 | 提高形式化定理证明能力 | ✓ | - | Apache 2.0 | nemotron_medium_500.yaml | - | | Math Formal Lean | math | Lean4 形式化证明验证环境 | 提高形式化定理证明能力 | ✓ | - | Apache 2.0 | nemotron_very_easy.yaml | - | | Math Formal Lean | math | Lean4 形式化证明验证环境 | 提高形式化定理证明能力 | ✓ | - | MIT | math_formal_lean.yaml | - | | Math Formal Lean | math | 具有多轮自我纠正的 Lean4 形式化证明验证环境 | 提高形式化定理证明能力 | ✓ | - | MIT | math_formal_lean_multi_turn.yaml | - | | Math With Code | math | 模型使用简单的计算器工具解决竞赛数学问题 | 提高数学和简单工具使用能力 | ✓ | - | Apache 2.0 | math_with_code.yaml | - | | Math With Judge | math | 带 math-verify 的 DAPO17k 数学数据集 | 提高包括 AIME 24 / 25 在内的数学能力 | ✓ | ✓ | Apache 2.0 | dapo17k.yaml | - | | Math With Judge | math | 带 math-verify 的 MathStackOverflow 数学数据集 | 提高包括 AIME 24 / 25 在内的数学能力 | ✓ | ✓ | Creative Commons Attribution-ShareAlike 4.0 International | math_stack_overflow.yaml | Nemotron-RL-math-stack_overflow | | Math With Judge | math | 带 math-verify 和 LLM-as-a-judge 的 OpenMathReasoning 数学数据集 | 提高包括 AIME 24 / 25 在内的数学能力 | ✓ | ✓ | Creative Commons Attribution 4.0 International | math_with_judge.yaml | Nemotron-RL-math-OpenMathReasoning | | Mcqa | knowledge | 多选题问答问题 | 提高 MMLU / GPQA / HLE 等基准 | ✓ | ✓ | Apache 2.0 | mcqa.yaml | Nemotron-RL-knowledge-mcqa | | Mini Swe Agent | coding | 使用 mini-swe-agent 编排的软件开发 | 提高软件开发能力,如 SWE-bench | ✓ | ✓ | MIT | mini_swe_agent.yaml | SWE-Gym | | Multichallenge | knowledge | 针对推理记忆、指令保留、版本编辑和自我一致性。 | 提高复杂的多轮对话能力 | ✓ | - | Creative Commons Attribution 4.0 International | multichallenge_nrl.yaml | Nemotron-RL-Instruction-Following-MultiTurnChat-v1 | | Newton Bench | math | 通过跨 12 个物理领域的 Agent 实验进行科学定律发现任务 | 提高科学、推理和工具使用能力 | ✓ | - | Apache 2.0 | newton_bench.yaml | - | | Ns Tools | agent | 带有数学验证的 NeMo Skills 工具执行 | - | - | - | - | ns_tools.yaml | - | | Over Refusal Detection | | - | - | ✓ | - | - | over_refusal_detection.yaml | - | | Reasoning Gym | knowledge | 超过 100 项任务,包括代数、算术、计算、认知、几何、图论、逻辑和许多常见游戏。 | 提高鲁棒性、泛化能力、广泛的知识和推理 | ✓ | - | Apache 2.0 | reasoning_gym.yaml | Nemotron-RL-ReasoningGym-v1 | | Single Step Tool Use With Argument Comparison | agent | 基于专家轨迹的会话工具使用 RL;跨身份验证、查找和服务域的每级行为克隆。 | - | ✓ | ✓ | Creative Commons Attribution 4.0 International | single_step_tool_use_with_argument_comparison.yaml | Nemotron-RL-Agentic-Conversational-Tool-Use-Pivot-v1 | | Single Step Tool Use With Argument Comparison | agent | 使用专家轨迹的通用函数调用 RL 数据集;行为克隆以匹配每级的专家工具调用。 | - | ✓ | ✓ | Creative Commons Attribution 4.0 International | toolcall_schema_single_step_tool_use_with_argument_comparison.yaml | Nemotron-RL-Agentic-Function-Calling-Pivot-v1 | | Single Step Tool Use With Argument Comparison | agent | 用于软件工程 Agent 的 GitHub-issue 数据集;从 SWE-Gym 和 SWE-Bench-Verified 重构以适配 NeMo Gym。 | - | ✓ | ✓ | Creative Commons Attribution 4.0 International | swe_pivot_single_step_tool_use_with_argument_comparison.yaml | Nemotron-RL-Agentic-SWE-Pivot-v1 | | Single Step Tool Use With Argument Comparison | agent | 模型必须在涉及搜索工具的给定轨迹中输出下一个正确的调用。 | 提高 Agent 搜索能力。 | ✓ | ✓ | Apache 2.0 | search_pivot_single_step_tool_use_with_argument_comparison.yaml | - | | Spider2 Lite | coding | 在 Spider 2.0-Lite (135 个 SQLite 任务) 上进行基于执行的 Text-to-SQL 评估。基于结果集等价性的二元奖励。 | 使用基于执行的二元奖励(无需 LLM judge)提高针对现实世界企业查询的 Text-to-SQL 能力。 | - | ✓ | - | spider2_lite.yaml | - | | Structured Outputs | instruction_following | 检查响应是否遵循提示中的结构化输出要求 | 提高指令遵循能力 | ✓ | ✓ | Apache 2.0 | structured_outputs_json.yaml | Nemotron-RL-instruction_following-structured_outputs | | Swerl Gen | coding | 运行 SWE 风格任务的沙盒评估(补丁生成或复现测试生成) | 提高 SWE 能力,适用于 SWE-bench 等基准 | ✓ | ✓ | Apache 2.0 | swerl_gen.yaml | - | | Swerl Llm Judge | coding | 通过 ... 选择评分的 SWE 风格多选 LLM-judge 任务。 | 提高 SWE 能力,适用于 SWE-bench 等基准 | ✓ | ✓ | MIT | swerl_llm_judge.yaml | - | | Tavily Search | agent | 模型使用搜索工具来满足用户查询。 | 衡量 Agent 搜索能力 | ✓ | ✓ | Apache 2.0 | tavily_search_judge_vllm_model.yaml | - | | Terminus Judge | agent | 单步基于终端的任务(rubrics v4 judge prompt) | 提高终端风格任务的性能 | ✓ | ✓ | Apache 2.0 | terminus_judge.yaml | - | |minus Judge | agent | 单步基于终端的任务(简单 judge prompt) | 提高终端风格任务的性能 | ✓ | ✓ | Apache 2.0 | terminus_judge_simple.yaml | - | | Text To Sql | coding | 带有 LLM-as-a-judge 等价性检查的 Text-to-SQL 生成 | 提高跨多种方言的 Text-to-SQL 能力 | - | - | - | text_to_sql.yaml | - | | Workplace Assistant | agent | 职场助手多步工具使用环境 | 提高多步工具使用能力 | ✓ | ✓ | Apache 2.0 | workplace_assistant.yaml | Nemotron-RL-agent-workplace_assistant | | Xlam Fc | agent | Salesforce xlam-function-calling-60k 工具调用任务 | 提高工具调用能力 | ✓ | ✓ | Apache 2.0 | xlam_fc.yaml | - | | Xstest | safety | XSTest 安全基准 - 夸大安全(过度拒绝)评估 | 评估模型在有用性和无害性之间的安全校准 | - | - | - | xstest.yaml | - | | Xstest | safety | XSTest 安全基准 - 夸大安全(过度拒绝)评估 | 评估模型在有用性和无害性之间的安全校准 | - | - | - | xstest_string_match.yaml | - | ## 📖 文档与资源 - **[文档](https://docs.nvidia.com/nemo/gym/latest/index.html)** - 技术参考文档 - **[训练教程](https://docs.nvidia.com/nemo/gym/latest/training-tutorials/index.html)** - 使用 NeMo Gym 环境进行训练 - **[API 参考](https://docs.nvidia.com/nemo/gym/latest/apidocs/index.html)** - 完整的类和函数参考 ## 🤝 社区与支持 我们需要您的贡献!以下是参与方式: - **[报告问题](https://github.com/NVIDIA-NeMo/Gym/issues)** - Bug 报告和功能请求 - **[贡献指南](https://docs.nvidia.com/nemo/gym/latest/contribute/index.html)** - 如何贡献代码、文档、新环境或训练框架集成 ## 📚 引用 如果您在研究中使用 NeMo Gym,请使用以下 BibTeX 条目进行引用: ``` @misc{nemo-gym, title = {NeMo Gym: An Open Source Library for Scaling Reinforcement Learning Environments for LLM}, howpublished = {\url{https://github.com/NVIDIA-NeMo/Gym}}, author={NVIDIA}, year = {2025}, note = {GitHub repository}, } ```
标签:Apex, DLL 劫持, Gym, NeMo, Python, RLHF, RLVR, 人工智能, 多轮对话, 大语言模型, 威胁情报, 开发者工具, 强化学习, 技术框架, 推理, 无后门, 机器学习, 模型训练, 深度学习, 生成式AI, 用户模式Hook绕过, 索引, 自动化训练, 训练环境, 逆向工具