Skip to main content
Most of miles-diffusion’s behavior can be replaced with user-supplied Python by passing a --*-path flag (loaded via miles.utils.misc.load_function as a dotted import path). This page lists the diffusion-relevant hooks, the signatures they expect, and the defaults they replace — in the same spirit as Miles customization.

At a glance

--loss-type (policy_loss / nft / sft_loss / custom_loss) is the shortcut that auto-fills several of the train-side paths; see § Training.

Rollout

--rollout-function-path

Replace the entire train rollout. Diffusion recipes use miles.rollout.sglang_diffusion_rollout.generate_rollout (not the LLM default).
miles/ray/rollout.py passes the data source positionally through call_rollout_fn. Legacy list/dict returns are still wrapped into the corresponding output dataclass by miles.rollout.base_types.call_rollout_fn.

--eval-function-path

Same shape as the rollout function. Defaults to --rollout-function-path when unset.

--data-source-path

Class (not a function). Default: miles.rollout.data_source.RolloutDataSourceWithBuffer.

--custom-generate-function-path

Replace the inner microgroup generator inside generate_and_rm_microgroup. Default: generate_microgroup.
evaluation= is optional — if your signature omits it, the caller skips that kwarg.

--diffusion-step-strategy-path

Select which denoising steps contribute SDE log-probs / train pairs. Stock implementations live in miles/rollout/step_strategy_hub.py.
Details: SDE step backend.

Reward

Built-in scorers (--rm-type pickscore / ocr) are documented in Rewards. The hooks below replace that dispatch entirely.

--custom-rm-path

Wired only through batched_async_rm — implement per-sample routing inside your batched function if needed.
HTTP / remote scoring: implement a batched custom RM and read args.rm_url (or your own flags). Encode images from sample.generated_output (see _sample_to_rgb_hwc_uint8_frames in miles/rollout/rm_hub/pickscore.py):

--custom-reward-post-process-path

Replace GRPO advantage normalization in RolloutManager._post_process_rewards.
Default behavior: reshape to (-1, n_samples_per_prompt), subtract mean (--globalize-reward-mean for batch-level), optionally divide by std (on by default — --disable-grpo-std-normalization turns it off; --globalize-reward-std switches per-group std to batch-wide).

Filtering

--dynamic-sampling-filter-path

Per-group filter after scoring (DAPO-style). Stock: miles.rollout.filter_hub.dynamic_sampling_filters.check_reward_nonzero_std.

--buffer-filter-path

Select samples when dequeuing from the rollout buffer. Default is pop_first in miles/rollout/data_source.py.

--rollout-sample-filter-path

Per-sample, in-place. Set sample.remove_sample = True to exclude a sample from the loss (it still participates in advantage normalization).

Training

--loss-type picks the default prepare / formula / expand paths: DiT forward always stays in the FSDP actor; the loss hook only computes the objective.

--custom-expand-samples-to-train-pairs-path

Default for Flow-GRPO lives under miles/ray/data_conversion_hub/flow_grpo.py.

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

Replace the entire RolloutManager._convert_samples_to_train_data (including reward post-process + expand). Prefer the narrower expand hook unless you need full control.

--custom-prepare-train-batch-path

Builds DiT inputs from train pairs. Defaults: miles.backends.fsdp_utils.loss_hub.flow_grpo.prepare_flow_grpo_batch or the NFT equivalent under loss_hub.nft.

--custom-loss-function-path

--sde-step-backend-path

Class implementing SdeStepBackend. Auto-selected from --diffusion-sde-type (sde / odeDiffusersSdeStepBackend, cpsCpsSdeStepBackend) unless overridden. See SDE step backend.

Logging

Return a truthy value to skip the default logging; falsy layers on top.

Model family

--hf-checkpoint / --diffusion-model-family / --train-pipeline-config-path

--hf-checkpoint names the diffusers pipeline for train + rollout. Family is resolved from the checkpoint name unless you pass --diffusion-model-family (e.g. sd3). For an unregistered family, pass --train-pipeline-config-path to a TrainPipelineConfig subclass instead.

--model-backend-path

Class for loading components / FSDP / scheduler. Default comes from the family config (usually a DiffusersModelBackend).

Worked example

Custom reward + post-process on top of the stock SD3 Flow-GRPO recipe:
(--extra-args forwarding depends on the launch script; you can also splice the flags into a forked recipe.)

Pairs well with