# AutoencoderKLKVAE

Mô hình autoencoder biến phân (VAE) 2D với tổn thất KL.

Mô hình có thể được tải bằng đoạn mã sau.

```python
import torch
from diffusers import AutoencoderKLKVAE

vae = AutoencoderKLKVAE.from_pretrained("kandinskylab/KVAE-2D-1.0", subfolder="diffusers", dtype=torch.bfloat16)
```

## AutoencoderKLKVAE[[diffusers.AutoencoderKLKVAE]]

#### diffusers.AutoencoderKLKVAE[[diffusers.AutoencoderKLKVAE]]

```python
diffusers.AutoencoderKLKVAE(in_channels: int = 3, channels: int = 128, num_enc_blocks: int = 2, num_dec_blocks: int = 2, z_channels: int = 16, double_z: bool = True, ch_mult: typing.Tuple[int, ...] = (1, 2, 4, 8), sample_size: int = 1024)
```

[Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/autoencoders/autoencoder_kl_kvae.py#L521)

**Tham số:**

in_channels (int, *tùy chọn*, mặc định là 3) : Số kênh trong ảnh đầu vào.

channels (int,  *tùy chọn*, mặc định là 128) : Số kênh cơ bản trong các khối đa phân giải.

num_enc_blocks (int, *tùy chọn*, mặc định là 2) : Số lượng khối Resnet trong các lớp đa phân giải của encoder.

num_dec_blocks (int, *tùy chọn*, mặc định là 2) : Số lượng khối Resnet trong các lớp đa phân giải của bộ giải mã.

z_channels (int, *tùy chọn*, mặc định là 16) : Số lượng kênh trong không gian tiềm ẩn.

double_z (`bool`, *tùy chọn*, mặc định là `True`) : Xác định có nhân đôi số kênh đầu ra của bộ mã hóa hay không.

ch_mult (`Tuple[int, ...]`, *tùy chọn*, mặc định là `(1, 2, 4, 8)`) : Các hệ số nhân kênh trong các khối đa phân giải.

sample_size (`int`, *tuỳ chọn*, mặc định là `1024`) : Kích thước đầu vào mẫu.

Một mô hình VAE có tổn thất KL để mã hóa ảnh thành các ẩn và giải mã các biểu diễn ẩn thành ảnh.

Mô hình này kế thừa từ [ModelMixin](/docs/diffusers/main/vi/api/models/overview#diffusers.ModelMixin). 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).

#### decode[[diffusers.AutoencoderKLKVAE.decode]]

```python
decode(z: FloatTensor, return_dict: bool = True, generator = None)
```

[Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/autoencoders/autoencoder_kl_kvae.py#L642)

**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.AutoencoderKLKVAE.encode]]

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

[Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/autoencoders/autoencoder_kl_kvae.py#L602)

**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 hình ảnh đã đượ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.

#### forward[[diffusers.AutoencoderKLKVAE.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/main/src/diffusers/models/autoencoders/autoencoder_kl_kvae.py#L776)

**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 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*) : Một [`torch.Generator`](https://pytorch.org/docs/stable/generated/torch.Generator.html) để làm cho việc lấy mẫu trở nên tất định.

**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ề.

#### tiled_decode[[diffusers.AutoencoderKLKVAE.tiled_decode]]

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

[Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/autoencoders/autoencoder_kl_kvae.py#L729)

**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.

