/generate endpoint, and writes tokens, logprobs,
loss mask, and status back onto the Sample.
This is one of two styles of custom generation, both selected through
--custom-generate-function-path. The other style exchanges OpenAI-compatible
chat messages instead of tokens — see
Agentic Rollout (TITO).
The generate-function hook
--custom-generate-function-path accepts two forms. The difference is only
the signature you write — load_generate_function
(miles/rollout/inference_rollout/compatibility.py) adapts an old-form
function automatically at load time:
The class-based rollout path is the default;
MILES_USE_LEGACY_ROLLOUT_V1=1
selects the deprecated v1 path. Both generate-function forms work on either.- Builds a request from the prompt.
- Executes it against SGLang.
- Updates the
Samplewith tokens, logprobs, loss mask, status.
GenerateFnInput / GenerateFnOutput live in miles/rollout/base_types.py.
The input carries:
state: tokenizer, processor, args, sampling defaults.sample: the prompt, current tokens, response, status.sampling_params:max_new_tokens,temperature,top_p, etc.evaluation: whether this call serves an eval rollout.
compute_prompt_ids_from_sampleandcompute_request_payloadfrommiles/rollout/generate_utils/generate_endpoint_utils.pybuild/generaterequests.- A generate function can set
GenerateFnOutput.samplesto aSampleorlist[Sample].
Reference generators
miles/rollout/generate_hub/ ships reusable token-level generate functions
that compose with tool use and multi-turn logic:
single_turn.py: single-turn generation via/generate. Text or multimodal prompts.multi_turn.py: multi-turn tool calling via/generate. Adds CLI flags--generate-max-turns,--generate-tool-specs-path,--generate-tool-call-parser,--generate-execute-tool-function-path.benchmarkers.py: forces random output sequence length for benchmarking.
Next
- Customization: browse every Python hook.
- Agentic Rollout (TITO): the message-level style of custom generation.

