Skip to content

Commit 7a4324c

Browse files
Add a docstring for the AutoencoderKL's encode (huggingface#5239)
* Add docstring for the AutoencoderKL's encode huggingface#5229 * Support Python 3.8 syntax in AutoencoderKL.decode type hints Co-authored-by: Patrick von Platen <[email protected]> * Follow the style guidelines in AutoencoderKL's encode huggingface#5230 --------- Co-authored-by: stano <> Co-authored-by: Patrick von Platen <[email protected]>
1 parent 37a787a commit 7a4324c

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/diffusers/models/autoencoder_kl.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,21 @@ def set_default_attn_processor(self):
249249
self.set_attn_processor(processor, _remove_lora=True)
250250

251251
@apply_forward_hook
252-
def encode(self, x: torch.FloatTensor, return_dict: bool = True) -> AutoencoderKLOutput:
252+
def encode(
253+
self, x: torch.FloatTensor, return_dict: bool = True
254+
) -> Union[AutoencoderKLOutput, Tuple[DiagonalGaussianDistribution]]:
255+
"""
256+
Encode a batch of images into latents.
257+
258+
Args:
259+
x (`torch.FloatTensor`): Input batch of images.
260+
return_dict (`bool`, *optional*, defaults to `True`):
261+
Whether to return a [`~models.autoencoder_kl.AutoencoderKLOutput`] instead of a plain tuple.
262+
263+
Returns:
264+
The latent representations of the encoded images. If `return_dict` is True, a
265+
[`~models.autoencoder_kl.AutoencoderKLOutput`] is returned, otherwise a plain `tuple` is returned.
266+
"""
253267
if self.use_tiling and (x.shape[-1] > self.tile_sample_min_size or x.shape[-2] > self.tile_sample_min_size):
254268
return self.tiled_encode(x, return_dict=return_dict)
255269

0 commit comments

Comments
 (0)