Guide for adding a new rollout function in slime and wiring it through --rollout-function-path. Use when user wants to implement custom rollout data generation logic, custom train/eval rollout outputs, or migrate from the default sglang rollout path.
Implement a custom rollout function and integrate it safely with slime training/eval flow.
Use this skill when:
slime.rollout.sglang_rollout.generate_rolloutStart from one of these references:
slime/rollout/sglang_rollout.pyslime/rollout/sft_rollout.pyIf the task needs engine-based async generation and rewards, use the sglang path as base. If the task is file/buffer-driven and simple, use sft path as base.
Create a new file, for example:
slime/rollout/<your_rollout>.pyRequired callable signature:
def generate_rollout(args, rollout_id, data_source, evaluation=False) -> RolloutFnTrainOutput | RolloutFnEvalOutput:
...
Return types are defined in slime/rollout/base_types.py.
evaluation=False), return RolloutFnTrainOutput(samples=..., metrics=...)evaluation=True), return RolloutFnEvalOutput(data=..., metrics=...)Minimal skeleton:
from slime.rollout.base_types import RolloutFnTrainOutput, RolloutFnEvalOutput
def generate_rollout(args, rollout_id, data_source, evaluation=False):
if evaluation:
result = {
"custom_eval": {
"rewards": [],
"truncated": [],
"samples": [],
}
}
return RolloutFnEvalOutput(data=result)
groups = data_source.get_samples(args.rollout_batch_size)
# fill Sample fields needed by training: tokens/response_length/reward/status (+ loss_mask when needed)
return RolloutFnTrainOutput(samples=groups)
For each generated sample, ensure required training fields are populated consistently with your objective:
tokensresponse_lengthreward (or reward dict if your setup uses keyed rewards)statusIf partial rollout or masking logic is involved, keep loss_mask semantics consistent with existing behavior.
Set your function path via CLI:
--rollout-function-path slime.rollout.<your_rollout>.generate_rollout
The default and signature expectation are documented in:
slime/utils/arguments.pydocs/en/get_started/customization.mdtokens, response_length, reward, status)slime/rollout/sglang_rollout.pyslime/rollout/sft_rollout.pyslime/rollout/base_types.pyslime/ray/rollout.pyslime/utils/arguments.pydocs/en/get_started/customization.md