Diffusers documentation
AutoencoderKLHunyuanImage
AutoencoderKLHunyuanImage
Mô hình autoencoder biến phân (VAE) 2D với tổn thất KL được sử dụng trong [HunyuanImage2.1].
Mô hình có thể được tải bằng đoạn mã sau.
from diffusers import AutoencoderKLHunyuanImage
vae = AutoencoderKLHunyuanImage.from_pretrained("hunyuanvideo-community/HunyuanImage-2.1-Diffusers", subfolder="vae", dtype=torch.bfloat16)AutoencoderKLHunyuanImage
lớp diffusers.AutoencoderKLHunyuanImage
< source >( in_channels: intout_channels: intlatent_channels: intblock_out_channels: tuplelayers_per_block: intspatial_compression_ratio: intsample_size: intscaling_factor: float = Nonedownsample_match_channel: bool = Trueupsample_match_channel: bool = True )
Một mô hình VAE cho hình ảnh 2D với hỗ trợ chia ô không gian.
Mô hình này kế thừa từ 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
< source >( z: Tensorreturn_dict: bool = True ) → ~models.vae.DecoderOutput or tuple
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.DecoderOutputthay 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.
enable_tiling
< source >( tile_sample_min_size: int | None = Nonetile_overlap_factor: float | None = None )
Bật giải mã VAE theo ô không gian. Khi tùy chọn này được bật, VAE sẽ chia tensor đầu vào thành các ô để 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.
encode
< source >( x: Tensorreturn_dict: bool = True )
Mã hóa một lô ảnh thành các biến ẩn.
forward
< source >( sample: Tensorsample_posterior: bool = Falsereturn_dict: bool = Truegenerator: typing.Optional[torch.Generator] = None ) → ~models.vae.DecoderOutput or tuple
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ừ posterior hay không. - return_dict (
bool, tùy chọn, mặc định làTrue) — Có nên trả về mộtDecoderOutputthay vì một tuple thông thường hay không. - generator (
torch.Generator, tùy chọn) — Mộttorch.Generatorđể 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
< source >( z: Tensorreturn_dict: bool = True ) → ~models.vae.DecoderOutput or tuple
Tham số
- z (
torch.Tensor) — Tensor ẩn có hình dạng (B, C, H, W). - return_dict (
bool, tùy chọn, mặc định làTrue) — Có nên trả về một~models.vae.DecoderOutputthay 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ã ẩn bằng chiến lược lát hóa không gian.
tiled_encode
< source >( x: Tensor ) → torch.Tensor
Mã hóa đầu vào bằng chiến lược lát hóa không gian.
DecoderOutput
lớp diffusers.models.autoencoders.vae.DecoderOutput
< source >( sample: Tensorcommit_loss: typing.Optional[torch.FloatTensor] = None )
Đầu ra của phương pháp giải mã.