Overview
GRPO is the foundation for most reinforcement-learning objectives on Whitney.
Your code owns prompts, rewards, grouping, advantages, and the loss payload.
Whitney owns sampling, weight sync, and ordered primitive execution.
Other algorithms in More algorithms extend this loop
with different advantage estimators, clipping, or distillation semantics.
Prerequisites
GET /v1/training/capabilities — confirm forward_backward, optim_step,
save_weights_for_sampler, sample, and optionally logprobs.
- Create a session and LoRA run (see Quickstart).
Training loop
For each cycle:
Run at least two full cycles so update, sync, and sample semantics are explicit.
Caller-owned math
After sample returns:
- Score each completion with your reward function.
- Group completions by prompt and compute advantages (for standard GRPO: mean-center
within each group; optionally divide by standard deviation).
- Build a forward JSON payload whose
loss_function and loss_config encode your
policy-gradient objective for those advantages.
examples/training/http/rl_loop.py is a complete, runnable implementation of
this loop. It calls a --build-loss MODULE:CALLABLE you supply on every
cycle — build_loss(sample, cycle, request, ctx) -> dict — so the only code
you write is the reward function and the few lines below:
Never substitute generic GRPO when your algorithm requires a different estimator.
See More algorithms for variants — most of them are
one small change to build_loss over the same loop.
Log probabilities
Use logprobs when your objective needs policy or reference log probabilities.
Do not infer them from generated text.
Sample, logprobs, and forward bodies use the typed
JSON primitive contract.
Checkpoints
Optionally call save_weights_for_sampler before each sample cycle.
Cleanup
On failure: cancel the run, poll until terminal, then close the session.
If the algorithm-specific loss cannot be represented in the current Whitney JSON and operation contract, stop before
creating a session. Never silently substitute generic GRPO.