fix(#430): GRPO 训练在 worker 线程建立 thread-local stream - #432
Open
dahai80 wants to merge 1 commit into
Open
Conversation
_execute_grpo 经 asyncio.to_thread 在 worker 线程跑训练,而 GRPOTrainer._sample_completions 调用 mlx_lm.generate.generate_step, 其内部 with mx.stream(generation_stream) 用的是 mlx_lm 模块级的 thread-local generation_stream,worker 线程未绑定该 stream,抛 "There is no Stream(gpu, N) in current thread." 在 _execute_grpo 入口先 mx.new_thread_local_stream 建立本线程默认 stream,原训练/保存逻辑下沉到 _run_grpo。HTTP/数据结构不变。 验证: 真实 GRPO 作业 (Qwen3-0.6B-4bit, group_size=2, iters=2) 修复前 status=failed (Stream gpu 6),修复后 status=completed, progress.mean_reward=58.0, adapter 已写出。 Closes #430 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
dahai80
force-pushed
the
fix/grpo-stream-430
branch
from
August 8, 2026 06:12
98c6cab to
e2ddb4e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
修复 #430
GRPO 训练作业启动即失败:
There is no Stream(gpu, 6) in current thread.根因
_execute_grpo经asyncio.to_thread在 worker 线程跑训练,而GRPOTrainer._sample_completions调用mlx_lm.generate.generate_step,其内部with mx.stream(generation_stream)用的是mlx_lm.generate模块级 thread-localgeneration_stream,worker 线程未绑定,MLX 抛 Stream 错误。SFT/DPO/reward 训练不调generate_step,故不触发。改动
_execute_grpo入口先mx.new_thread_local_stream(mx.default_device())建立本线程默认 stream,原训练/保存逻辑下沉到_run_grpo。HTTP/数据结构/适配器格式不变。验证
tests/unit/test_grpo.py+test_grpo_route.py:19 passed, 1 skipped。status=failed,error="There is no Stream(gpu, 6) in current thread."status=completed,progress={iter:2, loss:0.0, mean_reward:58.0},adapter(adapters.safetensors + adapter_config.json)已写出。Closes #430
🤖 Generated with Claude Code