Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adds stable_cascade_2pass #253

Merged
merged 4 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions hordelib/comfy_horde.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,10 +678,10 @@ def _run_pipeline(
# This is useful for dumping the entire pipeline to the terminal when
# developing and debugging new pipelines. A badly structured pipeline
# file just results in a cryptic error from comfy
# if False: # This isn't here, Tazlin :)
# with open("pipeline_debug.json", "w") as outfile:
# default = lambda o: f"<<non-serializable: {type(o).__qualname__}>>"
# outfile.write(json.dumps(pipeline, indent=4, default=default))
# if True: # This isn't here, Tazlin :)
# with open("pipeline_debug.json", "w") as outfile:
# default = lambda o: f"<<non-serializable: {type(o).__qualname__}>>"
# outfile.write(json.dumps(pipeline, indent=4, default=default))
# pretty_pipeline = pformat(pipeline)
# logger.warning(pretty_pipeline)

Expand Down
53 changes: 45 additions & 8 deletions hordelib/horde.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@ class HordeLib:
"model_loader_stage_b.ckpt_name": "stable_cascade_stage_b",
"model_loader_stage_b.model_name": "stable_cascade_stage_b",
"model_loader_stage_b.horde_model_name": "model_name",
# Stable Cascade 2pass
"2pass_sampler_stage_c.sampler_name": "sampler_name",
"2pass_sampler_stage_c.denoise": "hires_fix_denoising_strength",
"2pass_sampler_stage_b.sampler_name": "sampler_name",
}

_comfyui_callback: Callable[[str, dict, str], None] | None = None
Expand Down Expand Up @@ -771,14 +775,44 @@ def _final_pipeline_adjustments(self, payload, pipeline_data) -> tuple[dict, lis

# For hires fix, change the image sizes as we create an intermediate image first
if payload.get("hires_fix", False):
width = pipeline_params.get("empty_latent_image.width", 0)
height = pipeline_params.get("empty_latent_image.height", 0)
if width > 512 and height > 512:
newwidth, newheight = ImageUtils.calculate_source_image_size(width, height)
pipeline_params["latent_upscale.width"] = width
pipeline_params["latent_upscale.height"] = height
pipeline_params["empty_latent_image.width"] = newwidth
pipeline_params["empty_latent_image.height"] = newheight
model_details = (
SharedModelManager.manager.compvis.get_model_reference_info(payload["model_name"])
if SharedModelManager.manager.compvis
else None
)

original_width = pipeline_params.get("empty_latent_image.width")
original_height = pipeline_params.get("empty_latent_image.height")

if original_width is None or original_height is None:
logger.error("empty_latent_image.width or empty_latent_image.height not found. Using 512x512.")
original_width, original_height = (512, 512)

new_width, new_height = (None, None)

if model_details and model_details.get("baseline") == "stable_cascade":
new_width, new_height = ImageUtils.get_first_pass_image_resolution_max(
original_width,
original_height,
)
else:
new_width, new_height = ImageUtils.get_first_pass_image_resolution_min(
original_width,
original_height,
)

# This is the *target* resolution
pipeline_params["latent_upscale.width"] = original_width
pipeline_params["latent_upscale.height"] = original_height

if new_width and new_height:
# This is the *first pass* resolution
pipeline_params["empty_latent_image.width"] = new_width
pipeline_params["empty_latent_image.height"] = new_height
else:
logger.error("Could not determine new image size for hires fix. Using 1024x1024.")
pipeline_params["empty_latent_image.width"] = 1024
pipeline_params["empty_latent_image.height"] = 1024

if payload.get("control_type"):
# Inject control net model manager
Expand Down Expand Up @@ -886,13 +920,16 @@ def _get_appropriate_pipeline(self, params):
# image_upscale
# stable_cascade
# stable_cascade_remix
# stable_cascade_2pass

# controlnet, controlnet_hires_fix controlnet_annotator
if params.get("model_name"):
model_details = SharedModelManager.manager.compvis.get_model_reference_info(params["model_name"])
if model_details.get("baseline") == "stable_cascade":
if params.get("source_processing") == "remix":
return "stable_cascade_remix"
if params.get("hires_fix", False):
return "stable_cascade_2pass"
return "stable_cascade"
if params.get("control_type"):
if params.get("return_control_map", False):
Expand Down
216 changes: 108 additions & 108 deletions hordelib/pipeline_designs/pipeline_stable_cascade.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"1": 26
},
"flags": {},
"order": 7,
"order": 8,
"mode": 0,
"inputs": [
{
Expand Down Expand Up @@ -230,51 +230,6 @@
1
]
},
{
"id": 34,
"type": "StableCascade_EmptyLatentImage",
"pos": [
210,
725
],
"size": {
"0": 315,
"1": 150
},
"flags": {},
"order": 1,
"mode": 0,
"outputs": [
{
"name": "stage_c",
"type": "LATENT",
"links": [
82
],
"shape": 3,
"slot_index": 0
},
{
"name": "stage_b",
"type": "LATENT",
"links": [
83
],
"shape": 3,
"slot_index": 1
}
],
"title": "stable_cascade_empty_latent_image",
"properties": {
"Node name for S&R": "StableCascade_EmptyLatentImage"
},
"widgets_values": [
1024,
1024,
42,
5
]
},
{
"id": 3,
"type": "KSampler",
Expand All @@ -287,7 +242,7 @@
"1": 262
},
"flags": {},
"order": 8,
"order": 9,
"mode": 0,
"inputs": [
{
Expand Down Expand Up @@ -348,7 +303,7 @@
"1": 192
},
"flags": {},
"order": 4,
"order": 5,
"mode": 0,
"inputs": [
{
Expand Down Expand Up @@ -390,7 +345,7 @@
"1": 96
},
"flags": {},
"order": 5,
"order": 6,
"mode": 0,
"inputs": [
{
Expand Down Expand Up @@ -446,12 +401,52 @@
"ComfyUI"
]
},
{
"id": 48,
"type": "LoadImage",
"pos": [
-263,
724
],
"size": {
"0": 315,
"1": 314
},
"flags": {},
"order": 1,
"mode": 0,
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
117
],
"shape": 3,
"slot_index": 0
},
{
"name": "MASK",
"type": "MASK",
"links": null,
"shape": 3
}
],
"title": "sc_image_loader",
"properties": {
"Node name for S&R": "LoadImage"
},
"widgets_values": [
"example.png",
"image"
]
},
{
"id": 41,
"type": "CheckpointLoaderSimple",
"pos": [
-271.29601025390616,
353.6759821777344
-271,
354
],
"size": {
"0": 336,
Expand Down Expand Up @@ -498,6 +493,46 @@
"stable_cascade_stage_c.safetensors"
]
},
{
"id": 50,
"type": "RepeatImageBatch",
"pos": [
99,
936
],
"size": {
"0": 315,
"1": 58
},
"flags": {},
"order": 4,
"mode": 0,
"inputs": [
{
"name": "image",
"type": "IMAGE",
"link": 117
}
],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
118
],
"shape": 3,
"slot_index": 0
}
],
"title": "repeat_image_batch",
"properties": {
"Node name for S&R": "RepeatImageBatch"
},
"widgets_values": [
1
]
},
{
"id": 47,
"type": "StableCascade_StageC_VAEEncode",
Expand All @@ -510,7 +545,7 @@
"1": 78
},
"flags": {},
"order": 9,
"order": 7,
"mode": 0,
"inputs": [
{
Expand Down Expand Up @@ -547,83 +582,48 @@
]
},
{
"id": 48,
"type": "LoadImage",
"id": 34,
"type": "StableCascade_EmptyLatentImage",
"pos": [
-263,
724
],
"size": [
315,
314
210,
725
],
"size": {
"0": 315,
"1": 150
},
"flags": {},
"order": 3,
"mode": 0,
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"name": "stage_c",
"type": "LATENT",
"links": [
117
82
],
"shape": 3,
"slot_index": 0
},
{
"name": "MASK",
"type": "MASK",
"links": null,
"shape": 3
}
],
"title": "sc_image_loader",
"properties": {
"Node name for S&R": "LoadImage"
},
"widgets_values": [
"example.png",
"image"
]
},
{
"id": 50,
"type": "RepeatImageBatch",
"pos": [
99,
936
],
"size": {
"0": 315,
"1": 58
},
"flags": {},
"order": 6,
"mode": 0,
"inputs": [
{
"name": "image",
"type": "IMAGE",
"link": 117
}
],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"name": "stage_b",
"type": "LATENT",
"links": [
118
83
],
"shape": 3,
"slot_index": 0
"slot_index": 1
}
],
"title": "repeat_image_batch",
"title": "empty_latent_image",
"properties": {
"Node name for S&R": "RepeatImageBatch"
"Node name for S&R": "StableCascade_EmptyLatentImage"
},
"widgets_values": [
1
1024,
1024,
42,
5
]
}
],
Expand Down
Loading
Loading