Diffusers documentation
Bộ giải mã nhất quán
Bộ giải mã nhất quán
Consistency decoder có thể được sử dụng để giải mã các latents từ denoising UNet trong StableDiffusionPipeline. Bộ giải mã này được giới thiệu trong báo cáo kỹ thuật DALL-E 3.
Mã nguồn gốc có thể được tìm thấy tại openai/consistencydecoder.
Hiện tại, suy luận chỉ được hỗ trợ cho 2 lần lặp.
Pipeline này không thể được đóng góp mà không có sự giúp đỡ của madebyollin và mrsteyk từ vấn đề này.
ConsistencyDecoderVAE
lớp diffusers.ConsistencyDecoderVAE
< source >( scaling_factor: float = 0.18215latent_channels: int = 4sample_size: int = 32encoder_act_fn: str = 'silu'encoder_block_out_channels: tuple = (128, 256, 512, 512)encoder_double_z: bool = Trueencoder_down_block_types: tuple = ('DownEncoderBlock2D', 'DownEncoderBlock2D', 'DownEncoderBlock2D', 'DownEncoderBlock2D')encoder_in_channels: int = 3encoder_layers_per_block: int = 2encoder_norm_num_groups: int = 32encoder_out_channels: int = 4decoder_add_attention: bool = Falsedecoder_block_out_channels: tuple = (320, 640, 1024, 1024)decoder_down_block_types: tuple = ('ResnetDownsampleBlock2D', 'ResnetDownsampleBlock2D', 'ResnetDownsampleBlock2D', 'ResnetDownsampleBlock2D')decoder_downsample_padding: int = 1decoder_in_channels: int = 7decoder_layers_per_block: int = 3decoder_norm_eps: float = 1e-05decoder_norm_num_groups: int = 32decoder_num_train_timesteps: int = 1024decoder_out_channels: int = 6decoder_resnet_time_scale_shift: str = 'scale_shift'decoder_time_embedding_type: str = 'learned'decoder_up_block_types: tuple = ('ResnetUpsampleBlock2D', 'ResnetUpsampleBlock2D', 'ResnetUpsampleBlock2D', 'ResnetUpsampleBlock2D') )
Bộ giải mã tính nhất quán được sử dụng với DALL-E 3.
Ví dụ:
>>> import torch
>>> from diffusers import StableDiffusionPipeline, ConsistencyDecoderVAE
>>> vae = ConsistencyDecoderVAE.from_pretrained("openai/consistency-decoder", torch_dtype=torch.float16)
>>> pipe = StableDiffusionPipeline.from_pretrained(
... "stable-diffusion-v1-5/stable-diffusion-v1-5", vae=vae, torch_dtype=torch.float16
... ).to("cuda")
>>> image = pipe("horse", generator=torch.manual_seed(0)).images[0]
>>> imagedecode
< source >( z: Tensorgenerator: typing.Optional[torch.Generator] = Nonereturn_dict: bool = Truenum_inference_steps: int = 2 ) → DecoderOutput | tuple[torch.Tensor]
Tham số
- z (torch.Tensor) — Vector ẩn đầu vào.
- generator (torch.Generator | None) — Bộ tạo số ngẫu nhiên. Mặc định là None.
- return_dict (bool) — Xác định có trả về kết quả dưới dạng từ điển hay không. Mặc định là True.
- num_inference_steps (int) — Số bước suy luận. Mặc định là 2.
Trả về
DecoderOutput | tuple[torch.Tensor]
Đầu ra đã được giải mã.
Giải mã vector ẩn đầu vào z bằng mô hình VAE consistency decoder.
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 ) → 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ặc định làNone) — Bộ sinh (Generator) được sử dụng để lấy mẫu.
Trả về
DecoderOutput hoặc tuple
If return_dict is True, a DecoderOutput is returned, otherwise a plain tuple is returned.
Tắt các bộ xử lý chú ý tùy chỉnh và đặt cài đặt chú ý mặc định.
tiled_encode
< source >( x: Tensorreturn_dict: bool = True ) → ConsistencyDecoderVAEOutput or tuple
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ộtConsistencyDecoderVAEOutputthay vì một tuple đơn thuần hay không.
Trả về
ConsistencyDecoderVAEOutput hoặc tuple
If return_dict is True, a ConsistencyDecoderVAEOutput
is returned, otherwise a plain tuple is returned.
Mã hóa một lô ảnh bằng trình mã hóa 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 ô (tiles) để tính toán mã hóa qua nhiều bước. Điều này hữu ích để giữ cho việc sử dụng bộ nhớ luôn ổn định bất kể kích thước hình ảnh. Kết quả cuối cùng của mã hóa theo ô khác với mã hóa không theo ô vì mỗi ô sử dụng một bộ mã hóa khác nhau. Để tránh các hiện tượng méo do chia ô, các ô sẽ chồng lấn lên nhau và được trộn lẫn để tạo ra đầu vào mượt mà. Bạn vẫn có thể thấy những thay đổi theo kích thước ô trong đầu ra, nhưng chúng sẽ ít dễ nhận thấy hơn nhiều.