# AutoencoderKLQwenImage21

Biến thể tự mã hóa (variational auto-encoder) 64 kênh được sử dụng bởi Qwen-Image 2.1. Nó nén không gian 16 lần, và `latents_mean` / `latents_std` cho từng kênh là một phần của cấu hình thay vì một hệ số tỷ lệ duy nhất.

```python
import torch
from diffusers import AutoencoderKLQwenImage21

vae = AutoencoderKLQwenImage21.from_pretrained("Qwen/Qwen-Image-2.1", subfolder="vae", dtype=torch.bfloat16)
```

## AutoencoderKLQwenImage21[[diffusers.AutoencoderKLQwenImage21]]

#### diffusers.AutoencoderKLQwenImage21[[diffusers.AutoencoderKLQwenImage21]]

```python
diffusers.AutoencoderKLQwenImage21(base_dim: int = 96, decoder_base_dim: int | None = 144, z_dim: int = 64, dim_mult: list[int] = [1, 2, 4, 8, 8], num_res_blocks: int = 2, attn_scales: list[float] = [], temperal_downsample: list[bool] = [False, True, True, True], dropout: float = 0.0, latents_mean: list[float] = [0.5126, 0.7721, -0.0631, 1.3506, -0.7855, -2.1025, -0.3458, 1.3722, 1.8873, -1.7177, -0.651, 0.2732, 0.7562, -0.6163, -1.0277, 3.8363, 2.021, 0.0472, 0.932, 2.0087, 2.4954, -0.1391, -1.4249, 1.8464, -0.5236, 1.2826, 3.7046, -1.3035, 2.7286, -1.4518, -1.9036, -1.9955, -0.0342, -1.0265, -0.7636, 3.0555, 0.0746, -3.0751, -0.1076, 1.7376, -1.0914, -1.9435, -0.2784, -1.368, 0.4809, -0.4433, 0.3764, 0.5729, -2.0595, 1.096, -1.326, -2.0211, -5.0179, 0.5275, 4.0162, 1.8505, 0.3026, 1.9373, 1.4937, 0.2632, 0.5547, -1.7121, -0.1562, 0.0304], latents_std: list[float] = [3.2001, 3.2936, 3.4321, 3.0091, 3.1061, 4.0379, 4.0705, 3.791, 3.0785, 3.65, 3.9308, 3.0904, 2.8778, 3.7675, 3.732, 5.0756, 3.2864, 4.0397, 3.1317, 4.0443, 2.9249, 3.9454, 3.0988, 4.2489, 3.4896, 3.8513, 3.9323, 3.4719, 3.7498, 4.283, 3.5694, 4.2467, 3.9037, 3.2947, 5.077, 3.5075, 3.27, 3.4767, 2.8063, 5.1125, 3.5327, 4.7833, 3.1286, 4.1819, 3.8527, 3.8312, 3.5605, 4.3875, 3.9624, 4.0168, 3.5643, 4.055, 5.5614, 4.2963, 4.408, 3.4959, 3.8747, 3.7608, 3.5735, 3.149, 3.7662, 3.6746, 3.4563, 3.8161], is_residual: bool = True, in_channels: int = 4, out_channels: int = 4, patch_size: int | None = None, scale_factor_temporal: int | None = 8, scale_factor_spatial: int | None = 16)
```

[Nguồn](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/models/autoencoders/autoencoder_kl_qwenimage21.py#L977)

Một mô hình VAE có tổn thất KL để mã hóa video thành các biến ẩn và giải mã các biểu diễn ẩn thành video. Được giới thiệu trong [Qwen Image 2].

Mô hình này kế thừa từ [ModelMixin](/docs/diffusers/v0.43.0/vi/api/models/overview#diffusers.ModelMixin). Hãy xem tài liệu của lớp cha để biết các phương thức chung được triển khai cho tất cả các mô hình (chẳng hạn như tải xuống hoặc lưu trữ).

#### decode[[diffusers.AutoencoderKLQwenImage21.decode]]

```python
decode(z: Tensor, return_dict: bool = True)
```

[Nguồn](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/models/autoencoders/autoencoder_kl_qwenimage21.py#L1336)

**Tham số:**

z (`torch.Tensor`) : Lô đầu vào của các vector ẩn.

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

**Trả về:** `~models.vae.DecoderOutput` hoặc `tuple`

Nếu return_dict là True, một `~models.vae.DecoderOutput` sẽ được trả về, ngược lại một `tuple` thông thường sẽ được trả về.

Giải mã một lô ảnh.

#### encode[[diffusers.AutoencoderKLQwenImage21.encode]]

```python
encode(x: Tensor, return_dict: bool = True)
```

[Nguồn](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/models/autoencoders/autoencoder_kl_qwenimage21.py#L1276)

**Tham số:**

x (`torch.Tensor`) : Lô đầu vào của các hình ảnh.

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

**Trả về:**

Các biểu diễn ẩn của các video đã được mã hóa. Nếu `return_dict` là True, một `~models.autoencoder_kl.AutoencoderKLOutput` sẽ được trả về, ngược lại một `tuple` thông thường sẽ được trả về.

Mã hóa một lô ảnh thành các biến ẩn.

#### enable_tiling[[diffusers.AutoencoderKLQwenImage21.enable_tiling]]

```python
enable_tiling(tile_sample_min_height: int | None = None, tile_sample_min_width: int | None = None, tile_sample_stride_height: float | None = None, tile_sample_stride_width: float | None = None)
```

[Nguồn](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/models/autoencoders/autoencoder_kl_qwenimage21.py#L1207)

**Tham số:**

tile_sample_min_height (`int`, *optional*) : Chiều cao tối thiểu cần thiết để một mẫu được tách thành các ô (tiles) theo chiều cao.

tile_sample_min_width (`int`, *optional*) : Độ rộng tối thiểu cần thiết để một mẫu được tách thành các ô (tiles) theo chiều rộng.

tile_sample_stride_height (`int`, *optional*) : Lượng chồng lấn tối thiểu giữa hai gạch dọc liên tiếp. Điều này nhằm đảm bảo không có hiện tượng lỗi ghép gạch nào xảy ra dọc theo chiều cao.

tile_sample_stride_width (`int`, *optional*) : Khoảng cách giữa hai ô gạch ngang liên tiếp. Điều này nhằm đảm bảo không có hiện tượng lỗi ghép gạch nào xảy ra dọc theo chiều rộng.

Bật giải mã VAE dạng gạch. Khi tùy chọn này được bật, VAE sẽ chia tensor đầu vào thành các gạch để tính toán giải mã và mã hóa qua nhiều bước. Điều này hữu ích để tiết kiệm một lượng lớn bộ nhớ và cho phép xử lý các hình ảnh lớn hơn.

#### forward[[diffusers.AutoencoderKLQwenImage21.forward]]

```python
forward(sample: Tensor, sample_posterior: bool = False, return_dict: bool = True, generator: typing.Optional[torch.Generator] = None)
```

[Nguồn](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/models/autoencoders/autoencoder_kl_qwenimage21.py#L1532)

**Tham số:**

sample (`torch.Tensor`) : Mẫu đầu vào.

sample_posterior (`bool`, *tùy chọn*, mặc định là `False`) : Có lấy mẫu từ phân phối hậu nghiệm thay vì lấy mode của nó hay không.

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

generator (`torch.Generator`, *tùy chọn*) : Generator được sử dụng khi `sample_posterior` là `True`.

**Trả về:** [DecoderOutput](/docs/diffusers/v0.43.0/vi/api/models/autoencoderkl_qwenimage#diffusers.models.autoencoders.vae.DecoderOutput) hoặc `tuple`

[DecoderOutput](/docs/diffusers/v0.43.0/vi/api/models/autoencoderkl_qwenimage#diffusers.models.autoencoders.vae.DecoderOutput) nếu `return_dict` là True, ngược lại là một `tuple` thông thường.

#### tiled_decode[[diffusers.AutoencoderKLQwenImage21.tiled_decode]]

```python
tiled_decode(z: Tensor, return_dict: bool = True)
```

[Nguồn](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/models/autoencoders/autoencoder_kl_qwenimage21.py#L1454)

**Tham số:**

z (`torch.Tensor`) : Lô đầu vào của các vector ẩn.

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

**Trả về:** `~models.vae.DecoderOutput` hoặc `tuple`

Nếu return_dict là True, một `~models.vae.DecoderOutput` sẽ được trả về, ngược lại một `tuple` thông thường sẽ được trả về.

Giải mã một lô ảnh bằng trình giải mã dạng gạch.

#### tiled_encode[[diffusers.AutoencoderKLQwenImage21.tiled_encode]]

```python
tiled_encode(x: Tensor)
```

[Nguồn](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/models/autoencoders/autoencoder_kl_qwenimage21.py#L1381)

**Tham số:**

x (`torch.Tensor`) : Lô đầu vào các video.

**Trả về:** `torch.Tensor`

Biểu diễn ẩn của các video đã được mã hóa.

Mã hóa một lô ảnh bằng trình mã hóa dạng gạch.

## AutoencoderKLOutput[[diffusers.models.modeling_outputs.AutoencoderKLOutput]]

#### diffusers.models.modeling_outputs.AutoencoderKLOutput[[diffusers.models.modeling_outputs.AutoencoderKLOutput]]

```python
diffusers.models.modeling_outputs.AutoencoderKLOutput(latent_dist: DiagonalGaussianDistribution)
```

[Nguồn](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/models/modeling_outputs.py#L7)

**Tham số:**

latent_dist (`DiagonalGaussianDistribution`) : Đầu ra được mã hóa của `Encoder`, được biểu diễn dưới dạng mean và logvar của `DiagonalGaussianDistribution`. `DiagonalGaussianDistribution` cho phép lấy mẫu các biến ẩn (latents) từ phân phối này.

Đầu ra của phương pháp mã hóa của AutoencoderKL.

## DecoderOutput[[diffusers.models.autoencoders.vae.DecoderOutput]]

#### diffusers.models.autoencoders.vae.DecoderOutput[[diffusers.models.autoencoders.vae.DecoderOutput]]

```python
diffusers.models.autoencoders.vae.DecoderOutput(sample: Tensor, commit_loss: typing.Optional[torch.FloatTensor] = None)
```

[Nguồn](https://github.com/huggingface/diffusers/blob/v0.43.0/src/diffusers/models/autoencoders/vae.py#L49)

**Tham số:**

sample (`torch.Tensor` có shape `(batch_size, num_channels, height, width)`) : Mẫu đầu ra đã giải mã từ lớp cuối cùng của mô hình.

Đầu ra của phương pháp giải mã.

