o
    Gi.                     @   s   d dl mZ d dlZd dlZd dlZddlmZ ddlm	Z	 ddl
mZ ddlmZ dd	lmZmZ dd
lmZmZmZ eeZdd ZG dd deZdS )    )AnyN   )
FrozenDict)AutoencoderKL)logging)VaeImageProcessor   )ModularPipelineBlocksPipelineState)ComponentSpec
InputParamOutputParamc                 C   s   | j \}}}dt||d   }dt||d   }| ||d |d |d dd} | dddddd} | ||d ||} | S )Nr      r   r         )shapeintviewpermutereshape)latentsheightwidthvae_scale_factor
batch_sizenum_patcheschannels r   ]/home/ubuntu/.local/lib/python3.10/site-packages/diffusers/modular_pipelines/flux/decoders.py_unpack_latents    s    r   c                   @   s   e Zd ZdZedee fddZedefddZ	edee
eef  fddZedee fd	d
Ze dedefddZdS )FluxDecodeStepfluxreturnc                 C   s"   t dtt dttddiddgS )Nvaeimage_processorr      from_config)configdefault_creation_method)r   r   r   r   selfr   r   r   expected_components3   s   
z"FluxDecodeStep.expected_componentsc                 C   s   dS )Nz2Step that decodes the denoised latents into imagesr   r)   r   r   r   description?   s   zFluxDecodeStep.descriptionc              	   C   s2   t dddt dddt dddt ddtjd	d
gS )Noutput_typepil)defaultr   i   r   r   Tz,The denoised latents from the denoising step)required	type_hintr,   )r   torchTensorr)   r   r   r   inputsC   s   


zFluxDecodeStep.inputsc                 C   s$   t dttjj tjB tjB ddgS )NimageszUThe generated images, can be a list of PIL.Image.Image, torch.Tensor or a numpy array)r1   r,   )r   listPILImager2   r3   npndarrayr)   r   r   r   intermediate_outputsQ   s   z#FluxDecodeStep.intermediate_outputsstatec                 C   s   |  |}|j}|jdks:|j}t||j|j|j}||jj	 |jj
 }|j|ddd |_|jj|j|jd|_n|j|_| || ||fS )NlatentF)return_dictr   )r-   )get_block_stater#   r-   r   r   r   r   r   r'   scaling_factorshift_factordecoder5   r$   postprocessset_block_state)r*   
componentsr<   block_stater#   r   r   r   r   __call__[   s   


zFluxDecodeStep.__call__N)__name__
__module____qualname__
model_namepropertyr6   r   r+   strr,   tupler   r4   r;   r2   no_gradr
   rG   r   r   r   r   r    0   s    	r    )typingr   numpyr9   r7   r2   configuration_utilsr   modelsr   utilsr   video_processorr   modular_pipeliner	   r
   modular_pipeline_utilsr   r   r   
get_loggerrH   loggerr   r    r   r   r   r   <module>   s   
