o >gv, @sddlZddlZddlZddlZddlZddlZGdddejjZ GdddejjZ Gdddejj Z Gdd d Z Gd d d Z Gd d d ZGdddeZGdddZGdddZGdddZGdddZe eee eeeedZdS)Nc@eZdZddZdS)LCMc Cs|||jddd|jd}||jddd|jd}|||}d}|d}|d|d|d}||d|dd} | |||S)Nr?g$@)timestepviewshapendim) selfsigma model_output model_inputrx0 sigma_dataZscaled_timestepc_skipc_outrK/home/comdoleger1/zen-flux-style-shape/comfy_extras/nodes_model_advanced.pycalculate_denoised s(" zLCM.calculate_denoisedN__name__ __module__ __qualname__rrrrrr rc@r)X0cCs|S)Nr)r r rrrrrrszX0.calculate_denoisedNrrrrrrrrcs2eZdZdZd fdd ZddZddZZS) ModelSamplingDiscreteDistilled2Ncsvtj||d|j|j|_tj|jtjd}t|jD]}|j |jd||j||jd|<q| |dS)Nzsnr)dtyper) super__init__ num_timestepsoriginal_timesteps skip_stepstorchzerosfloat32rangesigmas set_sigmas)r model_configr Z sigmas_validx __class__rrr#s *z'ModelSamplingDiscreteDistilled.__init__cCsX|}||jj|jdddf}|jdd|j|j|jd|jS)Nr)dimr) logto log_sigmasdeviceabsargminr r r&)r r log_sigmadistsrrrr(s 0z'ModelSamplingDiscreteDistilled.timestepcCstj||jj|jd|jdt|jdd}| }| }| }d||j|||j|}| |jS)Nrr)minmax)r'clampfloatr3r4r5r&lenr+floorlongceilfracexp)r rtlow_idxhigh_idxwr8rrrr -s <   z$ModelSamplingDiscreteDistilled.sigma)NN)rrrr%r#rr __classcell__rrr/rrs  rc@,eZdZeddZdZdZdZddZdS) ModelSamplingDiscretecCsddgdfdddifdiS)NrequiredMODEL)eps v_predictionlcmrBOOLEANdefaultF)modelsamplingr rsrrr INPUT_TYPES7s z!ModelSamplingDiscrete.INPUT_TYPESrLpatchadvanced/modelc Cs|}tjj}|dkrtjj}n|dkrtjj}n|dkr#t}t}n|dkr)t}Gddd||}||j j |d}| d||fS) NrNrOrPrc@ eZdZdS)z:ModelSamplingDiscrete.patch..ModelSamplingAdvancedNrrrrrrrModelSamplingAdvancedQr\rmodel_sampling) clonecomfyr^rJEPS V_PREDICTIONrrrrSr-add_object_patch) r rSrTr m sampling_base sampling_typer\r^rrrrXCs   zModelSamplingDiscrete.patchN rrr classmethodrW RETURN_TYPESFUNCTIONCATEGORYrXrrrrrJ6s  rJc@rI) ModelSamplingStableCascadecCddddddddfd iS) NrKrLFLOATg@Y@{Gz?rRr:r;steprSshiftrrUrrrrWZz&ModelSamplingStableCascade.INPUT_TYPESrLrXrYcCsR|}tjj}tjj}Gddd||}||jj}|||d||fS)Nc@rZ)z?ModelSamplingStableCascade.patch..ModelSamplingAdvancedNr[rrrrr\kr]r\r^) r_r`r^StableCascadeSamplingrarSr-set_parametersrc)r rSrurdrerfr\r^rrrrXes   z ModelSamplingStableCascade.patchNrgrrrrrlYs  rlc@s.eZdZeddZdZdZdZd ddZd S) ModelSamplingSD3cCrm) NrKrLrng@rorprqrrrtrrUrrrrWtrvzModelSamplingSD3.INPUT_TYPESrLrXrYc CsV|}tjj}tjj}Gddd||}||jj}|j||d|d||fS)Nc@rZ)z5ModelSamplingSD3.patch..ModelSamplingAdvancedNr[rrrrr\r]r\)ru multiplierr^) r_r`r^ModelSamplingDiscreteFlowCONSTrSr-rxrc) r rSrur{rdrerfr\r^rrrrXs  zModelSamplingSD3.patchN)rzrgrrrrryss ryc@s$eZdZeddZdZddZdS)ModelSamplingAuraFlowcCrm) NrKrLrngGz?rorprqrrrtrrUrrrrWrvz!ModelSamplingAuraFlow.INPUT_TYPES patch_auracCs|j||ddS)N?r{)rX)r rSrurrrrsz ModelSamplingAuraFlow.patch_auraN)rrrrhrWrjrrrrrr~s   r~c@rI) ModelSamplingFluxc CsPddddddddfdd ddddfd d d tjd dfd d d tjd dfdiS)NrKrLrngffffff?rorprqrrrINTi)rS max_shift base_shiftwidthheight)nodesMAX_RESOLUTIONrUrrrrWs zModelSamplingFlux.INPUT_TYPESrLrXrYcCs|}d}d}||||} || |} ||d| | } tjj} tjj} Gddd| | }||jj}|j| d|d||fS)Nic@rZ)z6ModelSamplingFlux.patch..ModelSamplingAdvancedNr[rrrrr\r]r\)rur^) r_r`r^rr}rSr-rxrc)r rSrrrrrdx1x2mmbrurerfr\r^rrrrXs    zModelSamplingFlux.patchNrgrrrrrs  rc@rI) ModelSamplingContinuousEDMc Cs8ddgdfdddddd d fdd dddd d fd iS) NrKrL)rOedm_playground_v2.5rNrng^@ro@@MbP?FrRr:r;rsroundgMb`?rSrT sigma_max sigma_minrrUrrrrWs z&ModelSamplingContinuousEDM.INPUT_TYPESrLrXrYc Cs|}d}d}|dkrtjj}n|dkrtjj}n|dkr)tjj}d}tj}Gdddtjj|} | |j j } | |||| d| |durQ| d ||fS) NrrNrOrrc@rZ)z?ModelSamplingContinuousEDM.patch..ModelSamplingAdvancedNr[rrrrr\r]r\r^ latent_format) r_r`r^rarbEDMlatent_formatsSDXL_Playground_2_5rrSr-rxrc r rSrTrrrdrrrfr\r^rrrrXs$      z ModelSamplingContinuousEDM.patchNrgrrrrr  rc@rI) ModelSamplingContinuousVc Cs6dddgfdddddd d fdd dddd d fd iS) NrKrLrOrng@@rorrFrgQ?rrrUrrrrWs z$ModelSamplingContinuousV.INPUT_TYPESrLrXrYc Csb|}d}d}|dkrtjj}Gdddtjj|} | |jj} | ||||d| |fS)NrrOc@rZ)z=ModelSamplingContinuousV.patch..ModelSamplingAdvancedNr[rrrrr\r]r\r^) r_r`r^rbrrSr-rxrcrrrrrXs  zModelSamplingContinuousV.patchNrgrrrrrrrc@rI) RescaleCFGcCrm) NrKrLrngffffff?rorrqrr)rSr{rrUrrrrWrvzRescaleCFG.INPUT_TYPESrLrXrYcs$fdd}|}|||fS)Nc s |d}|d}|d}|d}||jddd|jd}|d}|||d}||||d dd |}||||d dd |}||||}tj|d d d }tj|d d d } ||| } | d|} ||| |||dd S)Nconduncond cond_scaler rrinputrrr)rrT)r1keepdim)r r r r'std) argsrrrr x_origr.Zx_cfgZro_posZro_cfgZ x_rescaledZx_finalrrr rescale_cfg s"    z%RescaleCFG.patch..rescale_cfg)r_set_model_sampler_cfg_function)r rSr{rrdrrrrX s  zRescaleCFG.patchNrgrrrrrs  r)rJrrrlryr~rr) folder_pathscomfy.sdr`comfy.model_samplingcomfy.latent_formatsrr'r^rarrrJrrlryr~rrrrNODE_CLASS_MAPPINGSrrrrs4# $&(