
    +jj
                         d dl mZ d dlmZmZ d dlmZ d dlZ G d dej                  Z	 G d de          Z
d	e
fd
ZdS )    )model_management)ComfyExtensionIO)overrideNc                   R    e Zd ZdZed             Zedej        fd            ZeZ	dS )LTXVLatentUpsamplerz4
    Upsamples a video latent by a factor of 2.
    c           
      "   t          j        dddt           j                            d          t           j                            d          t           j                            d          gt           j                                        g          S )Nr   zmodel/latent/videoTsamplesupscale_modelvae)node_idcategoryis_experimentalinputsoutputs)r   SchemaLatentInputLatentUpscaleModelVaeOutput)clss    ?/home/wildlama/comfy/ComfyUI/comfy_extras/nodes_lt_upsampler.pydefine_schemaz!LTXVLatentUpsampler.define_schema   sw    y)) 		**%++O<<U## 	  ""
 
 
 	
    returnc                 B   t          j                    }t          j        |          }t          |                                          j        }|d         }|j        }|t          j        |j                  dz  z  }t          j	        ||           	 |
                    |           |
                    ||          }	 |j        j                            |          } ||          }	|                                 n# |                                 w xY w|j        j                            |	          }	|	
                    |t          j                              }	|                                }
|	|
d<   |
                    dd           t'          j        |
          S )a?  
        Upsample the input latent using the provided model.

        Args:
            samples (dict): Input latent samples
            upscale_model (LatentUpsampler): Loaded upscale model
            vae: VAE model for normalization

        Returns:
            tuple: Tuple containing the upsampled latent
        r
   g     p@)dtypedevice
noise_maskN)r   get_torch_devicemodule_sizenext
parametersr   mathprodshapefree_memorytofirst_stage_modelper_channel_statisticsun_normalizecpu	normalizeintermediate_devicecopypopr   
NodeOutput)r   r
   r   r   r   memory_requiredmodel_dtypelatentsinput_dtypeupsampled_latentsreturn_dicts              r   executezLTXVLatentUpsampler.execute   s    "244*6}EE=335566<)$m49W]33f<<$_f===		 V$$$jj{6jBBG2+BOOPWXXG -g 6 6M1HRR
 
 .00{K[KoKqKq0rrllnn!2Id+++}[)))s   AC> >DN)
__name__
__module____qualname____doc__classmethodr   r   r2   r9   upsample_latent r   r   r   r      sd          
 
 [
 (*R] (* (* (* [(*T OOOr   r   c                   L    e Zd Zedeeej                          fd            ZdS )LTXVLatentUpsamplerExtensionr   c                    K   t           gS N)r   )selfs    r   get_node_listz*LTXVLatentUpsamplerExtension.get_node_listK   s      #$$r   N)	r:   r;   r<   r   listtyper   	ComfyNoderF   r@   r   r   rB   rB   J   sE        %T$r|*<%= % % % X% % %r   rB   r   c                  "   K   t                      S rD   )rB   r@   r   r   comfy_entrypointrK   P   s      ')))r   )comfyr   comfy_api.latestr   r   typing_extensionsr   r%   rI   r   rB   rK   r@   r   r   <module>rO      s    " " " " " " / / / / / / / / & & & & & & @ @ @ @ @", @ @ @F% % % % %> % % %* < * * * * * *r   