Skip to content

feat(#424): reward training service + tests (close #424) - #427

Merged
dahai80 merged 1 commit into
mainfrom
feat/reward-service-424
Aug 8, 2026
Merged

feat(#424): reward training service + tests (close #424)#427
dahai80 merged 1 commit into
mainfrom
feat/reward-service-424

Conversation

@dahai80

@dahai80 dahai80 commented Aug 8, 2026

Copy link
Copy Markdown
Owner

What

Closes #424. The reward-model training endpoints were partially landed: RewardTrainer (training/reward.py) and the admin routes (/admin/api/fine-tune/reward/jobs CRUD) were already on main, but RewardService — the queue/CRUD/persistence/SSE layer the routes and server.py depend 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. Mirrors DPOService.
  • tests/unit/test_reward_route.py (new) — 14 tests:
    • Route CRUD: create, missing model_id, missing pairs, malformed pair, invalid config, list, get-404, cancel-queued, delete, cancel-404
    • RewardConfig defaults, RewardJob.to_dict roundtrip
    • RewardTrainer.train_step with a stub backbone + registered value head: Bradley-Terry loss ≈ log(2) at init, acc_chosen ∈ {0,1}, value_head attached

Verification

  • pytest tests/unit/test_reward_route.py14 passed
  • ruff check clean, black --check clean (py313 target)
  • No real model loaded in route tests (queue processing neutralized, mirrors test_grpo_route.py / test_issue_399_dpo_orpo.py)

🤖 Generated with Claude Code

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
dahai80 merged commit e878f57 into main Aug 8, 2026
5 checks passed
@dahai80
dahai80 deleted the feat/reward-service-424 branch August 8, 2026 04:08
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(training): 新增 reward model 训练端点 (/admin/api/fine-tune/reward/jobs)

1 participant