#
# Được cấp phép theo Giấy phép Apache, Phiên bản 2.0 (gọi là "Giấy phép");
# bạn có thể không sử dụng tệp này ngoại trừ tuân thủ theo Giấy phép.
# Bạn có thể nhận được một bản sao của Giấy phép tại
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Trừ khi được yêu cầu bởi luật pháp có hiệu lực hoặc được thỏa thuận bằng văn bản, phần mềm
# được phân phối theo Giấy phép được phân phối trên cơ sở
# KHÔNG CÓ BẢO HÀNH HOẶC ĐIỀU KIỆN DƯỚI BẤT KỲ HÌNH THỨC NÀO, dù được nêu rõ hay ngụ ý.
# Xem Giấy phép để biết ngôn ngữ cụ thể điều chỉnh các quyền và
# giới hạn theo Giấy phép. -->

# FLUX 3 Image Klein

FLUX 3 Image Klein là mô hình tạo ảnh 5.6B từ Black Forest Labs: một transformer duy nhất ([Flux3Transformer2DModel](/docs/diffusers/main/vi/api/models/flux3_transformer#diffusers.Flux3Transformer2DModel)) tạo ảnh từ một prompt văn bản, hoạt động độc lập hoặc cùng với một hoặc nhiều ảnh tham chiếu. Điều kiện văn bản đến từ Qwen3-VL, và ảnh sử dụng autoencoder đóng gói FLUX.2 (`AutoencoderKLFlux2`).

FLUX 3 Image Klein được phát hành dưới dạng [pipeline module hóa](../../modular_diffusers/overview). Bắt đầu với việc tạo ảnh từ văn bản:

```python
import torch
from diffusers import ModularPipeline

pipe = ModularPipeline.from_pretrained("black-forest-labs/flux-3-image-klein-base")
pipe.load_components(dtype={"vae": torch.float32, "default": torch.bfloat16})
pipe.to("cuda")

image = pipe(
    prompt="A red fox in a snow-covered forest clearing at golden hour",
    generator=torch.Generator().manual_seed(0),
    output="images",
)[0]
image.save("fox.png")
```

`prompt` là đầu vào bắt buộc duy nhất: pipeline mang theo các cài đặt lấy mẫu được khuyến nghị (50 bước, guidance scale 3.5, scheduler shift 6.93) và mặc định tạo ảnh kích thước 1024 x 1024. Mỗi lần gọi chỉ nhận một prompt; dùng `num_images_per_prompt` để tạo nhiều ảnh từ cùng một prompt.

Như bạn có thể thấy trong ví dụ ở trên, việc tải và chạy hơi khác so với `DiffusionPipeline`. Việc tải là theo kiểu lười (lazy): [from_pretrained()](/docs/diffusers/main/vi/api/modular_diffusers/pipeline#diffusers.ModularPipeline.from_pretrained) chỉ xây dựng pipeline, và bạn gọi [load_components()](/docs/diffusers/main/vi/api/modular_diffusers/pipeline#diffusers.ModularPipeline.load_components) để tải trọng số. Một lời gọi sẽ trả về trạng thái của pipeline, và bạn yêu cầu những gì cần thiết bằng `output`: ở đây là `output="images"`, hoặc `output=["images", "prompt"]` để cũng nhận được chú thích mà prompt upsampler đã viết.

> [!TIP]
> Nếu bạn làm việc với `ModularPipeline` lần đầu tiên, hãy đọc [quickstart](../../modular_diffusers/quickstart), và [Coming from DiffusionPipeline](../../modular_diffusers/coming_from_diffusion_pipeline) nếu bạn đã quen thuộc với các pipeline chuẩn. Ngoài việc tải và đầu ra, một số điểm khác biệt khác là: [guidance](#guidance-scale), [callbacks](#per-step-callbacks) và [offloading](#memory).

## Mẫu hóa lại prompt

Việc tạo prompt rất quan trọng: FLUX 3 Image Klein nhận các mô tả cảnh hoàn chỉnh, trong đó nêu rõ chủ thể, bố cục, ánh sáng và bầu không khí, chứ không phải các `prompt` ngắn; một yêu cầu được gửi đúng như cách gõ sẽ cho ra kết quả chung chung. Đó là lý do pipeline chạy bộ mở rộng prompt trước tiên cho mọi yêu cầu, dù là tạo ảnh từ văn bản hay chỉnh sửa. Đây là một mô hình 9B riêng biệt từ Black Forest Labs ([black-forest-labs/flux-3-image-klein-pup](https://huggingface.co/black-forest-labs/flux-3-image-klein-pup)) có nhiệm vụ mở rộng `prompt` thành một mô tả như vậy trước khi đưa vào bộ mã hóa văn bản, và chỉ cần một `prompt` ngắn là đủ.

Upsampler prompt biến một yêu cầu ngắn, cùng với các hình ảnh tham chiếu khi chỉnh sửa, thành mô tả cảnh hoàn chỉnh mà mô hình sử dụng: medium và style, cảnh, ánh sáng và camera, mỗi chủ thể cùng màu sắc, vật liệu và vị trí của nó trong khung hình. Một mô hình bao phủ text-to-image, chỉnh sửa với hình ảnh tham chiếu và layout với các hộp. Mô tả mà nó viết được trả về dưới dạng đầu ra `prompt`. Trong ví dụ trên, hãy yêu cầu nó cùng với các hình ảnh để xem mô hình hình ảnh đã nhận được gì:

```python
out = pipe(
    prompt="A red fox in a snow-covered forest clearing at golden hour",
    generator=torch.Generator().manual_seed(0),
    output=["images", "prompt"],
)
print(out["prompt"])
```

```
Full-color outdoor wildlife photograph taken from a low eye-level perspective in a snow-covered forest clearing at golden hour. In the center foreground, a red fox stands in profile facing left, its body turned toward the viewer and its head raised as it looks across the clearing. The fox has dense rust-red winter fur, a white throat and chest, black lower legs, pointed ears with dark tips, and a long bushy tail ending in white. ...
```

Đoạn chú thích đầy đủ dài khoảng 240 từ; `max_new_tokens` giới hạn độ dài của nó (mặc định là 3584).

Bạn có thể in `doc` của bước để xem nó nhận những gì và ghi ra những gì:

```python
print(pipe.blocks.sub_blocks["prompt_upsampler"].doc)
```

```
  Inputs:
      prompt (`str`):
          The edit instruction to expand into the full caption (one per call).
      image (`Image | list`, *optional*):
          The reference image(s) of the edit, at most 10; the same ones the pipeline receives.
      boxes (`list`, *optional*):
          Layout boxes, each {'id', 'desc', 'from', 'src_bbox', 'tgt_bbox'} with the boxes as [y_min, x_min, y_max, x_max] in
          0-1: ...
      max_new_tokens (`int`, *optional*, defaults to 3584):
          The most tokens the upsampler may generate for the caption.

  Outputs:
      prompt (`str`):
          The full caption, replacing the request.
```

Tương tự như các khối khác trong pipeline, khối `prompt_upsampler` cũng chạy độc lập. Cách được khuyến nghị là tách nó ra khỏi các khối: khối bị tách ra sẽ trở thành một upsampler độc lập, và các khối còn lại sẽ tạo thành một pipeline nhận caption đã mở rộng dưới dạng `prompt`:

```python
blocks = ModularPipeline.from_pretrained("black-forest-labs/flux-3-image-klein-base").blocks
pup_block = blocks.sub_blocks.pop("prompt_upsampler")

pup = pup_block.init_pipeline("black-forest-labs/flux-3-image-klein-base")
pup.load_components(dtype=torch.bfloat16)
pup.to("cuda")
caption = pup(prompt="A red fox in a snow-covered forest clearing at golden hour", output="prompt")

pipe = blocks.init_pipeline("black-forest-labs/flux-3-image-klein-base")
pipe.load_components(dtype={"vae": torch.float32, "default": torch.bfloat16})
pipe.to("cuda")
image = pipe(prompt=caption, generator=torch.Generator().manual_seed(0), output="images")[0]
```

Nhờ đó, nó có thể được triển khai như một giai đoạn riêng biệt, trên GPU riêng hoặc sau endpoint riêng, và giao diện người dùng có thể hiển thị chú thích mà nó đã viết, cho phép người dùng chỉnh sửa trước khi tạo ảnh. Bất kỳ LLM nào khác cũng có thể thay thế upsampler, với cùng các system prompt: hãy cung cấp `system_prompts["t2i"]` từ kho upsampler (hoặc `"i2i"`, với các tham chiếu đặt trước trong user message) làm system prompt và yêu cầu làm user message, sau đó truyền chú thích mà nó trả về dưới dạng `prompt` cho `pipe`.

## Ảnh sang ảnh

Truyền một hoặc nhiều hình ảnh tham chiếu bằng `image`. Một tham chiếu đơn được giữ nguyên vẹn: nó chỉ bị giảm kích thước khi vượt quá 4 megapixel, được đệm lên lưới 16 pixel, và kích thước mặc định của quá trình tạo sẽ khớp với kích thước của nó, do đó kết quả chỉnh sửa sẽ có cùng kích thước với đầu vào. Nhiều tham chiếu sẽ mỗi cái được điều chỉnh dưới 1 megapixel và cắt theo lưới, và kích thước mặc định của quá trình tạo sẽ lấy theo kích thước của tham chiếu đầu tiên. Giá trị `height`/`width` cụ thể sẽ ghi đè lên mặc định. Hãy mô tả hình ảnh *mục tiêu* như một chú thích hoàn chỉnh của hình tham chiếu với phần chỉnh sửa của bạn được tích hợp vào, thay vì một dòng hướng dẫn ngắn, hoặc để [prompt upsampler](#prompt-upsampling) viết ra từ hướng dẫn và các hình tham chiếu:

```python
night = pipe(
    prompt="the same scene at night under a full moon",
    image=image,
    generator=torch.Generator().manual_seed(0),
    output=["images", "prompt"],
)
```

Với một số tham chiếu, hãy gọi chúng là hình ảnh đầu tiên, hình ảnh thứ hai, ... theo thứ tự chúng được truyền vào `image`; chú thích gọi chúng là `<ref_image_0>`, `<ref_image_1>`, ... đối với mô hình hình ảnh:

```python
combined = pipe(
    prompt="the fox from the first image sitting on the wooden bench from the second image",
    image=[image, bench],
    height=768,
    width=1360,
    output="images",
)[0]
```

Truyền `height` và/hoặc `width` để ghi đè kích thước đã suy ra.

## Kiểm soát bố cục

Để đặt nội dung một cách rõ ràng, hãy truyền `boxes`: cho mỗi phần tử một `id`, một `desc` ngắn, và một `bbox` dạng `[y_min, x_min, y_max, x_max]` trong khoảng 0-1 (gốc ở góc trên bên trái), để nó độc lập với kích thước đầu ra. Bộ tăng độ phân giải sẽ viết chú thích xung quanh chúng, trích dẫn mỗi phần tử dưới dạng `<id>`, và thêm bảng các hộp, giữ nguyên chính xác hộp của bạn:

```python
boxes = [
    {"id": "balloon_1", "desc": "a red and yellow striped hot-air balloon", "bbox": [0.08, 0.06, 0.48, 0.38]},
    {"id": "balloon_2", "desc": "a small blue hot-air balloon", "bbox": [0.20, 0.62, 0.42, 0.80]},
]
out = pipe(prompt="hot-air balloons over a green valley at sunrise", boxes=boxes, output=["images", "prompt"])
```

Khi chỉnh sửa, một hộp chỉ định nguồn của nó bằng `from`: `"target"` kèm `tgt_bbox` sẽ thêm một phần tử mới tại đó, `"ref_image_0"` kèm `src_bbox` và `tgt_bbox` sẽ di chuyển một phần tử của ảnh tham chiếu đó (các hộp bằng nhau sẽ giữ nguyên vị trí):

```python
boxes = [{"id": "cactus", "desc": "a small potted cactus", "from": "target", "src_bbox": None, "tgt_bbox": [0.55, 0.62, 0.85, 0.85]}]
out = pipe(prompt="add a small potted cactus in the marked spot", image=mug, boxes=boxes, output=["images", "prompt"])

boxes = [{"id": "knight", "desc": "the knight figure", "from": "ref_image_0", "src_bbox": [0.50, 0.15, 0.85, 0.35], "tgt_bbox": [0.19, 0.06, 0.54, 0.26]}]
out = pipe(prompt="move the knight up and to the left, keep the rest unchanged", image=knight, boxes=boxes, output=["images", "prompt"])
```

Caption mà mô hình ảnh đọc có các phần tử được gắn thẻ `<id>` trong văn bản và bảng được nối thêm dưới dạng JSON, với các hộp trên canvas 0-1000; in ra kết quả `prompt` để xem. Một caption được viết theo dạng đó bằng tay sẽ được đưa vào pipeline mà không cần bước này, như trong [Prompt upsampling](#prompt-upsampling).

## Thang độ dẫn

Pipeline áp dụng classifier-free guidance thông qua thành phần `guider` và không nhận đối số `guidance_scale` tại thời điểm gọi. Guider mặc định là [ClassifierFreeGuidance](/docs/diffusers/main/vi/api/modular_diffusers/guiders#diffusers.ClassifierFreeGuidance) với `guidance_scale=3.5`, cài đặt được khuyến nghị cho cả hai workflow. Để thay đổi, hãy tạo một bản sao cập nhật của guider:

```python
pipe.guider = pipe.guider.new(guidance_scale=5.0)
```

Xem [hướng dẫn cho guider](../../using-diffusers/guiders) để chuyển sang phương pháp guidance khác.

## Mô hình được chưng cất theo bước

Checkpoint được chưng cất theo bước tạo ra kết quả trong 16 bước mà không cần classifier-free guidance. Transformer của nó là một flow map: ở mỗi bước, nó được cung cấp timestep hiện tại và timestep mà bước đó nhảy tới. Nó được nạp giống như mô hình cơ sở (tệp `modular_model_index.json` trong kho chỉ đến [Flux3DistilledModularPipeline](/docs/diffusers/main/vi/api/pipelines/flux3#diffusers.Flux3DistilledModularPipeline) và [Flux3DistilledAutoBlocks](/docs/diffusers/main/vi/api/pipelines/flux3#diffusers.Flux3DistilledAutoBlocks)); pipeline không có `guider` và không nhận `negative_prompt`:

```python
pipe = ModularPipeline.from_pretrained("black-forest-labs/flux-3-image-klein")
pipe.load_components(dtype=torch.bfloat16)
pipe.to("cuda")

image = pipe(prompt=prompt, generator=torch.Generator().manual_seed(0), output="images")[0]
```

Nó phục vụ cùng hai luồng công việc như mô hình cơ sở. `num_inference_steps` mặc định là 16; mô hình được huấn luyện trong 4 đến 16 bước.

## Tạo ra có thể tái lập

Một `generator` cố định nhiễu mà pipeline lấy (xem [Tính tái lập](../../using-diffusers/reusing_seeds)). Để tái sử dụng nhiễu đã lấy ở nơi khác, hãy truyền nó dưới dạng `latents` với hình dạng `(batch_size, 128, height // 16, width // 16)`. Ví dụ, [cách triển khai của BFL](https://github.com/black-forest-labs/flux-3-image-klein) lấy nhiễu dưới dạng các token ảnh trên CPU và chuyển đổi nó sang bf16; điều này tái lập mẫu của nó cho một seed nhất định:

```python
height, width = 1024, 1024
h, w = height // 16, width // 16

noise = torch.randn((h * w, 128), generator=torch.Generator().manual_seed(0)).to(torch.bfloat16)
latents = noise.T.reshape(1, 128, h, w)

image = pipe(prompt=prompt, latents=latents, height=height, width=width, output="images")[0]
```

## Quy trình làm việc

Pipeline phục vụ hai luồng công việc, `text2image` và `image_conditioned`; luồng được thực thi sẽ được chọn dựa trên các đầu vào (`image` chọn image-to-image). [from_pretrained()](/docs/diffusers/main/vi/api/modular_diffusers/pipeline#diffusers.ModularPipeline.from_pretrained) cũng có thể xây dựng pipeline cho một luồng công việc bằng tham số `workflow`, khi đó pipeline chỉ kỳ vọng và tải các thành phần mà luồng công việc đó cần:

```python
from diffusers.modular_pipelines import Flux3AutoBlocks

print(Flux3AutoBlocks().available_workflows)
# ["text2image", "image_conditioned"]

t2i = ModularPipeline.from_pretrained("black-forest-labs/flux-3-image-klein-base", workflow="text2image")
print(t2i.blocks.doc)
```

## Callback theo từng bước

Để sử dụng một hàm callback có sẵn, hãy chèn một khối vào vòng lặp khử nhiễu. [hướng dẫn về callback](../../using-diffusers/callback#modular-pipelines) có một ví dụ đơn giản với khối `CallbackOnStepEnd` và hàm trợ giúp `walk_denoise_loops`:

```python
blocks = Flux3AutoBlocks()  # or Flux3DistilledAutoBlocks
for loop in walk_denoise_loops(blocks):
    loop.sub_blocks["callback"] = CallbackOnStepEnd()
pipe = blocks.init_pipeline("black-forest-labs/flux-3-image-klein-base")

image = pipe(prompt=caption, callback_on_step_end=my_callback, output="images")[0]
```

Để dừng sớm, hãy raise từ callback; không có cờ `interrupt`.

## Bộ nhớ

Việc nạp toàn bộ ở bf16 tiêu tốn khoảng 39 GB trọng số: transformer có 5,5B tham số, text encoder Qwen3-VL-4B có 4B và [prompt upsampler](#prompt-upsampling) có 9B (khoảng 19 GB riêng), với image VAE ở fp32. Một pipeline được xây dựng không có bước upsampler (xem ở đó) nạp khoảng 20 GB. Đối với GPU có bộ nhớ ít hơn, hãy bật component offloading; trình quản lý sẽ di chuyển các component giữa CPU và GPU khi mỗi bước cần đến, bao gồm cả upsampler:

```python
from diffusers import ComponentsManager, ModularPipeline

manager = ComponentsManager()
pipe = ModularPipeline.from_pretrained("black-forest-labs/flux-3-image-klein-base", components_manager=manager)
pipe.load_components(dtype={"vae": torch.float32, "default": torch.bfloat16})
manager.enable_auto_cpu_offload(device="cuda")
```

## Tải tệp đơn

[Flux3Transformer2DModel](/docs/diffusers/main/vi/api/models/flux3_transformer#diffusers.Flux3Transformer2DModel) nạp transformer trực tiếp từ gói mô hình của Black Forest Labs bằng [from_single_file()](/docs/diffusers/main/vi/api/loaders/single_file#diffusers.loaders.FromOriginalModelMixin.from_single_file). Gói `config.json` không được đọc; hãy truyền cấu hình diffusers bằng `config` và `subfolder`.

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

transformer = Flux3Transformer2DModel.from_single_file(
    "https://huggingface.co/black-forest-labs/flux-3-image-klein-base/blob/main/model.safetensors",
    config="black-forest-labs/flux-3-image-klein-base",
    subfolder="transformer",
    dtype=torch.bfloat16,
)

pipe = ModularPipeline.from_pretrained("black-forest-labs/flux-3-image-klein-base")
pipe.load_components(dtype={"vae": torch.float32, "default": torch.bfloat16})
pipe.update_components(transformer=transformer)
pipe.to("cuda")
```

Tải các thành phần khác theo tên trước: [load_components()](/docs/diffusers/main/vi/api/modular_diffusers/pipeline#diffusers.ModularPipeline.load_components) không có `names` cũng sẽ tải transformer từ kho pipeline.

Việc nạp các checkpoint đơn tệp FP8r và NVFP4 cũng được hỗ trợ. Cả hai đều được nạp thông qua cùng một lệnh gọi với [BFLQuantizationConfig](/docs/diffusers/main/vi/api/quantization#diffusers.BFLQuantizationConfig). Xem [hướng dẫn lượng tử hóa BFL](../../quantization/bfl) để biết yêu cầu về kernel của từng phương án.

```python
from diffusers import BFLQuantizationConfig

transformer = Flux3Transformer2DModel.from_single_file(
    "https://huggingface.co/black-forest-labs/flux-3-image-klein-base/blob/main/variants/nvfp4/model.safetensors",
    config="black-forest-labs/flux-3-image-klein-base",
    subfolder="transformer",
    quantization_config=BFLQuantizationConfig(compute_dtype=torch.bfloat16),
    dtype=torch.bfloat16,
)
```

Khi nạp các checkpoint đã chưng cất theo bước, chúng ta cần cấu hình của chúng (`flow_map=True`):

```python
transformer = Flux3Transformer2DModel.from_single_file(
    "https://huggingface.co/black-forest-labs/flux-3-image-klein/blob/main/variants/nvfp4/model.safetensors",
    config="black-forest-labs/flux-3-image-klein",
    subfolder="transformer",
    quantization_config=BFLQuantizationConfig(compute_dtype=torch.bfloat16),
    dtype=torch.bfloat16,
)
```

## Flux3ModularPipeline[[diffusers.Flux3ModularPipeline]]

#### diffusers.Flux3ModularPipeline[[diffusers.Flux3ModularPipeline]]

```python
diffusers.Flux3ModularPipeline(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/flux3/modular_pipeline.py#L24)

Một ModularPipeline cho FLUX.3.

## Flux3AutoBlocks[[diffusers.Flux3AutoBlocks]]

#### diffusers.Flux3AutoBlocks[[diffusers.Flux3AutoBlocks]]

```python
diffusers.Flux3AutoBlocks()
```

[Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/modular_pipelines/flux3/modular_blocks_flux3.py#L339)

Auto blocks thực hiện tạo ảnh từ văn bản và tạo ảnh từ ảnh bằng FLUX.3. `prompt` sẽ đi qua prompt upsampler trước; hãy bỏ bước `prompt_upsampler` để mã hóa như đã cho.

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: prompt_upsampler (`Qwen3_5ForConditionalGeneration`): Bộ tăng cường prompt. prompt_upsampler_processor (`AutoProcessor`): Bộ xử lý của nó. text_encoder (`Qwen3VLForConditionalGeneration`) tokenizer (`AutoProcessor`) image_processor (`Flux3ImageProcessor`) vae (`AutoencoderKLFlux2`) transformer (`Flux3Transformer2DModel`) scheduler (`FlowMatchEulerDiscreteScheduler`) guider (`ClassifierFreeGuidance`)

Inputs: prompt (`str`): Chỉ thị chỉnh sửa để mở rộng thành chú thích đầy đủ (một chỉ thị cho mỗi lần gọi). image (`Image | list`, *tùy chọn*): Ảnh tham chiếu của chỉnh sửa, tối đa 10 ảnh; chính là những ảnh mà pipeline nhận được. boxes (`list`, *tùy chọn*): Các hộp bố cục, mỗi hộp có dạng {'id', 'desc', 'from', 'src_bbox', 'tgt_bbox'} với các hộp được biểu diễn dưới dạng [y_min, x_min, y_max, x_max] trong khoảng 0-1: 'from': 'target' kèm `tgt_bbox` sẽ thêm một phần tử tại đó, 'from': 'ref_image_0', ... kèm `src_bbox` và `tgt_bbox` sẽ di chuyển một phần tử từ ảnh tham chiếu. max_new_tokens (`int`, *tùy chọn*, mặc định là 3584): Số token tối đa mà upsampler có thể tạo ra cho chú thích. negative_prompt (`str`, *tùy chọn*): Prompt không dùng để định hướng quá trình tạo. max_sequence_length (`int`, *tùy chọn*, mặc định là 8192): Số token prompt tối đa; các prompt dài hơn sẽ bị cắt bớt. text_encoder_out_layers (`tuple`, *tùy chọn*, mặc định là (4, 8, 12, 16, 20, 24, 28, 32)): Chỉ số của các lớp ẩn của text-encoder mà trạng thái của chúng được xếp chồng để tạo thành text embeddings. num_images_per_prompt (`int`, *tùy chọn*, mặc định là 1): Số ảnh cần tạo cho mỗi prompt. image_cond_latents (`list`, *tùy chọn*): Các latents đã chuẩn hóa và đóng gói của các ảnh tham chiếu, mỗi ảnh là một tensor có hình dạng (B, C, height_i//16, width_i//16). height (`int`, *tùy chọn*, mặc định là None hoặc 1024, tùy thuộc vào workflow): Chiều cao tính bằng pixel của ảnh được tạo; mặc định là chiều cao của chính ảnh tham chiếu đầu tiên. width (`int`, *tùy chọn*, mặc định là None hoặc 1024, tùy thuộc vào workflow): Chiều rộng tính bằng pixel của ảnh được tạo; mặc định là chiều rộng của chính ảnh tham chiếu đầu tiên. reference_crop (`list | NoneType`, *tùy chọn*): Đối với mỗi ảnh tham chiếu, hộp chứa ảnh tham chiếu bên trong canvas đã đệm của nó, hoặc None, lấy từ bước tiền xử lý. latents (`Tensor`): Các latents nhiễu đã tạo trước cho việc tạo ảnh. generator (`Generator`, *tùy chọn*): Torch generator cho việc tạo ảnh tất định. num_inference_steps (`int`): Số bước khử nhiễu. timesteps (`Tensor`): Các bước thời gian cho quá trình khử nhiễu. (ghi đè `num_inference_steps` khi được cung cấp) sigmas (`list`, *tùy chọn*): Các sigma tùy chỉnh cho quá trình khử nhiễu. (ghi đè `num_inference_steps` khi được cung cấp) **denoiser_input_fields (`None`, *tùy chọn*): Các đầu vào mô hình có điều kiện cho denoiser: ví dụ prompt_embeds, negative_prompt_embeds, v.v. attention_kwargs (`dict`, *tùy chọn*): Các kwargs bổ sung cho các attention processor. output_type (`str`, *tùy chọn*, mặc định là pil): Định dạng đầu ra: 'pil', 'np', 'pt'.

Đầu ra: images (`list`): Các hình ảnh được tạo ra. latents (`Tensor`): Các latents đã khử nhiễu.

## Flux3DistilledAutoBlocks[[diffusers.Flux3DistilledAutoBlocks]]

#### diffusers.Flux3DistilledAutoBlocks[[diffusers.Flux3DistilledAutoBlocks]]

```python
diffusers.Flux3DistilledAutoBlocks()
```

[Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/modular_pipelines/flux3/modular_blocks_flux3_distilled.py#L258)

Auto blocks thực hiện tạo ảnh từ văn bản và tạo ảnh từ ảnh bằng mô hình FLUX.3 đã được step-distilled (16 bước, không có classifier-free guidance). `prompt` sẽ đi qua prompt upsampler trước; hãy bỏ bước `prompt_upsampler` để mã hóa nó như đã cho.

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: prompt_upsampler (`Qwen3_5ForConditionalGeneration`): Bộ mở rộng prompt. prompt_upsampler_processor (`AutoProcessor`): Bộ xử lý của nó. text_encoder (`Qwen3VLForConditionalGeneration`) tokenizer (`AutoProcessor`) image_processor (`Flux3ImageProcessor`) vae (`AutoencoderKLFlux2`) transformer (`Flux3Transformer2DModel`) scheduler (`FlowMatchEulerDiscreteScheduler`)

Inputs: prompt (`str`): Chỉ thị chỉnh sửa để mở rộng thành chú thích đầy đủ (một chỉ thị cho mỗi lần gọi). image (`Image | list`, *tùy chọn*): Ảnh tham chiếu của chỉnh sửa, tối đa 10 ảnh; chính là những ảnh mà pipeline nhận được. boxes (`list`, *tùy chọn*): Các hộp bố cục, mỗi hộp có dạng {'id', 'desc', 'from', 'src_bbox', 'tgt_bbox'} với các hộp được biểu diễn dưới dạng [y_min, x_min, y_max, x_max] trong khoảng 0-1: 'from': 'target' kèm `tgt_bbox` sẽ thêm một phần tử tại đó, 'from': 'ref_image_0', ... kèm `src_bbox` và `tgt_bbox` sẽ di chuyển một phần tử từ ảnh tham chiếu. max_new_tokens (`int`, *tùy chọn*, mặc định là 3584): Số token tối đa mà bộ mở rộng có thể tạo ra cho chú thích. max_sequence_length (`int`, *tùy chọn*, mặc định là 8192): Số token prompt tối đa; các prompt dài hơn sẽ bị cắt bớt. text_encoder_out_layers (`tuple`, *tùy chọn*, mặc định là (4, 8, 12, 16, 20, 24, 28, 32)): Chỉ số của các lớp ẩn của text-encoder mà trạng thái của chúng được xếp chồng để tạo thành các nhúng văn bản 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. image_cond_latents (`list`, *tùy chọn*): Các latents đã đóng gói và chuẩn hóa của các ảnh tham chiếu, mỗi ảnh là một tensor có hình dạng (B, C, height_i//16, width_i//16) height (`int`, *tùy chọn*, mặc định là None hoặc 1024, tùy thuộc vào quy trình làm việc): Chiều cao tính bằng pixel của ảnh được tạo; mặc định là chiều cao của chính ảnh tham chiếu đầu tiên width (`int`, *tùy chọn*, mặc định là None hoặc 1024, tùy thuộc vào quy trình làm việc): Chiều rộng tính bằng pixel của ảnh được tạo; mặc định là chiều rộng của chính ảnh tham chiếu đầu tiên reference_crop (`list | NoneType`, *tùy chọn*): Đối với mỗi ảnh tham chiếu, hộp chứa ảnh tham chiếu bên trong canvas đã đệm của nó hoặc None, lấy từ bước tiền xử lý latents (`Tensor`): Các latents nhiễu đã tạo trước cho việc 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_inference_steps (`int`): Số bước khử nhiễu. timesteps (`Tensor`): Các bước thời gian cho quá trình khử nhiễu. (ghi đè `num_inference_steps` khi được cung cấp) sigmas (`list`, *tùy chọn*): Các sigma tùy chỉnh cho quá trình khử nhiễu. (ghi đè `num_inference_steps` khi được cung cấp) **denoiser_input_fields (`None`, *tùy chọn*): các đầu vào mô hình có đ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: images (`list`): Các hình ảnh được tạo ra. latents (`Tensor`): Các latents đã khử nhiễu.

## Flux3DistilledModularPipeline[[diffusers.Flux3DistilledModularPipeline]]

#### diffusers.Flux3DistilledModularPipeline[[diffusers.Flux3DistilledModularPipeline]]

```python
diffusers.Flux3DistilledModularPipeline(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/flux3/modular_pipeline.py#L52)

Mô hình FLUX.3 có bước chưng cất (16 bước, không có hướng dẫn không phân loại) với ModularPipeline.

