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 pass miles.rollout.sglang_diffusion_rollout.generate_rollout; the flag’s default (miles.rollout.sglang_rollout.generate_rollout, the LLM path) is not shipped in miles-diffusion.
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.
RolloutManager also reads len(data_source.dataset) when --num-rollout is unset.

--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, and which latents the engine ships back for the trainer. Stock implementations live in miles/rollout/step_strategy_hub.py.
--rollout-return-full-trajectory overrides return_step_indices back to all steps for debugging / A-B runs. DiffusionNFT picks the timesteps it trains on with a separate hook, --diffusion-nft-timestep-strategy-path: (args, num_steps, generator) -> list[int], built in drop_random_steps (default) and drop_final_steps in miles/ray/data_conversion_hub/nft.py.

Reward

Built-in scorers (--rm-type pickscore / hps / ocr / custom_api / openai_api) are documented in Rewards. --custom-rm-path replaces that dispatch entirely; --custom-reward-post-process-path replaces the normalization that runs after scoring.

--custom-rm-path

Wired only through batched_async_rm — implement per-sample routing inside your batched function if needed. Once set, --rm-type and metadata.rm_type are ignored: the custom function is the whole dispatch.
--custom-rm-args is an opaque string passed through as args.custom_rm_args for the custom RM to parse (requires --custom-rm-path). Shipped custom RMs: HTTP / remote scoring: --rm-type openai_api / custom_api (configured by --openai-api-rm-config / --custom-api-rm-config) call an external service; otherwise implement a batched custom RM and read args.rm_url (or your own flags). Encode images from sample.generated_output (see generated_output_to_rgb_hwc_uint8_frames in miles/utils/processing_utils.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. The stock diffusion rollout never calls add_samples, so this only fires when a custom rollout refills the buffer.

Training

--loss-type picks the default prepare / formula / expand paths: sft_loss auto-fills nothing: it requires the convert, rollout-log, prepare and loss paths, plus --train-only and a rollout function that runs no engines (e.g. miles.rollout.sft_rollout.generate_rollout; see scripts/run_diffusion_sft_wan22.py). custom_loss behaves like policy_loss: any hook left unset falls back to the Flow-GRPO built-in. 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. PreparedBatch.latents, timesteps and timesteps_for_model are keyed by latent stream name: "visual", plus e.g. "audio" for joint audio-video models.

--custom-loss-function-path

new_pred, old_pred and ref_pred are keyed by the same stream names as prepared.latents. old_pred is None unless --loss-type nft; ref_pred is None with --ref-mode none.

--sde-step-backend-path

Class implementing SdeStepBackend. Auto-selected from --diffusion-sde-type (sde / ode → FlowSdeStepBackend, cps → CpsSdeStepBackend) 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 / --diffusion-task / --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). The longest matching name pattern wins, so Qwen/Qwen-Image-2.1 resolves to qwen_image21. --diffusion-task (e.g. t2i) must be one of the tasks that family’s TrainPipelineConfig declares. For an unregistered family, pass --train-pipeline-config-path to a TrainPipelineConfig subclass instead.

--model-backend-path

Class for loading components / FSDP. 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 is spliced verbatim into a bash -c command line, so keep it on one line; you can also splice the flags into a forked recipe.)

Pairs well with