o
    پie                     @   s  d dl mZ d dlmZmZ d dlZd dlmZmZm	Z	 d dl
mZ d dlmZmZmZ d dlmZ d dlmZmZ d d	lmZ eeZd
edejfddZeG dd deZeG dd deZeG dd deZeG dd deZeG dd deeZeG dd deZ eG dd de Z!eG dd deZ"eG dd deeZ#eG d d! d!e#Z$eG d"d# d#eZ%eG d$d% d%eZ&eG d&d' d'eZ'dS )(    )Callable)	dataclassfieldN)	DiTConfigEncoderConfig	VAEConfig)WanVideoConfig)BaseEncoderOutputCLIPVisionConfigT5Config)WanVAEConfig)ModelTaskTypePipelineConfig)init_loggeroutputsreturnc                 C   sl   | j }| j}|djdd }t| dksJ dd t||ddD }tjdd |D dd}|S )	Nr      )dimc                 S   s   g | ]
\}}|d | qS N ).0uvr   r   f/home/ubuntu/.local/lib/python3.10/site-packages/sglang/multimodal_gen/configs/pipeline_configs/wan.py
<listcomp>   s    z't5_postprocess_text.<locals>.<listcomp>T)strictc                 S   s2   g | ]}t ||d |d |dgqS )i   r   r   )torchcat	new_zerossize)r   r   r   r   r   r   !   s    $)	attention_masklast_hidden_stategtsumlongr   isnanzipstack)r   _text_inputsmaskhidden_stateseq_lensprompt_embedsprompt_embeds_tensorr   r   r   t5_postprocess_text   s   r.   c                   @   s   e Zd Zdd ZdS )WanI2VCommonConfigc                 C   s@   | j jj}|| dkrtd| d || | d }|S |S )Nr   z(`num_frames - 1` has to be divisible by z!. Rounding to the nearest number.)
vae_configarch_configscale_factor_temporalloggerwarning)self
num_framesvae_scale_factor_temporalr   r   r   adjust_num_frames-   s   

z$WanI2VCommonConfig.adjust_num_framesN)__name__
__module____qualname__r8   r   r   r   r   r/   *   s    r/   c                   @   s   e Zd ZU dZejZeed< ee	dZ
eed< eedZeed< dZeed< dZeed< d	Zed
B ed< edd dZeedf ed< edd dZeeegejf df ed< dZeed< dZeed< edd dZeedf ed< dd Z d
S )WanT2V480PConfig:Base configuration for Wan T2V 1.3B pipeline architecture.	task_typedefault_factory
dit_configr0   F
vae_tilingvae_spg      @N
flow_shiftc                   C   s   t  fS r   )r   r   r   r   r   <lambda>M       zWanT2V480PConfig.<lambda>.text_encoder_configsc                   C   s   t fS r   )r.   r   r   r   r   rE   P   s    postprocess_text_funcsbf16	precisionfp32vae_precisionc                   C   s   dS )N)rK   r   r   r   r   r   rE   V   s    text_encoder_precisionsc                 C   s   d| j _d| j _d S )NFTr0   load_encoderload_decoderr5   r   r   r   __post_init__Z      zWanT2V480PConfig.__post_init__)!r9   r:   r;   __doc__r   T2Vr>   __annotations__r   r   rA   r   r   r0   r   rB   boolrC   rD   floatrG   tupler   rH   r   r	   r   TensorrJ   strrL   rM   rR   r   r   r   r   r<   :   s"   
 r<   c                   @   @   e Zd ZU dZdZedB ed< edd dZe	e
 dB ed< dS )	TurboWanT2V480PConfigr=          @NrD   c                   C      g dS )N)i    T  `  r   r   r   r   r   rE   e   rF   zTurboWanT2V480PConfig.<lambda>r?   dmd_denoising_stepsr9   r:   r;   rT   rD   rX   rV   r   rc   listintr   r   r   r   r]   _   s   
 r]   c                   @   s"   e Zd ZU dZdZedB ed< dS )WanT2V720PConfigz>Base configuration for Wan T2V 14B 720P pipeline architecture.      @NrD   )r9   r:   r;   rT   rD   rX   rV   r   r   r   r   rg   i   s   
 rg   c                   @   sr   e Zd ZU dZdZeed< ejZ	eed< e
edZeed< dZeed< e
d	d
 dZeed< dd ZdddZdS )WanI2V480PConfigz>Base configuration for Wan I2V 14B 480P pipeline architecture.i  max_arear>   r?   image_encoder_configrK   image_encoder_precisionc                   C   s
   t ddS )NT)output_hidden_states)dictr   r   r   r   rE      s    zWanI2V480PConfig.<lambda>image_encoder_extra_argsc                 C   s
   |j d S )N)hidden_states)r5   imager   r   r   postprocess_image   s   
z"WanI2V480PConfig.postprocess_imager   Nc                 C   s   d| j _d| j _d S NTrN   rQ   r   r   r   rR      rS   zWanI2V480PConfig.__post_init__r   N)r9   r:   r;   rT   rj   rf   rV   r   I2Vr>   r   r
   rk   r   rl   r[   ro   rn   rs   rR   r   r   r   r   ri   s   s   
 ri   c                   @   s.   e Zd ZU dZdZeed< dZedB ed< dS )WanI2V720PConfigz>Base configuration for Wan I2V 14B 720P pipeline architecture.i  rj   rh   NrD   )	r9   r:   r;   rT   rj   rf   rV   rD   rX   r   r   r   r   rw      s   
 rw   c                   @   sV   e Zd ZU dZedB ed< edd dZee	 dB ed< dZ
edB ed	< dddZdS )TurboWanI2V720Configr^   NrD   c                   C   r_   )N)i  r`   ra   rb   r   r   r   r   r   rE      rF   zTurboWanI2V720Config.<lambda>r?   rc   ?boundary_ratior   c                 C      | j | j_ d S r   rz   rA   rQ   r   r   r   rR         z"TurboWanI2V720Config.__post_init__ru   )r9   r:   r;   rD   rX   rV   r   rc   re   rf   rz   rR   r   r   r   r   rx      s   
 rx   c                   @   r\   )	FastWan2_1_T2V_480P_ConfigzKBase configuration for FastWan T2V 1.3B 480P pipeline architecture with DMDr^   NrD   c                   C   r_   N)  i  i
  r   r   r   r   r   rE      rF   z#FastWan2_1_T2V_480P_Config.<lambda>r?   rc   rd   r   r   r   r   r~      s   
 r~   c                   @   sN   e Zd ZU dZedB ed< ejZeed< dZ	e
ed< dZdd	 ZdddZdS )Wan2_2_TI2V_5B_Configrh   NrD   r>   Texpand_timesteps)      r   c           
      C   sB   |}| j jj}| j}|j}|j}|||||d  ||d  f}	|	S )Nr      )r0   r1   z_dim
vae_strideheightwidth)
r5   batch
batch_sizer6   Fr   r   ohowshaper   r   r   prepare_latent_shape   s   
z*Wan2_2_TI2V_5B_Config.prepare_latent_shaper   c                 C   s   d| j _d| j _| j| j_d S rt   )r0   rO   rP   r   rA   rQ   r   r   r   rR      s   z#Wan2_2_TI2V_5B_Config.__post_init__ru   )r9   r:   r;   rD   rX   rV   r   TI2Vr>   r   rW   r   r   rR   r   r   r   r   r      s   
 	r   c                   @   s<   e Zd ZU dZedB ed< edd dZee	 dB ed< dS )FastWan2_2_TI2V_5B_Configrh   NrD   c                   C   r_   r   r   r   r   r   r   rE      rF   z"FastWan2_2_TI2V_5B_Config.<lambda>r?   rc   )
r9   r:   r;   rD   rX   rV   r   rc   re   rf   r   r   r   r   r      s
   
 r   c                   @   s8   e Zd ZU dZedB ed< dZedB ed< d	ddZdS )
Wan2_2_T2V_A14B_Configg      (@NrD   g      ?rz   r   c                 C   r{   r   r|   rQ   r   r   r   rR      r}   z$Wan2_2_T2V_A14B_Config.__post_init__ru   )r9   r:   r;   rD   rX   rV   rz   rR   r   r   r   r   r      s   
 r   c                       s@   e Zd ZU dZedB ed< dZedB ed< d	 fddZ  ZS )
Wan2_2_I2V_A14B_Configrh   NrD   ry   rz   r   c                    s   t    | j| j_d S r   )superrR   rz   rA   rQ   	__class__r   r   rR      s   
z$Wan2_2_I2V_A14B_Config.__post_init__ru   )	r9   r:   r;   rD   rX   rV   rz   rR   __classcell__r   r   r   r   r      s   
 r   c                   @   sT   e Zd ZU dZeed< dZedB ed< edd dZ	e
e dB ed	< dZeed
< dS )SelfForcingWanT2V480PConfigT	is_causalrh   NrD   c                   C   r_   )N)r   i  i     r   r   r   r   r   rE      rF   z$SelfForcingWanT2V480PConfig.<lambda>r?   rc   warp_denoising_step)r9   r:   r;   r   rW   rV   rD   rX   r   rc   re   rf   r   r   r   r   r   r      s   
 r   )(collections.abcr   dataclassesr   r   r   $sglang.multimodal_gen.configs.modelsr   r   r   )sglang.multimodal_gen.configs.models.ditsr   -sglang.multimodal_gen.configs.models.encodersr	   r
   r   )sglang.multimodal_gen.configs.models.vaesr   3sglang.multimodal_gen.configs.pipeline_configs.baser   r   1sglang.multimodal_gen.runtime.utils.logging_utilsr   r9   r3   rZ   r.   r/   r<   r]   rg   ri   rw   rx   r~   r   r   r   r   r   r   r   r   r   <module>   sJ   $		
