feat(#424): reward training service + tests (close #424) - #427
Merged
Conversation
The RewardTrainer (training/reward.py) and admin routes
(/admin/api/fine-tune/reward/jobs CRUD) were already on main, but the
RewardService — the queue/CRUD/persistence/SSE layer that the routes
and server.py wire up — was never committed (left untracked from the
prior reward-training work). Without it the reward endpoints 500 at
import time.
This commits the missing service and adds test coverage:
- fusion_mlx/training/reward_service.py — RewardJob + RewardService
(queue, create/get/list/cancel/delete, _execute_reward, persistence,
SSE event push), mirroring DPOService.
- tests/unit/test_reward_route.py — 14 tests: route CRUD (create,
missing model_id/pairs, malformed pair, invalid config, list, get
404, cancel queued, delete, cancel 404) + RewardConfig defaults,
RewardJob.to_dict roundtrip, RewardTrainer.train_step loss/metrics
with a stub backbone + registered value head (Bradley-Terry loss
~= log(2) at init, acc in {0,1}).
Closes #424.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
dahai80
added a commit
that referenced
this pull request
Aug 8, 2026
补齐 PR #427 缺失的对外暴露层: - fine_tune_route.py: 新增 /admin/api/fine-tune/reward/jobs 的 create/list/get/cancel/delete 五个路由 + set_reward_context / _get_reward_service / _create_reward_job 共享辅助,校验 model_id 与 preference_pairs[{prompt,chosen,rejected}] schema。 - server.py: 启动期实例化 RewardService 单例,经 set_reward_context 注入 engine pool 与 event loop,镜像 DPO 装配块。 端到端验证(真实 Qwen3-0.6B-4bit, 4 iters): status=completed, loss 0.69→0.0003, reward_margin 7.98, acc_chosen 1.0, adapter 写盘 (reward_model=true)。 14 项 reward route 单测全绿。 Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
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.
What
Closes #424. The reward-model training endpoints were partially landed:
RewardTrainer(training/reward.py) and the admin routes (/admin/api/fine-tune/reward/jobsCRUD) were already on main, butRewardService— the queue/CRUD/persistence/SSE layer the routes andserver.pydepend on — was never committed (left untracked from prior work). The reward endpoints would 500 at import without it.Changes
fusion_mlx/training/reward_service.py(new, was untracked) —RewardJob+RewardService: job queue, create/get/list/cancel/delete,_execute_reward(load → LoRA → Bradley-Terry loop → save adapter → cleanup), JSON persistence, SSE event push. MirrorsDPOService.tests/unit/test_reward_route.py(new) — 14 tests:RewardConfigdefaults,RewardJob.to_dictroundtripRewardTrainer.train_stepwith a stub backbone + registered value head: Bradley-Terry loss ≈ log(2) at init,acc_chosen∈ {0,1},value_headattachedVerification
pytest tests/unit/test_reward_route.py→ 14 passedruff checkclean,black --checkclean (py313 target)test_grpo_route.py/test_issue_399_dpo_orpo.py)🤖 Generated with Claude Code