o
    ie	                     @   s.   d dl mZ d dlZG dd dZdeiZdS )    )model_managementNc                   @   s>   e Zd ZdZedd ZdZdZdZdZ	de
d	efd
dZdS )LTXVLatentUpsamplerz4
    Upsamples a video latent by a factor of 2.
    c                 C   s   dddddiS )NrequiredLATENT)LATENT_UPSCALE_MODEL)VAE)samplesupscale_modelvae )sr   r   =/mnt/c/Users/fbmor/ComfyUI/comfy_extras/nodes_lt_upsampler.pyINPUT_TYPES	   s   zLTXVLatentUpsampler.INPUT_TYPESr   upsample_latentzlatent/videoTr	   returnc                 C   s   t  }t |}t| j}|d }|j}|t|jd 7 }t 	|| z|
| |j
||d}	 |jj|}||}	W |  n|  w |jj|	}	|	j
|t  d}	| }
|	|
d< |
dd |
f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
            auto_tiling (bool): Whether to automatically tile the input for processing

        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pop)selfr	   r
   r   r   memory_requiredmodel_dtypelatentsinput_dtypeupsampled_latentsreturn_dictr   r   r   r      s,   


z#LTXVLatentUpsampler.upsample_latentN)__name__
__module____qualname____doc__classmethodr   RETURN_TYPESFUNCTIONCATEGORYEXPERIMENTALdicttupler   r   r   r   r   r      s    
	r   )comfyr   r   r   NODE_CLASS_MAPPINGSr   r   r   r   <module>   s
    F