# Qwen-Image 2.1

Qwen-Image 2.1 mã hóa prompt và các ảnh điều kiện cùng với một mô hình Qwen3-VL, sau đó khử nhiễu ảnh đích bằng một transformer block-causal single-stream. Xem [`QwenImage21Transformer2DModel`](../models/qwenimage21_transformer2d) để tìm hiểu về block-causal attention, các attention processor và `causal_condition`.

Mặc định là các giá trị do Qwen khuyến nghị: 40 bước và không có guidance. Truyền `negative_prompt` cùng với `true_cfg_scale > 1` để bật classifier-free guidance, điều này làm tăng gấp đôi khối lượng công việc cho mỗi bước.

```python
import torch
from diffusers import QwenImage21Pipeline

pipe = QwenImage21Pipeline.from_pretrained("Qwen/Qwen-Image-2.1", dtype=torch.bfloat16).to("cuda")

# Text-to-image
image = pipe("A capybara wearing a wizard hat, oil painting").images[0]
image.save("t2i.png")

# Image-conditioned editing
edited = pipe("Move it to a snowy mountain top", image=image).images[0]
edited.save("edit.png")
```

## Nhiều ảnh điều kiện

Truyền một danh sách vào `image` và mỗi mục sẽ trở thành một khối riêng biệt trong chuỗi kết hợp: bộ mã hóa Qwen3-VL sẽ xem chúng như ngữ cảnh thị giác và VAE sẽ đóng góp các token tiềm ẩn của chúng. Cơ chế chú ý nhân quả theo khối giữ cho mỗi khối có tính hai chiều bên trong trong khi cho phép các khối sau và hình ảnh đích chú ý đến các khối trước, do đó thứ tự bạn truyền vào chính là thứ tự mô hình đọc chúng.

```python
edited = pipe("Put the flowers from the first image into the second scene", image=[flowers, scene]).images[0]
```

## Chú ý nhanh hơn với flex_attention

The default `QwenImage21AttnProcessor` runs the block-causal prefill as one attention call per prefix segment. It needs no compilation and works on any PyTorch build. `QwenImage21FlexAttnProcessor` expresses the same mask as a single `flex_attention` call, which is faster once the model is **_compiled_**.

> [!TIP]
> Biên dịch mô hình khi bạn chuyển sang bộ xử lý linh hoạt. `flex_attention` chưa được biên dịch sẽ tạo ra ma trận điểm chú ý đầy đủ ở fp32, điều này chậm hơn nhiều và hết bộ nhớ ở độ phân giải cao.

```python
from diffusers.models.transformers.transformer_qwenimage21 import QwenImage21FlexAttnProcessor

pipe.transformer.set_attn_processor(QwenImage21FlexAttnProcessor())
pipe.transformer.compile()
```

## Tải checkpoint dạng tệp đơn

```python
import torch
from diffusers import QwenImage21Pipeline, QwenImage21Transformer2DModel

transformer = QwenImage21Transformer2DModel.from_single_file(
    "https://huggingface.co/Comfy-Org/Qwen-Image-2.1/blob/main/diffusion_models/qwen_image_2.1_bf16.safetensors",
    dtype=torch.bfloat16,
)
pipe = QwenImage21Pipeline.from_pretrained("Qwen/Qwen-Image-2.1", transformer=transformer, dtype=torch.bfloat16).to(
    "cuda"
)
```

## Các sigma lấy mẫu

Tác giả mô hình có thể cấu hình lưới lấy mẫu mặc định bằng `sample_sigmas` trong cấu hình pipeline. Khi bạn tải một checkpoint đã phát hành, lưới mặc định và cài đặt scheduler của nó sẽ được khôi phục tự động.

Để thử nghiệm với một lưới khác trong thời gian chạy, hãy truyền `sigmas` vào lệnh gọi pipeline:

```python
# Use the checkpoint's default sampling grid.
image = pipe(prompt).images[0]

# Override the default grid for this call.
image = pipe(prompt, sigmas=[1.0, 0.8, 0.5, 0.2]).images[0]
```

Lưới tùy chỉnh ở trên minh họa cho API; chất lượng sinh phụ thuộc vào checkpoint và lưới. Các danh sách sigma không bao gồm sigma cuối cùng, phần tử mà trình lập lịch sẽ thêm vào. Giá trị `sigmas` được chỉ định rõ ràng sẽ ghi đè lên `sample_sigmas` đã cấu hình, và danh sách nào được cung cấp cũng sẽ xác định số bước thay vì `num_inference_steps`. Nếu không có danh sách nào được cung cấp, pipeline sẽ sử dụng `num_inference_steps` để tạo lịch trình. Trình lập lịch sẽ áp dụng các xử lý đã cấu hình của nó lên cả hai lưới.

## Modular

Qwen-Image 2.1 cũng có sẵn dưới dạng [pipeline module hóa](../../modular_diffusers/overview). Các khối giống nhau chạy cả sinh ảnh từ văn bản lẫn sinh ảnh có điều kiện từ ảnh: truyền `image` để điều kiện hóa dựa trên một hoặc nhiều ảnh. Hướng dẫn không phân loại (classifier-free guidance) được cấu hình thông qua thành phần `guider` thay vì đối số gọi `true_cfg_scale`, và bộ nhớ đệm KV tiền tố được bật theo mặc định (`use_kv_cache=False` để tắt).

```python
import torch
from diffusers import ClassifierFreeGuidance, ModularPipeline

pipe = ModularPipeline.from_pretrained("Qwen/Qwen-Image-2.1")
pipe.load_components(dtype=torch.bfloat16)
pipe.to("cuda")

image = pipe(prompt="A capybara wearing a wizard hat, oil painting").images[0]

# Turn classifier-free guidance on for an edit.
pipe.update_components(guider=ClassifierFreeGuidance(guidance_scale=4.0))
edited = pipe(prompt="Move it to a snowy mountain top", negative_prompt="blurry", image=image).images[0]
```

Checkpoint Turbo được ánh xạ đến các khối riêng của nó ([QwenImage21TurboAutoBlocks](/docs/diffusers/main/vi/api/pipelines/qwenimage21#diffusers.QwenImage21TurboAutoBlocks)): nó chạy mà không có `guider`, không nhận `negative_prompt`, và lấy mẫu lưới sigma đi kèm. `ModularPipeline.from_pretrained` chọn các khối Turbo từ mục `sample_sigmas` trong cấu hình của checkpoint, vì vậy không cần cấu hình gì thêm:

```python
import torch
from diffusers import ModularPipeline

pipe = ModularPipeline.from_pretrained("Qwen/Qwen-Image-2.1-Turbo")
pipe.load_components(dtype=torch.bfloat16)
pipe.to("cuda")

image = pipe(prompt="A capybara wearing a wizard hat, oil painting").images[0]
```

## QwenImage21Pipeline[[diffusers.QwenImage21Pipeline]]

#### diffusers.QwenImage21Pipeline[[diffusers.QwenImage21Pipeline]]

```python
diffusers.QwenImage21Pipeline(scheduler: FlowMatchEulerDiscreteScheduler, vae: AutoencoderKLQwenImage21, text_encoder: Qwen3VLForConditionalGeneration, processor: Qwen3VLProcessor, transformer: QwenImage21Transformer2DModel, sample_sigmas: list[float] | None = None)
```

[Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/qwenimage21/pipeline_qwenimage21.py#L159)

**Tham số:**

scheduler ([FlowMatchEulerDiscreteScheduler](/docs/diffusers/main/vi/api/schedulers/flow_match_euler_discrete#diffusers.FlowMatchEulerDiscreteScheduler)) : Trình lập lịch được sử dụng để khử nhiễu các biến tiềm ẩn (latents) của ảnh đã mã hóa.

vae ([AutoencoderKLQwenImage21](/docs/diffusers/main/vi/api/models/autoencoderkl_qwenimage21#diffusers.AutoencoderKLQwenImage21)) : Autoencoder biến phân ánh xạ hình ảnh tới và từ không gian tiềm ẩn 64 kênh.

text_encoder (`Qwen3VLForConditionalGeneration`) : Mô hình Qwen3-VL tạo ra các embedding kết hợp văn bản/hình ảnh.

processor (`Qwen3VLProcessor`) : Bộ xử lý xây dựng mẫu trò chuyện và mã hóa token cho prompt cùng hình ảnh điều kiện.

transformer ([QwenImage21Transformer2DModel](/docs/diffusers/main/vi/api/models/qwenimage21_transformer2d#diffusers.QwenImage21Transformer2DModel)) : Transformer dạng khối nhân quả đơn luồng dùng để khử nhiễu các biến tiềm ẩn.

sample_sigmas (`list[float]`, *optional*) : Các sigma lấy mẫu mặc định do tác giả mô hình cấu hình, không bao gồm sigma cuối cùng. Độ dài của chúng xác định số bước khử nhiễu. Để thử nghiệm với một lưới khác khi chạy, hãy truyền `sigmas` vào `__call__`.

Tạo ảnh từ văn bản và tạo ảnh có điều kiện từ ảnh với Qwen-Image 2.1.

Hình ảnh prompt và hình ảnh điều kiện được mã hóa cùng nhau bởi mô hình Qwen3-VL, do đó hình ảnh điều kiện chiếm các khe thị giác mà bộ mã hóa đã dành riêng cho nó và transformer nhìn thấy một chuỗi văn bản/hình ảnh xen kẽ.

#### __call__[[diffusers.QwenImage21Pipeline.__call__]]

```python
__call__(prompt: str | list[str] = None, image: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor], NoneType] = None, negative_prompt: str | list[str] = None, true_cfg_scale: float = 1.0, height: int | None = None, width: int | None = None, num_inference_steps: int = 40, sigmas: list[float] | None = None, num_images_per_prompt: int = 1, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None, latents: typing.Optional[torch.Tensor] = None, prompt_embeds: typing.Optional[torch.Tensor] = None, prompt_embeds_mask: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds_mask: typing.Optional[torch.Tensor] = None, output_type: str | None = 'pil', return_dict: bool = True, attention_kwargs: dict[str, typing.Any] | None = None, callback_on_step_end: typing.Optional[typing.Callable[[int, int, dict], NoneType]] = None, callback_on_step_end_tensor_inputs: list[str] = ['latents'], output_resolution: int = 1024, use_kv_cache: bool = True)
```

[Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/qwenimage21/pipeline_qwenimage21.py#L509)

**Tham số:**

prompt (`str` hoặc `list[str]`, *tùy chọn*) : Prompt để hướng dẫn tạo ảnh. Truyền `prompt_embeds` thay vào đó để cung cấp trực tiếp các embedding.

image (`PipelineImageInput`, *tùy chọn*) : Một hoặc nhiều ảnh điều kiện, dưới dạng ảnh PIL hoặc mảng numpy. Chúng được mã hóa bởi text encoder như ngữ cảnh thị giác và bởi VAE thành các token tiềm ẩn được đặt trước tiếng ồn. Một danh sách là một bộ ảnh được chia sẻ bởi mọi prompt trong batch, không phải một mục cho mỗi prompt.

negative_prompt (`str` hoặc `list[str]`, *tùy chọn*) : Prompt không dùng để hướng dẫn tạo ảnh. Bị bỏ qua khi `true_cfg_scale` không lớn hơn 1.

true_cfg_scale (`float`, *optional*, mặc định là 1.0) : Thang độ hướng dẫn phân loại không có điều kiện. Được kích hoạt bởi `true_cfg_scale > 1` cùng với một prompt âm. Qwen-Image 2.1 được thiết kế để lấy mẫu mà không cần hướng dẫn, do đó giá trị mặc định là 1.0.

height (`int`, *tùy chọn*) : Chiều cao của hình ảnh được tạo ra, tính bằng pixel. Nếu bỏ trống, giá trị này sẽ được suy ra từ tỷ lệ khung hình của hình ảnh điều kiện.

width (`int`, *tuỳ chọn*) : Độ rộng tính bằng pixel của hình ảnh được tạo ra. Nếu bỏ trống, giá trị này sẽ được suy ra từ tỷ lệ khung hình của hình ảnh điều kiện.

num_inference_steps (`int`, *optional*, mặc định là 40) : Số bước khử nhiễu. Bỏ qua khi sử dụng `sigmas` hoặc `sample_sigmas` được cấu hình sẵn của pipeline; độ dài của lịch trình đó sẽ xác định số bước.

sigmas (`list[float]`, *optional*) : Các sigma lấy mẫu cần thử cho lần gọi này, không bao gồm sigma cuối cùng. Ghi đè `sample_sigmas` đã cấu hình của pipeline và xác định số bước khử nhiễu. Scheduler sẽ áp dụng các xử lý đã cấu hình lên các giá trị này.

num_images_per_prompt (`int`, *tuỳ chọn*, mặc định là 1) : Số lượng hình ảnh được tạo cho mỗi prompt.

generator (`torch.Generator` hoặc `list[torch.Generator]`, *tùy chọn*) : Bộ tạo (Generator) để làm cho quá trình sinh ra kết quả xác định.

latents (`torch.Tensor`, *tùy chọn*) : Các latents nhiễu đã được tạo trước.

prompt_embeds (`torch.Tensor`, *tùy chọn*) : Các vector nhúng văn bản đã được tạo trước, giúp bỏ qua bước mã hóa prompt. Hãy truyền `prompt_embeds_mask` cùng với chúng.

prompt_embeds_mask (`torch.Tensor`, *tùy chọn*) : Mặt nạ Bool đánh dấu các vị trí hợp lệ của `prompt_embeds`.

negative_prompt_embeds (`torch.Tensor`, *tùy chọn*) : Các vector nhúng văn bản âm đã tạo trước, được sử dụng thay cho `negative_prompt`. Hãy truyền `negative_prompt_embeds_mask` cùng với chúng.

negative_prompt_embeds_mask (`torch.Tensor`, *tùy chọn*) : Mặt nạ Bool đánh dấu các vị trí hợp lệ của `negative_prompt_embeds`.

output_type (`str`, *tùy chọn*, mặc định là `"pil"`) : Định dạng đầu ra, `"pil"`, `"np"`, `"pt"` hoặc `"latent"`.

return_dict (`bool`, *tùy chọn*, mặc định là `True`) : Có nên trả về một `~pipelines.qwenimage.QwenImagePipelineOutput` thay vì một tuple thông thường hay không.

attention_kwargs (`dict`, *tùy chọn*) : Được truyền qua cho bộ xử lý chú ý.

callback_on_step_end (`Callable`, *tùy chọn*) : Được gọi vào cuối mỗi bước khử nhiễu.

callback_on_step_end_tensor_inputs (`list[str]`, *tùy chọn*, mặc định là `["latents"]`) : Các tensor từ vòng lặp khử nhiễu để truyền cho `callback_on_step_end`. Chúng phải được liệt kê trong `_callback_tensor_inputs` của pipeline.

output_resolution (`int`, *optional*, mặc định là 1024) : Độ dài cạnh đích được dùng để suy ra `height`/`width` và để thay đổi kích thước ảnh điều kiện.

use_kv_cache (`bool`, *tuỳ chọn*, mặc định là `True`) : Lưu cache các key và value của text và ảnh điều kiện sau bước đầu tiên. Hợp lệ vì `causal_condition` điều chế các token đó từ `t = 0`, khiến các kích hoạt của chúng không phụ thuộc vào bước. Việc bật/tắt tuỳ chọn này không tái tạo được cùng một ảnh bit-for-bit ở độ chính xác giảm. Lưu cache khiến bước decode chú ý đến một bố trí trình tự khác so với bước prefill, do đó hai bước này chia tile khác nhau và rơi vào các phép làm tròn khác nhau; cả hai đều khớp với tham chiếu fp32 ở cùng mức dung sai. Một sự khác biệt một-ULP ở khối đầu tiên sau đó bị khuếch đại bởi 32 khối và mỗi bước của sampler, do đó hai cài đặt cho ra các mẫu hợp lệ như nhau nhưng khác biệt rõ rệt về mặt thị giác. Hãy cố định một mẫu bằng cách cố định cờ này.

**Trả về:** `~pipelines.qwenimage.QwenImagePipelineOutput` hoặc `tuple`

`~pipelines.qwenimage.QwenImagePipelineOutput` nếu `return_dict` là True, ngược lại là một `tuple` mà phần tử đầu tiên là một danh sách chứa các hình ảnh đã tạo.

Hàm được gọi khi gọi pipeline cho việc sinh.

Ví dụ:
```py
>>> import torch
>>> from diffusers import QwenImage21Pipeline

>>> pipe = QwenImage21Pipeline.from_pretrained("Qwen/Qwen-Image-2.1", dtype=torch.bfloat16)
>>> pipe.to("cuda")
>>> prompt = "A capybara wearing a wizard hat, reading a book by candlelight, oil painting"
>>> image = pipe(prompt).images[0]
>>> image.save("qwenimage21.png")
```

#### encode_prompt[[diffusers.QwenImage21Pipeline.encode_prompt]]

```python
encode_prompt(prompt: str | list[str], image: list[typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor]]] | None = None, device: typing.Optional[torch.device] = None, num_images_per_prompt: int = 1, prompt_embeds: typing.Optional[torch.Tensor] = None, prompt_embeds_mask: typing.Optional[torch.Tensor] = None, image_pad_mask: typing.Optional[torch.Tensor] = None)
```

[Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/qwenimage21/pipeline_qwenimage21.py#L339)

**Tham số:**

prompt (`str` hoặc `list[str]`, *tùy chọn*) : Prompt cần được mã hóa.

image (`list[PipelineImageInput]`, *tùy chọn*) : Các ảnh điều kiện để mã hóa cùng với prompt.

device (`torch.device`) : Thiết bị Torch.

num_images_per_prompt (`int`) : Số lượng hình ảnh được tạo cho mỗi prompt.

prompt_embeds (`torch.Tensor`, *tùy chọn*) : Các vector nhúng văn bản đã được tạo trước. Bỏ qua bước mã hóa nếu được cung cấp.

## QwenImagePipelineOutput[[diffusers.pipelines.qwenimage.pipeline_output.QwenImagePipelineOutput]]

#### diffusers.pipelines.qwenimage.pipeline_output.QwenImagePipelineOutput[[diffusers.pipelines.qwenimage.pipeline_output.QwenImagePipelineOutput]]

```python
diffusers.pipelines.qwenimage.pipeline_output.QwenImagePipelineOutput(images: list[PIL.Image.Image] | numpy.ndarray)
```

[Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/qwenimage/pipeline_output.py#L10)

**Tham số:**

images (`list[PIL.Image.Image]` hoặc `np.ndarray`) : danh sách các hình ảnh PIL đã khử nhiễu có độ dài `batch_size` hoặc mảng numpy có hình dạng `(batch_size, height, width, num_channels)`. Các hình ảnh PIL hoặc mảng numpy thể hiện các hình ảnh đã khử nhiễu của pipeline khuếch tán.

Lớp đầu ra cho các pipeline Stable Diffusion.

## QwenImage21ModularPipeline[[diffusers.QwenImage21ModularPipeline]]

#### diffusers.QwenImage21ModularPipeline[[diffusers.QwenImage21ModularPipeline]]

```python
diffusers.QwenImage21ModularPipeline(blocks: diffusers.modular_pipelines.modular_pipeline.ModularPipelineBlocks | None = None, pretrained_model_name_or_path: str | os.PathLike | None = None, components_manager: diffusers.modular_pipelines.components_manager.ComponentsManager | None = None, collection: str | None = None, workflow: str | None = None, modular_config_dict: dict[str, typing.Any] | None = None, config_dict: dict[str, typing.Any] | None = None, **kwargs)
```

[Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/modular_pipelines/qwenimage21/modular_pipeline.py#L23)

Một ModularPipeline cho Qwen-Image 2.1.

## QwenImage21AutoBlocks[[diffusers.QwenImage21AutoBlocks]]

#### diffusers.QwenImage21AutoBlocks[[diffusers.QwenImage21AutoBlocks]]

```python
diffusers.QwenImage21AutoBlocks()
```

[Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/modular_pipelines/qwenimage21/modular_blocks_qwenimage21.py#L497)

Auto Modular pipeline cho việc tạo ảnh từ văn bản và tạo ảnh có điều kiện từ ảnh bằng Qwen-Image 2.1.
- để tạo ảnh từ văn bản, bạn chỉ cần cung cấp `prompt`
- cho tạo hình ảnh có điều kiện, bạn cần cung cấp `prompt` và `image` (một hình ảnh hoặc một danh sách)

Các quy trình làm việc được hỗ trợ:
- `text2image`: yêu cầu `prompt`
- `image_conditioned`: yêu cầu `prompt`, `image`

Các thành phần: image_processor (`VaeImageProcessor`) text_encoder (`Qwen3VLForConditionalGeneration`) processor (`Qwen3VLProcessor`) vae (`AutoencoderKLQwenImage21`) scheduler (`FlowMatchEulerDiscreteScheduler`) guider (`ClassifierFreeGuidance`) transformer (`QwenImage21Transformer2DModel`)

Inputs: image (`Image | list`, *tùy chọn*): Ảnh tham chiếu để khử nhiễu. Có thể là một ảnh duy nhất hoặc danh sách các ảnh. output_resolution (`int`, *tùy chọn*, mặc định là 1024): Độ dài cạnh mục tiêu dùng để suy ra kích thước đầu ra và để thay đổi kích thước các ảnh điều kiện. prompt (`str`): Câu lệnh hoặc các câu lệnh để định hướng việc tạo ảnh. negative_prompt (`str`, *tùy chọn*): Câu lệnh hoặc các câu lệnh không dùng để định hướng việc tạo ảnh. generator (`Generator`, *tùy chọn*): Bộ tạo Torch cho việc tạo ảnh tất định. num_images_per_prompt (`int`, *tùy chọn*, mặc định là 1): Số lượng ảnh cần tạo cho mỗi câu lệnh. height (`int`, *tùy chọn*): Chiều cao tính bằng pixel của ảnh được tạo. width (`int`, *tùy chọn*): Chiều rộng tính bằng pixel của ảnh được tạo. image_latents (`list`, *tùy chọn*): Các latents đã chuẩn hóa của từng ảnh điều kiện. Có thể được tạo từ bước vae_encoder. latents (`Tensor`): Các latents nhiễu đã tạo trước cho việc tạo ảnh. num_inference_steps (`int`): Số bước khử nhiễu. sigmas (`list`, *tùy chọn*): Các sigmas tùy chỉnh cho quá trình khử nhiễu. use_kv_cache (`bool`, *tùy chọn*, mặc định là True): Lưu trữ bộ nhớ đệm các khóa và giá trị của văn bản và ảnh điều kiện sau bước đầu tiên. Điều này hợp lệ vì `causal_condition` điều biến các token đó từ `t = 0`, khiến các kích hoạt của chúng không phụ thuộc vào bước. Việc bật/tắt tùy chọn này không tái tạo cùng một ảnh khớp từng bit ở độ chính xác giảm. attention_kwargs (`dict`, *tùy chọn*): Các kwargs bổ sung cho các bộ xử lý attention. **denoiser_input_fields (`None`, *tùy chọn*): các đầu vào của mô hình điều kiện cho bộ khử nhiễu: ví dụ prompt_embeds, negative_prompt_embeds, v.v. output_type (`str`, *tùy chọn*, mặc định là pil): Định dạng đầu ra: 'pil', 'np', 'pt'.

Đầu ra: hình ảnh (`list`): Các hình ảnh được tạo ra.

## QwenImage21TurboModularPipeline[[diffusers.QwenImage21TurboModularPipeline]]

#### diffusers.QwenImage21TurboModularPipeline[[diffusers.QwenImage21TurboModularPipeline]]

```python
diffusers.QwenImage21TurboModularPipeline(blocks: diffusers.modular_pipelines.modular_pipeline.ModularPipelineBlocks | None = None, pretrained_model_name_or_path: str | os.PathLike | None = None, components_manager: diffusers.modular_pipelines.components_manager.ComponentsManager | None = None, collection: str | None = None, workflow: str | None = None, modular_config_dict: dict[str, typing.Any] | None = None, config_dict: dict[str, typing.Any] | None = None, **kwargs)
```

[Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/modular_pipelines/qwenimage21/modular_pipeline.py#L54)

Một ModularPipeline cho Qwen-Image 2.1 Turbo, checkpoint tăng tốc cho phép lấy mẫu chỉ trong vài bước mà không cần hướng dẫn.

## QwenImage21TurboAutoBlocks[[diffusers.QwenImage21TurboAutoBlocks]]

#### diffusers.QwenImage21TurboAutoBlocks[[diffusers.QwenImage21TurboAutoBlocks]]

```python
diffusers.QwenImage21TurboAutoBlocks()
```

[Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/modular_pipelines/qwenimage21/modular_blocks_qwenimage21_turbo.py#L466)

Auto Modular pipeline cho text-to-image và tạo ảnh có điều kiện từ ảnh, sử dụng Qwen-Image 2.1 Turbo, checkpoint tăng tốc cho phép lấy mẫu trên lưới sigma đi kèm chỉ trong vài bước mà không cần guidance.
- để tạo ảnh từ văn bản, bạn chỉ cần cung cấp `prompt`
- cho tạo hình ảnh có điều kiện, bạn cần cung cấp `prompt` và `image` (một hình ảnh hoặc một danh sách)

Các quy trình làm việc được hỗ trợ:
- `text2image`: yêu cầu `prompt`
- `image_conditioned`: yêu cầu `prompt`, `image`

Các thành phần: image_processor (`VaeImageProcessor`) text_encoder (`Qwen3VLForConditionalGeneration`) processor (`Qwen3VLProcessor`) vae (`AutoencoderKLQwenImage21`) scheduler (`FlowMatchEulerDiscreteScheduler`) transformer (`QwenImage21Transformer2DModel`)

Configs: sample_sigmas (mặc định: None): Lưới lấy mẫu đi kèm checkpoint, được sử dụng khi `sigmas` không được truyền vào.

Inputs: image (`Image | list`, *tùy chọn*): Ảnh tham chiếu để khử nhiễu. Có thể là một ảnh hoặc danh sách các ảnh. output_resolution (`int`, *tùy chọn*, mặc định là 1024): Độ dài cạnh mục tiêu dùng để suy ra kích thước đầu ra và để thay đổi kích thước ảnh điều kiện. prompt (`str`): Prompt hoặc các prompt để hướng dẫn tạo ảnh. generator (`Generator`, *tùy chọn*): Bộ tạo Torch cho việc tạo ra có tính xác định. num_images_per_prompt (`int`, *tùy chọn*, mặc định là 1): Số lượng ảnh cần tạo cho mỗi prompt. height (`int`, *tùy chọn*): Chiều cao tính bằng pixel của ảnh được tạo. width (`int`, *tùy chọn*): Chiều rộng tính bằng pixel của ảnh được tạo. image_latents (`list`, *tùy chọn*): Latents đã chuẩn hóa của mỗi ảnh điều kiện. Có thể được tạo từ bước vae_encoder. latents (`Tensor`): Noisy latents đã tạo trước cho việc tạo ảnh. num_inference_steps (`int`): Số bước khử nhiễu. sigmas (`list`, *tùy chọn*): Các sigmas tùy chỉnh cho quá trình khử nhiễu. use_kv_cache (`bool`, *tùy chọn*, mặc định là True): Lưu cache các khóa và giá trị của văn bản và ảnh điều kiện sau bước đầu tiên. Điều này hợp lệ vì `causal_condition` điều biến các token đó từ `t = 0`, khiến kích hoạt của chúng không phụ thuộc vào bước. Việc bật/tắt tùy chọn này không tái tạo cùng một ảnh bit-for-bit ở độ chính xác giảm. attention_kwargs (`dict`, *tùy chọn*): Các kwargs bổ sung cho các bộ xử lý attention. **denoiser_input_fields (`None`, *tùy chọn*): các đầu vào mô hình điều kiện cho bộ khử nhiễu: ví dụ prompt_embeds, negative_prompt_embeds, v.v. output_type (`str`, *tùy chọn*, mặc định là pil): Định dạng đầu ra: 'pil', 'np', 'pt'.

Đầu ra: hình ảnh (`list`): Các hình ảnh được tạo ra.

