55import comfy .utils
66import node_helpers
77import math
8+ from typing_extensions import override
9+ from comfy_api .latest import ComfyExtension , io
10+
811
912def perp_neg (x , noise_pred_pos , noise_pred_neg , noise_pred_nocond , neg_scale , cond_scale ):
1013 pos = noise_pred_pos - noise_pred_nocond
@@ -16,20 +19,27 @@ def perp_neg(x, noise_pred_pos, noise_pred_neg, noise_pred_nocond, neg_scale, co
1619 return cfg_result
1720
1821#TODO: This node should be removed, it has been replaced with PerpNegGuider
19- class PerpNeg :
22+ class PerpNeg (io .ComfyNode ):
23+ @classmethod
24+ def define_schema (cls ):
25+ return io .Schema (
26+ node_id = "PerpNeg" ,
27+ display_name = "Perp-Neg (DEPRECATED by PerpNegGuider)" ,
28+ category = "_for_testing" ,
29+ inputs = [
30+ io .Model .Input ("model" ),
31+ io .Conditioning .Input ("empty_conditioning" ),
32+ io .Float .Input ("neg_scale" , default = 1.0 , min = 0.0 , max = 100.0 , step = 0.01 ),
33+ ],
34+ outputs = [
35+ io .Model .Output (),
36+ ],
37+ is_experimental = True ,
38+ is_deprecated = True ,
39+ )
40+
2041 @classmethod
21- def INPUT_TYPES (s ):
22- return {"required" : {"model" : ("MODEL" , ),
23- "empty_conditioning" : ("CONDITIONING" , ),
24- "neg_scale" : ("FLOAT" , {"default" : 1.0 , "min" : 0.0 , "max" : 100.0 , "step" : 0.01 }),
25- }}
26- RETURN_TYPES = ("MODEL" ,)
27- FUNCTION = "patch"
28-
29- CATEGORY = "_for_testing"
30- DEPRECATED = True
31-
32- def patch (self , model , empty_conditioning , neg_scale ):
42+ def execute (cls , model , empty_conditioning , neg_scale ) -> io .NodeOutput :
3343 m = model .clone ()
3444 nocond = comfy .sampler_helpers .convert_cond (empty_conditioning )
3545
@@ -50,7 +60,7 @@ def cfg_function(args):
5060
5161 m .set_model_sampler_cfg_function (cfg_function )
5262
53- return ( m , )
63+ return io . NodeOutput ( m )
5464
5565
5666class Guider_PerpNeg (comfy .samplers .CFGGuider ):
@@ -112,35 +122,42 @@ def predict_noise(self, x, timestep, model_options={}, seed=None):
112122
113123 return cfg_result
114124
115- class PerpNegGuider :
125+ class PerpNegGuider ( io . ComfyNode ) :
116126 @classmethod
117- def INPUT_TYPES (s ):
118- return {"required" :
119- {"model" : ("MODEL" ,),
120- "positive" : ("CONDITIONING" , ),
121- "negative" : ("CONDITIONING" , ),
122- "empty_conditioning" : ("CONDITIONING" , ),
123- "cfg" : ("FLOAT" , {"default" : 8.0 , "min" : 0.0 , "max" : 100.0 , "step" :0.1 , "round" : 0.01 }),
124- "neg_scale" : ("FLOAT" , {"default" : 1.0 , "min" : 0.0 , "max" : 100.0 , "step" : 0.01 }),
125- }
126- }
127-
128- RETURN_TYPES = ("GUIDER" ,)
129-
130- FUNCTION = "get_guider"
131- CATEGORY = "_for_testing"
132-
133- def get_guider (self , model , positive , negative , empty_conditioning , cfg , neg_scale ):
127+ def define_schema (cls ):
128+ return io .Schema (
129+ node_id = "PerpNegGuider" ,
130+ category = "_for_testing" ,
131+ inputs = [
132+ io .Model .Input ("model" ),
133+ io .Conditioning .Input ("positive" ),
134+ io .Conditioning .Input ("negative" ),
135+ io .Conditioning .Input ("empty_conditioning" ),
136+ io .Float .Input ("cfg" , default = 8.0 , min = 0.0 , max = 100.0 , step = 0.1 , round = 0.01 ),
137+ io .Float .Input ("neg_scale" , default = 1.0 , min = 0.0 , max = 100.0 , step = 0.01 ),
138+ ],
139+ outputs = [
140+ io .Guider .Output (),
141+ ],
142+ is_experimental = True ,
143+ )
144+
145+ @classmethod
146+ def execute (cls , model , positive , negative , empty_conditioning , cfg , neg_scale ) -> io .NodeOutput :
134147 guider = Guider_PerpNeg (model )
135148 guider .set_conds (positive , negative , empty_conditioning )
136149 guider .set_cfg (cfg , neg_scale )
137- return (guider ,)
150+ return io .NodeOutput (guider )
151+
152+
153+ class PerpNegExtension (ComfyExtension ):
154+ @override
155+ async def get_node_list (self ) -> list [type [io .ComfyNode ]]:
156+ return [
157+ PerpNeg ,
158+ PerpNegGuider ,
159+ ]
138160
139- NODE_CLASS_MAPPINGS = {
140- "PerpNeg" : PerpNeg ,
141- "PerpNegGuider" : PerpNegGuider ,
142- }
143161
144- NODE_DISPLAY_NAME_MAPPINGS = {
145- "PerpNeg" : "Perp-Neg (DEPRECATED by PerpNegGuider)" ,
146- }
162+ async def comfy_entrypoint () -> PerpNegExtension :
163+ return PerpNegExtension ()
0 commit comments