# AutoencoderKLLTXVideo

Mô hình autoencoder biến phân 3D (VAE) với tổn thất KL được sử dụng trong [LTX](https://huggingface.co/Lightricks/LTX-Video) do Lightricks giới thiệu.

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

```python
from diffusers import AutoencoderKLLTXVideo

vae = AutoencoderKLLTXVideo.from_pretrained("Lightricks/LTX-Video", subfolder="vae", dtype=torch.float32).to("cuda")  # or "mps", "xpu", "cpu"
```

## AutoencoderKLLTXVideo[[diffusers.AutoencoderKLLTXVideo]]

#### diffusers.AutoencoderKLLTXVideo[[diffusers.AutoencoderKLLTXVideo]]

```python
diffusers.AutoencoderKLLTXVideo(in_channels: int = 3, out_channels: int = 3, latent_channels: int = 128, block_out_channels: tuple = (128, 256, 512, 512), down_block_types: tuple = ('LTXVideoDownBlock3D', 'LTXVideoDownBlock3D', 'LTXVideoDownBlock3D', 'LTXVideoDownBlock3D'), decoder_block_out_channels: tuple = (128, 256, 512, 512), layers_per_block: tuple = (4, 3, 3, 3, 4), decoder_layers_per_block: tuple = (4, 3, 3, 3, 4), spatio_temporal_scaling: tuple = (True, True, True, False), decoder_spatio_temporal_scaling: tuple = (True, True, True, False), decoder_inject_noise: tuple = (False, False, False, False, False), downsample_type: tuple = ('conv', 'conv', 'conv', 'conv'), upsample_residual: tuple = (False, False, False, False), upsample_factor: tuple = (1, 1, 1, 1), timestep_conditioning: bool = False, patch_size: int = 4, patch_size_t: int = 1, resnet_norm_eps: float = 1e-06, scaling_factor: float = 1.0, encoder_causal: bool = True, decoder_causal: bool = False, spatial_compression_ratio: int = None, temporal_compression_ratio: int = None)
```

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

**Tham số:**

in_channels (`int`, mặc định là `3`) : Số lượng kênh đầu vào.

out_channels (`int`, mặc định là `3`) : Số lượng kênh đầu ra.

latent_channels (`int`, mặc định là `128`) : Số lượng kênh tiềm ẩn.

block_out_channels (`tuple[int, ...]`, mặc định là `(128, 256, 512, 512)`) : Số lượng kênh đầu ra cho mỗi khối.

spatio_temporal_scaling (`tuple[bool, ...], defaults to `(True, True, True, False)` : Whether a block should contain spatio-temporal downscaling or not.

layers_per_block (`tuple[int, ...]`, mặc định là `(4, 3, 3, 3, 4)`) : Số lượng lớp cho mỗi khối.

patch_size (`int`, mặc định là `4`) : Kích thước của các khối không gian.

patch_size_t (`int`, mặc định là `1`) : Kích thước của các patch thời gian.

resnet_norm_eps (`float`, mặc định là `1e-6`) : Giá trị epsilon cho các lớp chuẩn hóa của ResNet.

scaling_factor (`float`, *optional*, mặc định là `1.0`) : Độ lệch chuẩn từng thành phần của không gian tiềm ẩn đã được huấn luyện, được tính toán bằng cách sử dụng lô đầu tiên của tập dữ liệu huấn luyện. Giá trị này được dùng để chuẩn hóa không gian tiềm ẩn sao cho có phương sai bằng đơn vị khi huấn luyện mô hình khuếch tán. Các biến tiềm ẩn được chuẩn hóa bằng công thức `z = z * scaling_factor` trước khi được truyền vào mô hình khuếch tán. Khi giải mã, các biến tiềm ẩn được đưa về thang đo ban đầu bằng công thức: `z = 1 / scaling_factor * z`. Để biết thêm chi tiết, hãy tham khảo các mục 4.3.2 và D.1 của bài báo [High-Resolution Image Synthesis with Latent Diffusion Models](https://huggingface.co/papers/2112.10752).

encoder_causal (`bool`, mặc định là `True`) : Xác định xem bộ mã hóa có nên hoạt động theo kiểu nhân quả (các khung hình trong tương lai chỉ phụ thuộc vào các khung hình trong quá khứ) hay không.

decoder_causal (`bool`, mặc định là `False`) : Xác định xem bộ giải mã có nên hoạt động theo kiểu nhân quả (các khung trong tương lai chỉ phụ thuộc vào các khung trong quá khứ) hay không.

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. Được sử dụng trong [LTX](https://huggingface.co/Lightricks/LTX-Video).

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.AutoencoderKLLTXVideo.decode]]

```python
decode(z: Tensor, temb: typing.Optional[torch.Tensor] = None, return_dict: bool = True)
```

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

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

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

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

**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.AutoencoderKLLTXVideo.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_ltx.py#L1186)

**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.AutoencoderKLLTXVideo.forward]]

```python
forward(sample: Tensor, temb: typing.Optional[torch.Tensor] = None, 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_ltx.py#L1517)

**Tham số:**

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

temb (`torch.Tensor`, *tùy chọn*) : Tensor nhúng bước thời gian tùy chọn được sử dụng để điều kiện hóa bộ giải mã.

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.AutoencoderKLLTXVideo.tiled_decode]]

```python
tiled_decode(z: Tensor, temb: typing.Optional[torch.Tensor], return_dict: bool = True)
```

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

**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.AutoencoderKLLTXVideo.tiled_encode]]

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

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

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

