scheduling_rcm ¶
Classes¶
fastvideo.models.schedulers.scheduling_rcm.RCMScheduler ¶
RCMScheduler(num_train_timesteps: int = 1000, sigma_max: float = 80.0, mid_timesteps: list[float] | None = None)
Bases: SchedulerMixin, ConfigMixin, BaseScheduler
rCM (recurrent Consistency Model) scheduler for TurboDiffusion.
This scheduler implements the rCM sampling method which enables 1-4 step video generation using distilled checkpoints. It uses: 1. TrigFlow → RectifiedFlow timestep conversion 2. SDE sampling formula: x = (1 - t_next) * (x - t_cur * v_pred) + t_next * noise
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_train_timesteps | `int`, defaults to 1000 | The number of diffusion steps used to train the model. | 1000 |
sigma_max | `float`, defaults to 80.0 | The initial sigma value for rCM sampling. Controls the noise level at the start of sampling. | 80.0 |
mid_timesteps | `list[float]`, *optional* | Custom intermediate timesteps. If None, uses optimized defaults [1.5, 1.4, 1.0] for better visual quality. | None |
Source code in fastvideo/models/schedulers/scheduling_rcm.py
Attributes¶
fastvideo.models.schedulers.scheduling_rcm.RCMScheduler.begin_index property ¶
begin_index: int | None
The index for the first timestep.
fastvideo.models.schedulers.scheduling_rcm.RCMScheduler.init_noise_sigma property ¶
init_noise_sigma: float
Initial noise sigma for scaling latents.
In rCM, initial noise is scaled by the first sigma value: x_0 = noise * sigmas[0]
This property is used by LatentPreparationStage to scale initial latents.
fastvideo.models.schedulers.scheduling_rcm.RCMScheduler.step_index property ¶
step_index: int | None
The index counter for current timestep. Increases by 1 after each scheduler step.
Methods:¶
fastvideo.models.schedulers.scheduling_rcm.RCMScheduler.add_noise ¶
Add noise to samples (forward diffusion process).
Not typically used for rCM inference, but provided for API compatibility.
Source code in fastvideo/models/schedulers/scheduling_rcm.py
fastvideo.models.schedulers.scheduling_rcm.RCMScheduler.scale_model_input ¶
scale_model_input(sample: Tensor, timestep: int | None = None) -> Tensor
rCM doesn't scale model input, returns sample as-is.
fastvideo.models.schedulers.scheduling_rcm.RCMScheduler.scale_noise ¶
scale_noise(sample: FloatTensor, timestep: FloatTensor | None = None, noise: FloatTensor | None = None) -> FloatTensor
Scale initial noise for rCM sampling.
In rCM, initial noise is scaled by the first timestep (raw sigma): x_0 = noise * t_steps[0]
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample | FloatTensor | Not used (for API compatibility) | required |
timestep | FloatTensor | None | Not used (for API compatibility) | None |
noise | FloatTensor | None | The noise tensor to scale | None |
Returns:
| Type | Description |
|---|---|
FloatTensor | Scaled noise tensor ready for sampling |
Source code in fastvideo/models/schedulers/scheduling_rcm.py
fastvideo.models.schedulers.scheduling_rcm.RCMScheduler.set_begin_index ¶
set_begin_index(begin_index: int = 0) -> None
Sets the begin index for the scheduler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
begin_index | `int` | The begin index for the scheduler. | 0 |
fastvideo.models.schedulers.scheduling_rcm.RCMScheduler.set_timesteps ¶
set_timesteps(num_inference_steps: int, device: str | device | None = None, sigma_max: float | None = None) -> None
Sets the discrete timesteps used for the rCM sampling process.
The timesteps are computed using TrigFlow → RectifiedFlow conversion: 1. Start with atan(sigma_max) and intermediate values 2. Convert via: t = sin(t) / (cos(t) + sin(t))
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_inference_steps | `int` | The number of diffusion steps (1-4 for rCM). | required |
device | `str` or `torch.device`, *optional* | The device to move timesteps to. | None |
sigma_max | `float`, *optional* | Override the initial sigma value. | None |
Source code in fastvideo/models/schedulers/scheduling_rcm.py
fastvideo.models.schedulers.scheduling_rcm.RCMScheduler.step ¶
step(model_output: FloatTensor, timestep: int | Tensor, sample: FloatTensor, generator: Generator | None = None, return_dict: bool = True) -> RCMSchedulerOutput | tuple[FloatTensor, ...]
Predict the sample from the previous timestep using rCM update rule.
The rCM update formula is
x_{t+1} = (1 - t_next) * (x_t - t_cur * v_pred) + t_next * noise
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_output | `torch.FloatTensor` | The velocity prediction from the model (v_pred). | required |
timestep | `int` or `torch.Tensor` | The current timestep index (not the actual timestep value). For rCM, this should be the index into self.timesteps. | required |
sample | `torch.FloatTensor` | Current sample x_t. | required |
generator | `torch.Generator`, *optional* | Random number generator for noise. | None |
return_dict | `bool` | Whether to return RCMSchedulerOutput or tuple. | True |
Returns:
| Type | Description |
|---|---|
RCMSchedulerOutput | tuple[FloatTensor, ...] |
|
Source code in fastvideo/models/schedulers/scheduling_rcm.py
fastvideo.models.schedulers.scheduling_rcm.RCMSchedulerOutput dataclass ¶
Bases: BaseOutput
Output class for the RCM scheduler's step function output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prev_sample | `torch.FloatTensor` of shape `(batch_size, num_channels, ...)` | Computed sample | required |