For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /max/get-started.md).
Python class
DiffusionPipeline
DiffusionPipelineβ
class max.pipelines.diffusion.DiffusionPipeline(pipeline_config, session, devices, weight_paths, cache_config=None, **kwargs)
Bases: ABC
Base class for diffusion pipelines.
Subclasses must define components mapping component names to ComponentModel types.
-
Parameters:
-
- pipeline_config (PipelineConfig)
- session (InferenceSession)
- devices (list[Device])
- weight_paths (list[Path])
- cache_config (DenoisingCacheConfig | None)
- kwargs (Any)
componentsβ
components: dict[str, type[ComponentModel]] | None = None
create_cache_state()β
create_cache_state(batch_size, seq_len, transformer_config, text_seq_len=0)
Create per-request cache state with fresh tensors.
-
Parameters:
-
- batch_size (int) β Batch dimension (from prompt_embeds).
- seq_len (int) β Sequence length (from latents).
- transformer_config (Any) β Transformer config carrying dimension info.
Must have
num_attention_heads,attention_head_dim,patch_size,out_channels, andin_channelsattributes. - text_seq_len (int) β Text sequence length. Reserved for cache modes that require text-aware allocations.
-
Return type:
default_num_inference_stepsβ
default_num_inference_steps: int = 50
Default number of denoising steps when the user does not specify one.
Subclasses may override this to provide a model-appropriate default.
default_residual_thresholdβ
default_residual_threshold: float = 0.05
Model-specific default for the FBCache relative difference threshold.
Subclasses may override this to provide a model-appropriate default.
Used when the request does not specify a residual_threshold.
default_taylorseer_cache_intervalβ
default_taylorseer_cache_interval: int = 5
Model-specific default for the TaylorSeer cache interval.
Subclasses may override this to provide a model-appropriate default.
Used when DenoisingCacheConfig.taylorseer_cache_interval is None.
default_taylorseer_max_orderβ
default_taylorseer_max_order: int = 1
Model-specific default for the TaylorSeer expansion order.
Subclasses may override this to provide a model-appropriate default.
Used when DenoisingCacheConfig.taylorseer_max_order is None.
default_taylorseer_warmup_stepsβ
default_taylorseer_warmup_steps: int = 9
Model-specific default for the TaylorSeer warmup steps.
Subclasses may override this to provide a model-appropriate default.
Used when DenoisingCacheConfig.taylorseer_warmup_steps is None.
execute()β
abstract execute(model_inputs, **kwargs)
Execute the pipeline with the given model inputs.
-
Parameters:
-
Returns:
-
A DiffusionPipelineOutput containing NHWC uint8 images.
-
Return type:
init_remaining_components()β
abstract init_remaining_components()
Initialize non-ComponentModel components (e.g., image processors).
-
Return type:
-
None
prepare_inputs()β
abstract prepare_inputs(context)
Prepare inputs for the pipeline.
-
Parameters:
-
context (PixelGenerationContext)
-
Return type:
run_denoising_step()β
run_denoising_step(step, cache_state, device, **kwargs)
Execute one denoising step with caching logic.
Delegates the actual transformer call to self.run_transformer(),
which subclasses override with model-specific arguments.
-
Parameters:
-
- step (int) β Current step index.
- cache_state (DenoisingCacheState) β Per-request mutable cache state for this stream.
- device (Device) β Target device.
- **kwargs (Any) β Model-specific arguments forwarded to
run_transformer.
-
Returns:
-
noise_pred tensor for this step.
-
Return type:
run_transformer()β
run_transformer(cache_state, **kwargs)
Run the transformer for one denoising step.
Subclasses must override this to call their transformer with the
appropriate model-specific arguments. The method should return
(noise_pred,) when first_block_caching is disabled, or
(new_residual, noise_pred) when first_block_caching is enabled.
-
Parameters:
-
- cache_state (DenoisingCacheState) β Per-request mutable cache state for this stream.
- **kwargs (Any) β Model-specific arguments forwarded from
run_denoising_step.
-
Return type:
unprefixed_weight_componentβ
When set, weight files without a <component>/ prefix are assigned to
this component. This supports multi-repo layouts where quantized weights
for one component (e.g. the transformer) are shipped as flat files in a
separate repo while the remaining components use the base model repo.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!