5
5
import comfy .utils
6
6
import node_helpers
7
7
import math
8
+ from typing_extensions import override
9
+ from comfy_api .latest import ComfyExtension , io
10
+
8
11
9
12
def perp_neg (x , noise_pred_pos , noise_pred_neg , noise_pred_nocond , neg_scale , cond_scale ):
10
13
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
16
19
return cfg_result
17
20
18
21
#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
+
20
41
@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 :
33
43
m = model .clone ()
34
44
nocond = comfy .sampler_helpers .convert_cond (empty_conditioning )
35
45
@@ -50,7 +60,7 @@ def cfg_function(args):
50
60
51
61
m .set_model_sampler_cfg_function (cfg_function )
52
62
53
- return ( m , )
63
+ return io . NodeOutput ( m )
54
64
55
65
56
66
class Guider_PerpNeg (comfy .samplers .CFGGuider ):
@@ -112,35 +122,42 @@ def predict_noise(self, x, timestep, model_options={}, seed=None):
112
122
113
123
return cfg_result
114
124
115
- class PerpNegGuider :
125
+ class PerpNegGuider ( io . ComfyNode ) :
116
126
@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 :
134
147
guider = Guider_PerpNeg (model )
135
148
guider .set_conds (positive , negative , empty_conditioning )
136
149
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
+ ]
138
160
139
- NODE_CLASS_MAPPINGS = {
140
- "PerpNeg" : PerpNeg ,
141
- "PerpNegGuider" : PerpNegGuider ,
142
- }
143
161
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