V 0.6.0 - Align your steps to Sampler
This commit is contained in:
+67
-53
@@ -15,6 +15,7 @@ import random
|
||||
import nodes
|
||||
import comfy_extras.nodes_custom_sampler as nodes_custom_sampler
|
||||
import comfy_extras.nodes_stable_cascade as nodes_stable_cascade
|
||||
import comfy_extras.nodes_align_your_steps as nodes_align_your_steps
|
||||
import torch
|
||||
from ..components import utility
|
||||
from ..components import latentnoise
|
||||
@@ -433,11 +434,11 @@ class PrimereKSampler:
|
||||
return {
|
||||
"required": {
|
||||
"model": ("MODEL", {"forceInput": True}),
|
||||
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
|
||||
"steps": ("INT", {"default": 20, "min": 1, "max": 10000}),
|
||||
"cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0}),
|
||||
"sampler_name": (comfy.samplers.KSampler.SAMPLERS, ),
|
||||
"scheduler_name": (comfy.samplers.KSampler.SCHEDULERS, ),
|
||||
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff, "forceInput": True}),
|
||||
"steps": ("INT", {"default": 20, "min": 1, "max": 10000, "forceInput": True}),
|
||||
"cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0, "forceInput": True}),
|
||||
"sampler_name": (comfy.samplers.KSampler.SAMPLERS, {"forceInput": True}),
|
||||
"scheduler_name": (comfy.samplers.KSampler.SCHEDULERS, {"forceInput": True}),
|
||||
"positive": ("CONDITIONING", ),
|
||||
"negative": ("CONDITIONING", ),
|
||||
"latent_image": ("LATENT", ),
|
||||
@@ -445,6 +446,7 @@ class PrimereKSampler:
|
||||
"variation_extender": ("FLOAT", {"default": 0.0, "min": 0.0, "max": 1.0, "step": 0.01}),
|
||||
"variation_batch_step": ("FLOAT", {"default": 0.0, "min": 0.0, "max": 0.5, "step": 0.01}),
|
||||
"device": (["DEFAULT", "GPU", "CPU"], {"default": 'DEFAULT'}),
|
||||
"align_your_steps": ("BOOLEAN", {"default": False, "label_on": "Use AlignYourSteps", "label_off": "Ignore AlignYourSteps"}),
|
||||
},
|
||||
"optional": {
|
||||
"model_concept": ("STRING", {"default": "Normal", "forceInput": True}),
|
||||
@@ -455,7 +457,7 @@ class PrimereKSampler:
|
||||
}
|
||||
}
|
||||
|
||||
def pk_sampler(self, model, seed, steps, cfg, sampler_name, scheduler_name, positive, negative, latent_image, extra_pnginfo, prompt, model_concept = "Normal", denoise=1.0, variation_extender = 0, variation_batch_step = 0, device = 'DEFAULT'):
|
||||
def pk_sampler(self, model, seed, steps, cfg, sampler_name, scheduler_name, positive, negative, latent_image, extra_pnginfo, prompt, model_concept = "Normal", denoise=1.0, variation_extender = 0, variation_batch_step = 0, device = 'DEFAULT', align_your_steps = False):
|
||||
samples = latent_image
|
||||
variation_extender_original = variation_extender
|
||||
variation_batch_step_original = variation_batch_step
|
||||
@@ -471,55 +473,67 @@ class PrimereKSampler:
|
||||
|
||||
batch_counter = int(check_state(self, extra_pnginfo, prompt)) + 1
|
||||
|
||||
match model_concept:
|
||||
case "Turbo":
|
||||
sigmas = nodes_custom_sampler.SDTurboScheduler().get_sigmas(model, steps, denoise)
|
||||
sampler = comfy.samplers.sampler_object(sampler_name)
|
||||
turbo_samples = nodes_custom_sampler.SamplerCustom().sample(model, True, seed, cfg, positive, negative, sampler, sigmas[0], latent_image)
|
||||
samples = (turbo_samples[0],)
|
||||
# return samples
|
||||
if align_your_steps == True:
|
||||
modelname_only = model
|
||||
model_version = utility.get_value_from_cache('model_version', modelname_only)
|
||||
match model_version:
|
||||
case 'SDXL_2048':
|
||||
model_type = 'SDXL'
|
||||
case _:
|
||||
model_type = 'SD1'
|
||||
|
||||
case "Cascade":
|
||||
if type(model).__name__ == 'list':
|
||||
latent_size = utility.getLatentSize(latent_image)
|
||||
if (latent_size[0] < latent_size[1]):
|
||||
orientation = 'Vertical'
|
||||
sigmas = nodes_align_your_steps.AlignYourStepsScheduler.get_sigmas(self, model_type, steps, denoise)
|
||||
sampler = comfy.samplers.sampler_object(sampler_name)
|
||||
AYS_samples = nodes_custom_sampler.SamplerCustom().sample(model, True, seed, cfg, positive, negative, sampler, sigmas[0], latent_image)
|
||||
samples = (AYS_samples[0],)
|
||||
else:
|
||||
match model_concept:
|
||||
case "Turbo":
|
||||
sigmas = nodes_custom_sampler.SDTurboScheduler().get_sigmas(model, steps, denoise)
|
||||
sampler = comfy.samplers.sampler_object(sampler_name)
|
||||
turbo_samples = nodes_custom_sampler.SamplerCustom().sample(model, True, seed, cfg, positive, negative, sampler, sigmas[0], latent_image)
|
||||
samples = (turbo_samples[0],)
|
||||
|
||||
case "Cascade":
|
||||
if type(model).__name__ == 'list':
|
||||
latent_size = utility.getLatentSize(latent_image)
|
||||
if (latent_size[0] < latent_size[1]):
|
||||
orientation = 'Vertical'
|
||||
else:
|
||||
orientation = 'Horizontal'
|
||||
|
||||
dimensions = utility.get_dimensions_by_shape(self, 'Square [1:1]', 1024, orientation, True, True, latent_size[0], latent_size[1], 'CASCADE')
|
||||
dimension_x = dimensions[0]
|
||||
dimension_y = dimensions[1]
|
||||
|
||||
height = dimension_y
|
||||
width = dimension_x
|
||||
compression = 42
|
||||
if type(model[0]).__name__ == 'ModelPatcher' and type(model[1]).__name__ == 'ModelPatcher':
|
||||
c_latent = {"samples": torch.zeros([1, 16, height // compression, width // compression])}
|
||||
b_latent = {"samples": torch.zeros([1, 4, height // 4, width // 4])}
|
||||
samples_c = nodes.KSampler.sample(self, model[1], seed, steps, cfg, sampler_name, scheduler_name, positive, negative, c_latent, denoise=denoise)[0]
|
||||
conditining_c = nodes_stable_cascade.StableCascade_StageB_Conditioning.set_prior(self, positive, samples_c)[0]
|
||||
samples = nodes.KSampler.sample(self, model[0], seed, 10, 1.00, sampler_name, scheduler_name, conditining_c, negative, b_latent, denoise=denoise)
|
||||
# return samples
|
||||
case _:
|
||||
if variation_batch_step_original > 0:
|
||||
if batch_counter > 0:
|
||||
variation_batch_step = variation_batch_step_original * batch_counter
|
||||
|
||||
variation_extender = round(variation_extender_original + variation_batch_step, 2)
|
||||
|
||||
if variation_extender_original > 0 or device != 'DEFAULT' or variation_batch_step_original > 0:
|
||||
if (variation_extender > 1):
|
||||
random.seed(batch_counter)
|
||||
variation_extender = round(random.uniform(0.01, 1.00), 2)
|
||||
if variation_batch_step == 0:
|
||||
variation_seed = batch_counter + seed
|
||||
else:
|
||||
variation_seed = seed
|
||||
samples = latentnoise.noisy_samples(model, device, steps, cfg, sampler_name, scheduler_name, positive, negative, latent_image, denoise, variation_seed, variation_extender)
|
||||
else:
|
||||
orientation = 'Horizontal'
|
||||
|
||||
dimensions = utility.get_dimensions_by_shape(self, 'Square [1:1]', 1024, orientation, True, True, latent_size[0], latent_size[1], 'CASCADE')
|
||||
dimension_x = dimensions[0]
|
||||
dimension_y = dimensions[1]
|
||||
|
||||
height = dimension_y
|
||||
width = dimension_x
|
||||
compression = 42
|
||||
if type(model[0]).__name__ == 'ModelPatcher' and type(model[1]).__name__ == 'ModelPatcher':
|
||||
c_latent = {"samples": torch.zeros([1, 16, height // compression, width // compression])}
|
||||
b_latent = {"samples": torch.zeros([1, 4, height // 4, width // 4])}
|
||||
samples_c = nodes.KSampler.sample(self, model[1], seed, steps, cfg, sampler_name, scheduler_name, positive, negative, c_latent, denoise=denoise)[0]
|
||||
conditining_c = nodes_stable_cascade.StableCascade_StageB_Conditioning.set_prior(self, positive, samples_c)[0]
|
||||
samples = nodes.KSampler.sample(self, model[0], seed, 10, 1.00, sampler_name, scheduler_name, conditining_c, negative, b_latent, denoise=denoise)
|
||||
# return samples
|
||||
case _:
|
||||
if variation_batch_step_original > 0:
|
||||
if batch_counter > 0:
|
||||
variation_batch_step = variation_batch_step_original * batch_counter
|
||||
|
||||
variation_extender = round(variation_extender_original + variation_batch_step, 2)
|
||||
|
||||
if variation_extender_original > 0 or device != 'DEFAULT' or variation_batch_step_original > 0:
|
||||
if (variation_extender > 1):
|
||||
random.seed(batch_counter)
|
||||
variation_extender = round(random.uniform(0.01, 1.00), 2)
|
||||
if variation_batch_step == 0:
|
||||
variation_seed = batch_counter + seed
|
||||
else:
|
||||
variation_seed = seed
|
||||
samples = latentnoise.noisy_samples(model, device, steps, cfg, sampler_name, scheduler_name, positive, negative, latent_image, denoise, variation_seed, variation_extender)
|
||||
else:
|
||||
samples = nodes.KSampler.sample(self, model, seed, steps, cfg, sampler_name, scheduler_name, positive, negative, latent_image, denoise=denoise)
|
||||
# return samples
|
||||
samples = nodes.KSampler.sample(self, model, seed, steps, cfg, sampler_name, scheduler_name, positive, negative, latent_image, denoise=denoise)
|
||||
|
||||
return samples
|
||||
|
||||
|
||||
@@ -55,6 +55,7 @@ Git link: https://github.com/CosmicLaca/ComfyUI_Primere_Nodes
|
||||
|
||||
## Last changes:
|
||||
#### Usually after node changes have to reload/re-wire nodes within existing workflow, or open the latest workflows from the nodepack's **Workflow** folder.
|
||||
- Nvidia AlignYourSteps support on sampler: https://research.nvidia.com/labs/toronto-ai/AlignYourSteps/
|
||||
- Image recycler node read images without meta, using Pic2Story model to generate prompt from picture only
|
||||
- Some nodes moved to **deprecated** subtree. Nodes can be used but not developed in the future.
|
||||
- **Segmented refiners** will mesure the aesthetic score of results, and if the original segment is better, changes will be ignored. Only in **Primere_full_workflow.json** workflow. Feature can switch off.
|
||||
@@ -518,6 +519,7 @@ Get the aesthetic score of your generated image.
|
||||
|
||||
### Primere KSampler:
|
||||
Sampler using the 'model_concept' input this node automatically handle Turbo and Cascade modes, no need another workflow or extra node. You can select device (CPU or GPU), and use 'variation_extender' input for new image with very less (adjustable) difference from previous one (if seed and other details freezed). This settings can be used in queued workflow.
|
||||
- One button support of Nvidia AlignYourStpes: https://research.nvidia.com/labs/toronto-ai/AlignYourSteps/
|
||||
|
||||
<a href="./Workflow/readme_images/pksampler.jpg" target="_blank"><img src="./Workflow/readme_images/pksampler.jpg" height="220px"></a>
|
||||
<hr>
|
||||
|
||||
+2246
-2241
File diff suppressed because it is too large
Load Diff
@@ -1306,7 +1306,7 @@
|
||||
},
|
||||
"widgets_values": [
|
||||
"",
|
||||
712453657043459,
|
||||
211084894698341,
|
||||
"randomize"
|
||||
],
|
||||
"color": "#145414",
|
||||
@@ -1361,7 +1361,7 @@
|
||||
},
|
||||
"widgets_values": [
|
||||
"",
|
||||
946952457448339,
|
||||
239872422581783,
|
||||
"randomize"
|
||||
],
|
||||
"color": "#145414",
|
||||
@@ -1825,7 +1825,7 @@
|
||||
false,
|
||||
1.6,
|
||||
2.8,
|
||||
711756667041831,
|
||||
1095399425108326,
|
||||
"randomize",
|
||||
"BaseModel_1024",
|
||||
"Normal"
|
||||
@@ -1998,7 +1998,7 @@
|
||||
1,
|
||||
0.8,
|
||||
1.4,
|
||||
503831462214994,
|
||||
1071756380805453,
|
||||
"randomize",
|
||||
false,
|
||||
"cpu",
|
||||
@@ -2267,7 +2267,7 @@
|
||||
],
|
||||
"size": {
|
||||
"0": 322.92181396484375,
|
||||
"1": 310
|
||||
"1": 334
|
||||
},
|
||||
"flags": {},
|
||||
"order": 26,
|
||||
@@ -2357,7 +2357,7 @@
|
||||
"Node name for S&R": "PrimereKSampler"
|
||||
},
|
||||
"widgets_values": [
|
||||
311963377597273,
|
||||
349545987479056,
|
||||
"randomize",
|
||||
20,
|
||||
8,
|
||||
@@ -2367,6 +2367,7 @@
|
||||
0,
|
||||
0,
|
||||
"DEFAULT",
|
||||
false,
|
||||
"Normal"
|
||||
],
|
||||
"color": "#941414",
|
||||
@@ -2458,8 +2459,8 @@
|
||||
"id": 92,
|
||||
"type": "PrimereAestheticCKPTScorer",
|
||||
"pos": [
|
||||
2609,
|
||||
523
|
||||
2611,
|
||||
546
|
||||
],
|
||||
"size": {
|
||||
"0": 323.20916748046875,
|
||||
|
||||
+953
-946
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"last_node_id": 66,
|
||||
"last_node_id": 69,
|
||||
"last_link_id": 284,
|
||||
"nodes": [
|
||||
{
|
||||
@@ -724,7 +724,7 @@
|
||||
},
|
||||
"widgets_values": [
|
||||
"",
|
||||
636402502684314,
|
||||
1093923594010474,
|
||||
"randomize"
|
||||
],
|
||||
"color": "#145414",
|
||||
@@ -779,7 +779,7 @@
|
||||
},
|
||||
"widgets_values": [
|
||||
"",
|
||||
798381124197252,
|
||||
744357966969803,
|
||||
"randomize"
|
||||
],
|
||||
"color": "#145414",
|
||||
@@ -873,7 +873,7 @@
|
||||
false,
|
||||
1.6,
|
||||
2.8,
|
||||
90995882162185,
|
||||
663109167090432,
|
||||
"randomize",
|
||||
"BaseModel_1024",
|
||||
"Normal"
|
||||
@@ -1023,7 +1023,7 @@
|
||||
1,
|
||||
0.8,
|
||||
1.4,
|
||||
242258049340592,
|
||||
1113455142479464,
|
||||
"randomize",
|
||||
false,
|
||||
"cpu",
|
||||
@@ -1494,7 +1494,7 @@
|
||||
],
|
||||
"size": {
|
||||
"0": 341.0091247558594,
|
||||
"1": 310
|
||||
"1": 334
|
||||
},
|
||||
"flags": {},
|
||||
"order": 19,
|
||||
@@ -1584,7 +1584,7 @@
|
||||
"Node name for S&R": "PrimereKSampler"
|
||||
},
|
||||
"widgets_values": [
|
||||
1089729015963368,
|
||||
205252127749919,
|
||||
"randomize",
|
||||
20,
|
||||
8,
|
||||
@@ -1594,6 +1594,7 @@
|
||||
0,
|
||||
0,
|
||||
"DEFAULT",
|
||||
false,
|
||||
"Normal"
|
||||
],
|
||||
"color": "#941414",
|
||||
@@ -1685,8 +1686,8 @@
|
||||
"id": 66,
|
||||
"type": "PrimereAestheticCKPTScorer",
|
||||
"pos": [
|
||||
2504,
|
||||
522
|
||||
2508,
|
||||
550
|
||||
],
|
||||
"size": {
|
||||
"0": 341.3660888671875,
|
||||
@@ -1722,7 +1723,7 @@
|
||||
true,
|
||||
false,
|
||||
false,
|
||||
"619"
|
||||
"620"
|
||||
],
|
||||
"color": "#2c002c",
|
||||
"bgcolor": "#400040"
|
||||
|
||||
Reference in New Issue
Block a user