Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/diffusers/models/autoencoders/autoencoder_dc.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ def blend_h(self, a: torch.Tensor, b: torch.Tensor, blend_extent: int) -> torch.
b[:, :, :, x] = a[:, :, :, -blend_extent + x] * (1 - x / blend_extent) + b[:, :, :, x] * (x / blend_extent)
return b

def tiled_encode(self, x: torch.Tensor, return_dict: bool = True) -> torch.Tensor:
def tiled_encode(self, x: torch.Tensor, return_dict: bool = True) -> EncoderOutput | tuple[torch.Tensor]:
batch_size, num_channels, height, width = x.shape
latent_height = height // self.spatial_compression_ratio
latent_width = width // self.spatial_compression_ratio
Expand Down Expand Up @@ -664,7 +664,7 @@ def tiled_encode(self, x: torch.Tensor, return_dict: bool = True) -> torch.Tenso
return (encoded,)
return EncoderOutput(latent=encoded)

def tiled_decode(self, z: torch.Tensor, return_dict: bool = True) -> DecoderOutput | torch.Tensor:
def tiled_decode(self, z: torch.Tensor, return_dict: bool = True) -> DecoderOutput | tuple[torch.Tensor]:
batch_size, num_channels, height, width = z.shape

tile_latent_min_height = self.tile_sample_min_height // self.spatial_compression_ratio
Expand Down Expand Up @@ -705,7 +705,7 @@ def tiled_decode(self, z: torch.Tensor, return_dict: bool = True) -> DecoderOutp
return (decoded,)
return DecoderOutput(sample=decoded)

def forward(self, sample: torch.Tensor, return_dict: bool = True) -> torch.Tensor:
def forward(self, sample: torch.Tensor, return_dict: bool = True) -> DecoderOutput | tuple[torch.Tensor]:
r"""
Args:
sample (`torch.Tensor`): Input sample.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ def encode(self, x: torch.Tensor, return_dict: bool = True) -> AutoencoderKLOutp
return AutoencoderKLOutput(latent_dist=posterior)

@apply_forward_hook
def decode(self, z: torch.Tensor, return_dict: bool = True) -> DecoderOutput | tuple:
def decode(self, z: torch.Tensor, return_dict: bool = True) -> DecoderOutput | tuple[torch.Tensor]:
r"""
Decode latents into a video.

Expand Down Expand Up @@ -645,7 +645,7 @@ def forward(
sample_posterior: bool = False,
return_dict: bool = True,
generator: torch.Generator | None = None,
) -> DecoderOutput | tuple:
) -> DecoderOutput | tuple[torch.Tensor]:
r"""
Args:
sample (`torch.Tensor` of shape `(batch_size, channels, num_frames, height, width)`):
Expand Down
8 changes: 4 additions & 4 deletions src/diffusers/models/autoencoders/autoencoder_kl.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def encode(

return AutoencoderKLOutput(latent_dist=posterior)

def _decode(self, z: torch.Tensor, return_dict: bool = True) -> DecoderOutput | torch.Tensor:
def _decode(self, z: torch.Tensor, return_dict: bool = True) -> DecoderOutput | tuple[torch.Tensor]:
if self.use_tiling and (z.shape[-1] > self.tile_latent_min_size or z.shape[-2] > self.tile_latent_min_size):
return self.tiled_decode(z, return_dict=return_dict)

Expand All @@ -213,7 +213,7 @@ def _decode(self, z: torch.Tensor, return_dict: bool = True) -> DecoderOutput |
@apply_forward_hook
def decode(
self, z: torch.FloatTensor, return_dict: bool = True, generator=None
) -> DecoderOutput | torch.FloatTensor:
) -> DecoderOutput | tuple[torch.Tensor]:
"""
Decode a batch of images.

Expand Down Expand Up @@ -361,7 +361,7 @@ def tiled_encode(self, x: torch.Tensor, return_dict: bool = True) -> Autoencoder

return AutoencoderKLOutput(latent_dist=posterior)

def tiled_decode(self, z: torch.Tensor, return_dict: bool = True) -> DecoderOutput | torch.Tensor:
def tiled_decode(self, z: torch.Tensor, return_dict: bool = True) -> DecoderOutput | tuple[torch.Tensor]:
r"""
Decode a batch of images using a tiled decoder.

Expand Down Expand Up @@ -416,7 +416,7 @@ def forward(
sample_posterior: bool = False,
return_dict: bool = True,
generator: torch.Generator | None = None,
) -> DecoderOutput | torch.Tensor:
) -> DecoderOutput | tuple[torch.Tensor]:
r"""
Args:
sample (`torch.Tensor`): Input sample.
Expand Down
4 changes: 2 additions & 2 deletions src/diffusers/models/autoencoders/autoencoder_kl_allegro.py
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ def _decode(self, z: torch.Tensor) -> torch.Tensor:
raise NotImplementedError("Decoding without tiling has not been implemented yet.")

@apply_forward_hook
def decode(self, z: torch.Tensor, return_dict: bool = True) -> DecoderOutput | torch.Tensor:
def decode(self, z: torch.Tensor, return_dict: bool = True) -> DecoderOutput | tuple[torch.Tensor]:
"""
Decode a batch of videos.

Expand Down Expand Up @@ -1044,7 +1044,7 @@ def forward(
sample_posterior: bool = False,
return_dict: bool = True,
generator: torch.Generator | None = None,
) -> DecoderOutput | torch.Tensor:
) -> DecoderOutput | tuple[torch.Tensor]:
r"""
Args:
sample (`torch.Tensor`): Input sample.
Expand Down
12 changes: 7 additions & 5 deletions src/diffusers/models/autoencoders/autoencoder_kl_cogvideox.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ def fake_context_parallel_forward(
inputs = torch.cat(cached_inputs + [inputs], dim=2)
return inputs

def forward(self, inputs: torch.Tensor, conv_cache: torch.Tensor | None = None) -> torch.Tensor:
def forward(
self, inputs: torch.Tensor, conv_cache: torch.Tensor | None = None
) -> tuple[torch.Tensor, torch.Tensor | None]:
inputs = self.fake_context_parallel_forward(inputs, conv_cache)

if self.pad_mode == "replicate":
Expand Down Expand Up @@ -1176,7 +1178,7 @@ def encode(
return (posterior,)
return AutoencoderKLOutput(latent_dist=posterior)

def _decode(self, z: torch.Tensor, return_dict: bool = True) -> DecoderOutput | torch.Tensor:
def _decode(self, z: torch.Tensor, return_dict: bool = True) -> DecoderOutput | tuple[torch.Tensor]:
batch_size, num_channels, num_frames, height, width = z.shape

if self.use_tiling and (width > self.tile_latent_min_width or height > self.tile_latent_min_height):
Expand Down Expand Up @@ -1205,7 +1207,7 @@ def _decode(self, z: torch.Tensor, return_dict: bool = True) -> DecoderOutput |
return DecoderOutput(sample=dec)

@apply_forward_hook
def decode(self, z: torch.Tensor, return_dict: bool = True) -> DecoderOutput | torch.Tensor:
def decode(self, z: torch.Tensor, return_dict: bool = True) -> DecoderOutput | tuple[torch.Tensor]:
"""
Decode a batch of images.

Expand Down Expand Up @@ -1319,7 +1321,7 @@ def tiled_encode(self, x: torch.Tensor) -> torch.Tensor:
enc = torch.cat(result_rows, dim=3)
return enc

def tiled_decode(self, z: torch.Tensor, return_dict: bool = True) -> DecoderOutput | torch.Tensor:
def tiled_decode(self, z: torch.Tensor, return_dict: bool = True) -> DecoderOutput | tuple[torch.Tensor]:
r"""
Decode a batch of images using a tiled decoder.

Expand Down Expand Up @@ -1408,7 +1410,7 @@ def forward(
sample_posterior: bool = False,
return_dict: bool = True,
generator: torch.Generator | None = None,
) -> torch.Tensor | torch.Tensor:
) -> DecoderOutput | tuple[torch.Tensor]:
r"""
Args:
sample (`torch.Tensor`): Input sample.
Expand Down
8 changes: 4 additions & 4 deletions src/diffusers/models/autoencoders/autoencoder_kl_flux2.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def encode(

return AutoencoderKLOutput(latent_dist=posterior)

def _decode(self, z: torch.Tensor, return_dict: bool = True) -> DecoderOutput | torch.Tensor:
def _decode(self, z: torch.Tensor, return_dict: bool = True) -> DecoderOutput | tuple[torch.Tensor]:
if self.use_tiling and (z.shape[-1] > self.tile_latent_min_size or z.shape[-2] > self.tile_latent_min_size):
return self.tiled_decode(z, return_dict=return_dict)

Expand All @@ -225,7 +225,7 @@ def _decode(self, z: torch.Tensor, return_dict: bool = True) -> DecoderOutput |
@apply_forward_hook
def decode(
self, z: torch.FloatTensor, return_dict: bool = True, generator=None
) -> DecoderOutput | torch.FloatTensor:
) -> DecoderOutput | tuple[torch.Tensor]:
"""
Decode a batch of images.

Expand Down Expand Up @@ -373,7 +373,7 @@ def tiled_encode(self, x: torch.Tensor, return_dict: bool = True) -> Autoencoder

return AutoencoderKLOutput(latent_dist=posterior)

def tiled_decode(self, z: torch.Tensor, return_dict: bool = True) -> DecoderOutput | torch.Tensor:
def tiled_decode(self, z: torch.Tensor, return_dict: bool = True) -> DecoderOutput | tuple[torch.Tensor]:
r"""
Decode a batch of images using a tiled decoder.

Expand Down Expand Up @@ -428,7 +428,7 @@ def forward(
sample_posterior: bool = False,
return_dict: bool = True,
generator: torch.Generator | None = None,
) -> DecoderOutput | torch.Tensor:
) -> DecoderOutput | tuple[torch.Tensor]:
r"""
Args:
sample (`torch.Tensor`): Input sample.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ def encode(
return (posterior,)
return AutoencoderKLOutput(latent_dist=posterior)

def _decode(self, z: torch.Tensor, return_dict: bool = True) -> DecoderOutput | torch.Tensor:
def _decode(self, z: torch.Tensor, return_dict: bool = True) -> DecoderOutput | tuple[torch.Tensor]:
batch_size, num_channels, num_frames, height, width = z.shape
tile_latent_min_height = self.tile_sample_min_height // self.spatial_compression_ratio
tile_latent_min_width = self.tile_sample_min_width // self.spatial_compression_ratio
Expand All @@ -823,7 +823,7 @@ def _decode(self, z: torch.Tensor, return_dict: bool = True) -> DecoderOutput |
return DecoderOutput(sample=dec)

@apply_forward_hook
def decode(self, z: torch.Tensor, return_dict: bool = True) -> DecoderOutput | torch.Tensor:
def decode(self, z: torch.Tensor, return_dict: bool = True) -> DecoderOutput | tuple[torch.Tensor]:
r"""
Decode a batch of images.

Expand Down Expand Up @@ -922,7 +922,7 @@ def tiled_encode(self, x: torch.Tensor) -> AutoencoderKLOutput:
enc = torch.cat(result_rows, dim=3)[:, :, :, :latent_height, :latent_width]
return enc

def tiled_decode(self, z: torch.Tensor, return_dict: bool = True) -> DecoderOutput | torch.Tensor:
def tiled_decode(self, z: torch.Tensor, return_dict: bool = True) -> DecoderOutput | tuple[torch.Tensor]:
r"""
Decode a batch of images using a tiled decoder.

Expand Down Expand Up @@ -1011,7 +1011,7 @@ def _temporal_tiled_encode(self, x: torch.Tensor) -> AutoencoderKLOutput:
enc = torch.cat(result_row, dim=2)[:, :, :latent_num_frames]
return enc

def _temporal_tiled_decode(self, z: torch.Tensor, return_dict: bool = True) -> DecoderOutput | torch.Tensor:
def _temporal_tiled_decode(self, z: torch.Tensor, return_dict: bool = True) -> DecoderOutput | tuple[torch.Tensor]:
batch_size, num_channels, num_frames, height, width = z.shape
num_sample_frames = (num_frames - 1) * self.temporal_compression_ratio + 1

Expand Down Expand Up @@ -1053,7 +1053,7 @@ def forward(
sample_posterior: bool = False,
return_dict: bool = True,
generator: torch.Generator | None = None,
) -> DecoderOutput | torch.Tensor:
) -> DecoderOutput | tuple[torch.Tensor]:
r"""
Args:
sample (`torch.Tensor`): Input sample.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ def _decode(self, z: torch.Tensor, return_dict: bool = True):
return DecoderOutput(sample=dec)

@apply_forward_hook
def decode(self, z: torch.Tensor, return_dict: bool = True) -> DecoderOutput | torch.Tensor:
def decode(self, z: torch.Tensor, return_dict: bool = True) -> DecoderOutput | tuple[torch.Tensor]:
r"""
Decode a batch of images.

Expand Down Expand Up @@ -619,7 +619,7 @@ def tiled_encode(self, x: torch.Tensor) -> torch.Tensor:

return moments

def tiled_decode(self, z: torch.Tensor, return_dict: bool = True) -> DecoderOutput | torch.Tensor:
def tiled_decode(self, z: torch.Tensor, return_dict: bool = True) -> DecoderOutput | tuple[torch.Tensor]:
"""
Decode latent using spatial tiling strategy.

Expand Down Expand Up @@ -670,7 +670,7 @@ def forward(
sample_posterior: bool = False,
return_dict: bool = True,
generator: torch.Generator | None = None,
) -> DecoderOutput | torch.Tensor:
) -> DecoderOutput | tuple[torch.Tensor]:
"""
Args:
sample (`torch.Tensor`): Input sample.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ def _decode(self, z: torch.Tensor) -> torch.Tensor:
return dec

@apply_forward_hook
def decode(self, z: torch.Tensor, return_dict: bool = True) -> DecoderOutput | torch.Tensor:
def decode(self, z: torch.Tensor, return_dict: bool = True) -> DecoderOutput | tuple[torch.Tensor]:
r"""
Decode a batch of images.

Expand Down Expand Up @@ -896,7 +896,7 @@ def forward(
sample_posterior: bool = False,
return_dict: bool = True,
generator: torch.Generator | None = None,
) -> DecoderOutput | torch.Tensor:
) -> DecoderOutput | tuple[torch.Tensor]:
r"""
Args:
sample (`torch.Tensor`): Input sample.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ def _decode(self, z: torch.Tensor) -> torch.Tensor:
return dec

@apply_forward_hook
def decode(self, z: torch.Tensor, return_dict: bool = True) -> DecoderOutput | torch.Tensor:
def decode(self, z: torch.Tensor, return_dict: bool = True) -> DecoderOutput | tuple[torch.Tensor]:
r"""
Decode a batch of images.

Expand Down Expand Up @@ -929,7 +929,7 @@ def forward(
sample_posterior: bool = False,
return_dict: bool = True,
generator: torch.Generator | None = None,
) -> DecoderOutput | torch.Tensor:
) -> DecoderOutput | tuple[torch.Tensor]:
r"""
Args:
sample (`torch.Tensor`): Input sample.
Expand Down
8 changes: 4 additions & 4 deletions src/diffusers/models/autoencoders/autoencoder_kl_kvae.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ def encode(

return AutoencoderKLOutput(latent_dist=posterior)

def _decode(self, z: torch.Tensor, return_dict: bool = True) -> Union[DecoderOutput, torch.Tensor]:
def _decode(self, z: torch.Tensor, return_dict: bool = True) -> Union[DecoderOutput, tuple[torch.Tensor]]:
if self.use_tiling and (z.shape[-1] > self.tile_latent_min_size or z.shape[-2] > self.tile_latent_min_size):
return self.tiled_decode(z, return_dict=return_dict)

Expand All @@ -642,7 +642,7 @@ def _decode(self, z: torch.Tensor, return_dict: bool = True) -> Union[DecoderOut
@apply_forward_hook
def decode(
self, z: torch.FloatTensor, return_dict: bool = True, generator=None
) -> Union[DecoderOutput, torch.FloatTensor]:
) -> Union[DecoderOutput, tuple[torch.Tensor]]:
"""
Decode a batch of images.

Expand Down Expand Up @@ -726,7 +726,7 @@ def _tiled_encode(self, x: torch.Tensor) -> torch.Tensor:
enc = torch.cat(result_rows, dim=2)
return enc

def tiled_decode(self, z: torch.Tensor, return_dict: bool = True) -> Union[DecoderOutput, torch.Tensor]:
def tiled_decode(self, z: torch.Tensor, return_dict: bool = True) -> Union[DecoderOutput, tuple[torch.Tensor]]:
r"""
Decode a batch of images using a tiled decoder.

Expand Down Expand Up @@ -779,7 +779,7 @@ def forward(
sample_posterior: bool = False,
return_dict: bool = True,
generator: Optional[torch.Generator] = None,
) -> Union[DecoderOutput, torch.Tensor]:
) -> Union[DecoderOutput, tuple[torch.Tensor]]:
r"""
Args:
sample (`torch.Tensor`): Input sample.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ def _decode(self, z: torch.Tensor) -> torch.Tensor:
return self.decoder(z)

@apply_forward_hook
def decode(self, z: torch.Tensor, return_dict: bool = True) -> DecoderOutput | torch.Tensor:
def decode(self, z: torch.Tensor, return_dict: bool = True) -> DecoderOutput | tuple[torch.Tensor]:
"""
Decode a batch of latents into audio waveforms.

Expand Down Expand Up @@ -382,7 +382,7 @@ def forward(
sample_posterior: bool = False,
return_dict: bool = True,
generator: Optional[torch.Generator] = None,
) -> DecoderOutput | torch.Tensor:
) -> DecoderOutput | tuple[torch.Tensor]:
r"""
Args:
sample (`torch.Tensor` of shape `(batch_size, num_channels, num_samples)`):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,7 @@ def _decode(self, z: torch.Tensor, seg_len: int = 16) -> torch.Tensor:
return torch.cat(recs, dim=2)

@apply_forward_hook
def decode(self, z: torch.Tensor, return_dict: bool = True) -> Union[DecoderOutput, torch.Tensor]:
def decode(self, z: torch.Tensor, return_dict: bool = True) -> Union[DecoderOutput, tuple[torch.Tensor]]:
"""
Decode a batch of videos.

Expand Down Expand Up @@ -941,7 +941,7 @@ def forward(
sample_posterior: bool = False,
return_dict: bool = True,
generator: Optional[torch.Generator] = None,
) -> Union[DecoderOutput, torch.Tensor]:
) -> Union[DecoderOutput, tuple[torch.Tensor]]:
r"""
Args:
sample (`torch.Tensor`): Input sample.
Expand Down
Loading
Loading