Datum.
Record samples and attach provenance
To record routes and attach them to a training example, create the sampling client withrecord_stability_info=True, sample with include_routed_experts=True, and describe the datum’s tokens with with_provenance():
record_stability_info=Truerecords every sample from the client. Each returnedSampledSequencecarries asequence_idthat refers to its record. The record and its routes stay on Baseten, and the datum carries only the references. Create the client from the training client, as in the snippet, so the run’s own sampler records the routes that its trainer replays.include_routed_experts=Truecaptures the expert routes with each record. It requires a client created withrecord_stability_info=True.with_provenance()returns a copy of the datum with two span lists. Themodel_inputspans describe the input tokens in order, and theloss_fn_inputsspans describetarget_tokensin order. Each span names a sample’ssequence_id, whether its tokens come from the sample’s prompt (PromptProvenanceSpan) or its completion (SampledProvenanceSpan), the position of its first token in that part (offset,0by default), and the number of tokens (length).
PromptProvenanceSpan and SampledProvenanceSpan from tinker.types.
Requirements and limitations
- Router replay works in both availability modes on MoE models whose sampler captures routes. On other models, a
sample()call withinclude_routed_experts=Truefails. - Recording takes tokenized text prompts. A recording client rejects prompts that contain images.
dpodoesn’t support router replay. Aforward_backward()call withloss_fn="dpo"fails when its datums carry provenance.
Routing mismatch between the sampler and trainer
Each MoE layer has a router that sends every token to a few of the layer’s experts. The sampler and the trainer both run the router, but with different kernels and numerics, so for some tokens they choose different experts. The trainer then computes those tokens’ log-probabilities and gradients through experts that didn’t generate them. These routing differences widen the KL divergence between the sampler and trainer even when both run the same weights. The RL losses read the gap as a change in the policy, and in MoE models the mismatch can grow until training becomes unstable. R3 removes this source of mismatch: the sampler records the experts it chose for each token, and the trainer reuses them in its forward and backward passes. The trainer still computes the router’s gating weights from its own logits, so the router keeps training.Next steps
- Check whether an RL run is learning: Monitor the KL divergence between the sampler and trainer.
- Write an RL loop with the Loops SDK: Sample, score, and train in your own loop.
- SamplingClient: The
sample()options for route capture.