Skip to main content
Most of Miles’s behavior can be replaced with user-supplied Python by passing a --*-path flag. This page lists every such hook, the function signature it expects, and the default it replaces.

At a glance


Rollout

--rollout-function-path

Replace the entire rollout function. Use this only for fundamentally different flows such as multi-agent co-evolution.
Default: miles.rollout.inference_rollout.inference_rollout_common.InferenceRolloutFn; use miles.rollout.sglang_rollout.generate_rollout under MILES_USE_LEGACY_ROLLOUT_V1=1. Plain functions with the signature above are wrapped in a legacy adapter. A class-based rollout function needs to subclass miles.rollout.base_types.BaseRolloutFn. Reference: examples/experimental/multi_agent/rollout_with_multi_agents.py.

--custom-generate-function-path

Replace just the generation step inside the default rollout. Most tool-use, RAG, and multi-turn workflows live here.
The hook also accepts the GenerateFnInput -> GenerateFnOutput form; both signatures load through the same adapter. See Generate Endpoint for the full contract. Reference: examples/experimental/search-r1/generate_with_search.py.

--custom-agent-function-path

Enabled when you set --custom-generate-function-path miles.rollout.generate_hub.agentic_tool_call.generate. Use --custom-agent-function-path to specify the async agent or environment loop that sends OpenAI-compatible chat requests through Miles’ TITO session server.
See Agentic Rollout (TITO) for the full wiring and message/token ownership contract.

--data-source-path

Default: miles.rollout.data_source.RolloutDataSourceWithBuffer.

--eval-function-path

Same signature as --rollout-function-path. Defaults to whatever rollout function is configured.

Session

--session-message-matcher

Some harnesses do not replay history verbatim — they reserialize tool-call arguments or drop reasoning_content — and the default strict matcher counts that as divergence (v1 rollback, v2 branching). This flag loosens what “the same message” means during replay: choose a looser built-in selector (see Agentic Rollout (TITO)) or supply your own matcher via a trusted dotted import path:
stored_message is the authoritative stored message; return True to accept the replayed message as the same history at that position. Keep the matcher a fast, synchronous, side-effect-free equivalence check — exceptions or non-bool results return HTTP 500, and startup fails if the path does not resolve.

Reward

--custom-rm-path

Built-in --rm-type options: math, dapo, deepscaler, gemma_math, f1, gpqa, ifbench, remote_rm (with --rm-url), random, deterministic_random. Prefixing any of them with boxed_ (for example boxed_math) extracts \boxed{} from the response before grading.

--custom-reward-post-process-path

Hook to normalize rewards differently from the default GRPO normalization.

Filtering

--dynamic-sampling-filter-path

Per-group filter; runs after scoring, before queueing for training.
Stock implementation: miles.rollout.filter_hub.dynamic_sampling_filters.check_reward_nonzero_std.

--buffer-filter-path

Pops samples from the rollout buffer at dequeue time. The default is pop_first in miles/rollout/data_source.py.

--rollout-sample-filter-path

Per-sample, in-place. Set s.remove_sample = True to exclude a sample from the loss (advantage normalization still uses it). The framework passes data: list[list[Sample]] — a list of n_samples_per_prompt-size groups — so iterate the outer list once to reach Sample objects:

--rollout-all-samples-process-path

Runs after rollout completes and can see all samples, including filtered ones. Useful for logging or analysis.

--rollout-data-postprocess-path

Runs after log probabilities have been computed but before training. Useful for updating loss masks based on per-token logprobs.

Training

--custom-loss-function-path

Replace the GRPO/PPO loss. Requires --loss-type custom_loss. Useful for novel objectives or multi-objective work.

--custom-tis-function-path

Importance sampling correction for off-policy training when train and inference diverge. Reference: examples/infra_features/train_infer_mismatch_helper/mis.py.

--custom-pg-loss-reducer-function-path

Use case: Dr.GRPO divides by a constant instead of effective token count. Reference: examples/experimental/DrGRPO/custom_reducer.py.

--custom-convert-samples-to-train-data-path


Megatron hooks

The Megatron init, log-prob, and train-step hooks give access to the live model and optimizer, useful for custom probes, weight clipping, or surgical interventions. The post-save hook runs on rank 0 after checkpoint save completion and receives the saved checkpoint paths instead of live model objects.

Logging

Return True to suppress Miles’s default logging, False to layer on top.

Model

--custom-model-provider-path

Replace Megatron’s default model factory.

Worked example

A custom rollout plus a custom reward in one launch script:
That is the entire delta from the stock GRPO recipe, with no source changes to Miles. → Next: Server arguments reference