
    ^(j                     d    d Z ddlZddlZddlmZ ddlmZ ddlmZ  G d d      Z G d	 d
      Zy)a  
    This file is part of ComfyUI.
    Copyright (C) 2024 Comfy

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
    N   )
model_base)utils)latent_formatsc                       e Zd Zd Zy)
ClipTargetc                 .    || _         || _        i | _        y N)clip	tokenizerparams)selfr   r   s      E/Users/danicosta/Desktop/Flux2/ComfyUI/comfy/supported_models_base.py__init__zClipTarget.__init__   s    	"    N)__name__
__module____qualname__r    r   r   r   r      s    r   r   c                      e Zd Zi ZdddZi Zg ZdZdZi Z	e
j                  ZdgZdgZej                   ej"                  ej$                  gZdZdZdZdZdd	iZedd
       ZddZd Zd ZddZd Zd Z d Z!d Z"d Z#d Z$d Z%d Z&d Z'y)BASE@   )	num_headsnum_head_channelsNzfirst_stage_model.zcond_stage_model.g       @fp8Fc                     | j                   D ]  }||vs| j                   |   ||   k7  s y || j                  D ]  }||vs y y)NFT)unet_configrequired_keys)sr   
state_dictks       r   matcheszBASE.matches8   sU    A#q}}Q'7;q>'I  !__J&  % r   c                 6    t         j                  j                  S r
   )r   	ModelTypeEPS)r   r!   prefixs      r   
model_typezBASE.model_typeC   s    ##'''r   c                 &    | j                   d   dkD  S )Nin_channels   )r   )r   s    r   inpaint_modelzBASE.inpaint_modelF   s    .22r   c                 .   |j                         | _        | j                  j                         | _        | j                         | _        | j                  j                         | _        | j
                  D ]  }| j
                  |   | j                  |<     y r
   )copyr   sampling_settingslatent_formatoptimizationsunet_extra_config)r   r   xs      r   r   zBASE.__init__I   s}    &++-!%!7!7!<!<!>!//1!//446''A"&"8"8";DQ (r   c                    | j                   4t        j                  | | j                   | j                  ||      |      }n(t        j                  | | j                  ||      |      }| j                         r|j                          |S )N)r(   device)noise_aug_configr   
SD21UNCLIPr(   	BaseModelr,   set_inpaint)r   r!   r'   r5   outs        r   	get_modelzBASE.get_modelQ   s~      ,''d.C.CPTP_P_`jlrPs  }C  DC&&t
TZ8[djkCOO
r   c                 r    t        j                  || j                  D ci c]  }|d c}d      }|S c c}w )N T)filter_keys)r   state_dict_prefix_replacetext_encoder_key_prefix)r   r!   r"   s      r   process_clip_state_dictzBASE.process_clip_state_dictZ   sG    44ZQUQmQmAnQmA!R%QmAn  }A  B
 Bos   
4
c                     |S r
   r   r   r!   s     r   process_unet_state_dictzBASE.process_unet_state_dict^       r   c                     |S r
   r   rC   s     r   process_vae_state_dictzBASE.process_vae_state_dicta   rE   r   c                 P    d| j                   d   i}t        j                  ||      S Nr=   r   )r@   r   r?   r   r!   replace_prefixs      r   "process_clip_state_dict_for_savingz'BASE.process_clip_state_dict_for_savingd   s*    d::1=>..z>JJr   c                 h    i }| j                   | j                   |d<   t        j                  ||      S )Nr=   )clip_vision_prefixr   r?   rJ   s      r   )process_clip_vision_state_dict_for_savingz.BASE.process_clip_vision_state_dict_for_savingh   s6    "".!%!8!8N2..z>JJr   c                 6    ddi}t        j                  ||      S )Nr=   zmodel.diffusion_model.)r   r?   rJ   s      r   "process_unet_state_dict_for_savingz'BASE.process_unet_state_dict_for_savingn   s     67..z>JJr   c                 P    d| j                   d   i}t        j                  ||      S rI   )vae_key_prefixr   r?   rJ   s      r   !process_vae_state_dict_for_savingz&BASE.process_vae_state_dict_for_savingr   s*    d11!45..z>JJr   c                 0    || j                   d<   || _        y )Ndtype)r   manual_cast_dtype)r   rV   rW   s      r   set_inference_dtypezBASE.set_inference_dtypev   s    $)!!2r   c                 L    t        j                  dj                  |             y )Nzb
WARNING, you accessed {} from the model config object which doesn't exist. Please fix your code.
)loggingwarningformat)r   names     r   __getattr__zBASE.__getattr__z   s.    ~  F  F  GK  L  	Mr   r
   )r=   )r=   N)(r   r   r   r   r2   r   clip_prefixrN   r6   r/   r   LatentFormatr0   rS   r@   torchfloat16bfloat16float32supported_inference_dtypesmemory_usage_factorrW   custom_operationsquant_configr1   classmethodr#   r(   r,   r   r;   rA   rD   rG   rL   rO   rQ   rT   rX   r^   r   r   r   r   r      s    K
 MK"//M*+N23"'--!OLENM (3<KKKK3r   r   )	__doc__ra   rZ   r=   r   r   r   r   r   r   r   r   <module>rk      s1   $      ] ]r   