Skip to content

vllm_omni.diffusion.models.magi2.conditioning

Native MAGI-2 prompt conditioning.

Adapted from SandAI's MAGI-2 Preview inference implementation. The model loading remains in-tree and uses the Transformers Qwen3.5 implementation; no MAGI-2 reference checkout is imported at runtime.

Magi2Qwen35TextEncoder

Bases: Module

Qwen3.5-27B feature extractor used by MAGI-2 Preview.

forward class-attribute instance-attribute

forward = encode

max_length instance-attribute

max_length = max_length

skip_layer instance-attribute

skip_layer = skip_layer

text_model instance-attribute

text_model = Qwen3_5TextModel.from_pretrained(
    model_path,
    torch_dtype=dtype,
    local_files_only=local_files_only,
)

tokenizer instance-attribute

tokenizer = AutoTokenizer.from_pretrained(
    model_path,
    padding_side="right",
    local_files_only=local_files_only,
)

encode

encode(prompt: str) -> Tensor

get_target_token_indices

get_target_token_indices(
    prompt: str, target: str | None
) -> list[int] | None

pool_figure_tokens

pool_figure_tokens(
    prompt: str, targets: list[str], text_features: Tensor
) -> Tensor

Mean-pool the token features spelling each <Figure N> marker.

json_to_compact_markdown

json_to_compact_markdown(
    raw_json: str | dict[str, Any],
) -> str

Convert MAGI's structured prompt JSON into its training-time text form.

normalize_prompt

normalize_prompt(prompt: str) -> str

Normalize structured prompts while leaving ordinary text byte-for-byte intact.