# AutoencoderKLMagvit

Mô hình autoencoder biến phân 3D (VAE) với tổn thất KL được sử dụng trong [EasyAnimate](https://github.com/aigc-apps/EasyAnimate) do Alibaba PAI giới thiệu.

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

```python
from diffusers import AutoencoderKLMagvit

vae = AutoencoderKLMagvit.from_pretrained("alibaba-pai/EasyAnimateV5.1-12b-zh", subfolder="vae", dtype=torch.float16).to("cuda")  # or "mps", "xpu", "cpu"
```

## AutoencoderKLMagvit[[diffusers.AutoencoderKLMagvit]]

#### diffusers.AutoencoderKLMagvit[[diffusers.AutoencoderKLMagvit]]

```python
diffusers.AutoencoderKLMagvit(in_channels: int = 3, latent_channels: int = 16, out_channels: int = 3, block_out_channels: tuple = [128, 256, 512, 512], down_block_types: tuple = ['SpatialDownBlock3D', 'SpatialTemporalDownBlock3D', 'SpatialTemporalDownBlock3D', 'SpatialTemporalDownBlock3D'], up_block_types: tuple = ['SpatialUpBlock3D', 'SpatialTemporalUpBlock3D', 'SpatialTemporalUpBlock3D', 'SpatialTemporalUpBlock3D'], layers_per_block: int = 2, act_fn: str = 'silu', norm_num_groups: int = 32, scaling_factor: float = 0.7125, spatial_group_norm: bool = True)
```

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

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 được sử dụng trong [EasyAnimate](https://huggingface.co/papers/2405.18991).

Mô hình này kế thừa từ [ModelMixin](/docs/diffusers/main/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.AutoencoderKLMagvit.decode]]

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

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

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

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

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

**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.AutoencoderKLMagvit.enable_tiling]]

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

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

**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.AutoencoderKLMagvit.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_magvit.py#L1046)

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

## 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/main/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/main/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ã.

