IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /get-started.md).

Python module

max.pipelines.architectures.wan

Wan diffusion architecture for video generation.

BlockLevelModel

class max.pipelines.architectures.wan.BlockLevelModel(pre, post, *, combined_blocks)

source

Bases: object

Executes transformer forward pass as pre -> combined blocks -> post.

All transformer blocks are compiled into a single Model graph, so the runtime allocates one shared workspace.

Parameters:

WanArchConfig

class max.pipelines.architectures.wan.WanArchConfig(*, pipeline_config, quantization_encoding=None)

source

Bases: ArchConfig

Pipeline-level config for Wan (implements ArchConfig; no KV cache).

Parameters:

DEFAULT_ENCODING

DEFAULT_ENCODING: ClassVar[SupportedEncoding] = 'bfloat16'

source

SUPPORTED_ENCODINGS

SUPPORTED_ENCODINGS: ClassVar[set[SupportedEncoding]] = {'bfloat16', 'float32', 'float8_e4m3fn'}

source

get_max_seq_len()

get_max_seq_len()

source

Returns the default maximum sequence length for the model.

Subclasses should determine whether this value can be overridden by setting the --max-length (pipeline_config.model.max_length) flag.

Return type:

int

initialize()

classmethod initialize(pipeline_config, model_config=None)

source

Initialize the config from a PipelineConfig.

Parameters:

  • pipeline_config (PipelineConfig) – The pipeline configuration.
  • model_config (MAXModelConfig | None) – The model configuration to read from. When None (the default), pipeline_config.model is used. Pass an explicit config (e.g. pipeline_config.draft_model) to initialize the arch config for a different model.

Return type:

Self

pipeline_config

pipeline_config: PipelineConfig

source

quantization_encoding

quantization_encoding: SupportedEncoding | None = None

source

WanConfig

class max.pipelines.architectures.wan.WanConfig(*, config_file=None, section_name=None, patch_size=(1, 2, 2), num_attention_heads=40, attention_head_dim=128, in_channels=16, out_channels=16, text_dim=4096, freq_dim=256, ffn_dim=13824, num_layers=40, cross_attn_norm=True, qk_norm='rms_norm_across_heads', eps=1e-06, image_dim=None, added_kv_proj_dim=None, rope_max_seq_len=1024, pos_embed_seq_len=None, dtype=bfloat16, device=<factory>, quant_config=None)

source

Bases: WanConfigBase

Parameters:

  • config_file (str | None)
  • section_name (str | None)
  • patch_size (tuple[int, int, int])
  • num_attention_heads (int)
  • attention_head_dim (int)
  • in_channels (int)
  • out_channels (int)
  • text_dim (int)
  • freq_dim (int)
  • ffn_dim (int)
  • num_layers (int)
  • cross_attn_norm (bool)
  • qk_norm (str | None)
  • eps (float)
  • image_dim (int | None)
  • added_kv_proj_dim (int | None)
  • rope_max_seq_len (int)
  • pos_embed_seq_len (int | None)
  • dtype (DType)
  • device (DeviceRef)
  • quant_config (QuantConfig | None)

generate()

static generate(config_dict, encoding, devices)

source

Parameters:

  • config_dict (dict[str, Any])
  • encoding (Literal['float32', 'float16', 'bfloat16', 'q4_k', 'q4_0', 'q6_k', 'float8_e4m3fn', 'float4_e2m1fnx2', 'gptq'])
  • devices (list[Device])

Return type:

WanConfig

model_config

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'strict': False}

source

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

WanConfigBase

class max.pipelines.architectures.wan.WanConfigBase(*, config_file=None, section_name=None, patch_size=(1, 2, 2), num_attention_heads=40, attention_head_dim=128, in_channels=16, out_channels=16, text_dim=4096, freq_dim=256, ffn_dim=13824, num_layers=40, cross_attn_norm=True, qk_norm='rms_norm_across_heads', eps=1e-06, image_dim=None, added_kv_proj_dim=None, rope_max_seq_len=1024, pos_embed_seq_len=None, dtype=bfloat16, device=<factory>, quant_config=None)

source

Bases: MAXModelConfigBase

Parameters:

  • config_file (str | None)
  • section_name (str | None)
  • patch_size (tuple[int, int, int])
  • num_attention_heads (int)
  • attention_head_dim (int)
  • in_channels (int)
  • out_channels (int)
  • text_dim (int)
  • freq_dim (int)
  • ffn_dim (int)
  • num_layers (int)
  • cross_attn_norm (bool)
  • qk_norm (str | None)
  • eps (float)
  • image_dim (int | None)
  • added_kv_proj_dim (int | None)
  • rope_max_seq_len (int)
  • pos_embed_seq_len (int | None)
  • dtype (DType)
  • device (DeviceRef)
  • quant_config (QuantConfig | None)

added_kv_proj_dim

added_kv_proj_dim: int | None

source

attention_head_dim

attention_head_dim: int

source

cross_attn_norm

cross_attn_norm: bool

source

device

device: DeviceRef

source

dtype

dtype: DType

source

eps

eps: float

source

ffn_dim

ffn_dim: int

source

freq_dim

freq_dim: int

source

image_dim

image_dim: int | None

source

in_channels

in_channels: int

source

model_config

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'strict': False}

source

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

num_attention_heads

num_attention_heads: int

source

num_layers

num_layers: int

source

out_channels

out_channels: int

source

patch_size

patch_size: tuple[int, int, int]

source

pos_embed_seq_len

pos_embed_seq_len: int | None

source

qk_norm

qk_norm: str | None

source

quant_config

quant_config: QuantConfig | None

source

Static per-tensor FP8 quantization config, populated when the transformer encoding is float8_e4m3fn. None for bfloat16.

rope_max_seq_len

rope_max_seq_len: int

source

text_dim

text_dim: int

source