From 989d3d7f3c28391b092af2df3d2d46e979b2a080 Mon Sep 17 00:00:00 2001 From: Brandon Rising Date: Thu, 27 Jul 2023 10:08:45 -0400 Subject: [PATCH] Remove onnx changes from canvas img2img, inpaint, and linear image2image --- invokeai/backend/generator/base.py | 1 + .../backend/model_management/models/base.py | 10 +++---- .../buildCanvasImageToImageGraph.ts | 27 +++++++---------- .../graphBuilders/buildCanvasInpaintGraph.ts | 16 ++++------ .../buildLinearImageToImageGraph.ts | 29 ++++++++----------- 5 files changed, 33 insertions(+), 50 deletions(-) diff --git a/invokeai/backend/generator/base.py b/invokeai/backend/generator/base.py index be6127332f..8af8d399d5 100644 --- a/invokeai/backend/generator/base.py +++ b/invokeai/backend/generator/base.py @@ -458,6 +458,7 @@ class Generator: dtype=samples.dtype, device=samples.device, ) + latent_image = samples[0].permute(1, 2, 0) @ v1_5_latent_rgb_factors latents_ubyte = ( ((latent_image + 1) / 2) diff --git a/invokeai/backend/model_management/models/base.py b/invokeai/backend/model_management/models/base.py index 370265dba8..8bee9d409f 100644 --- a/invokeai/backend/model_management/models/base.py +++ b/invokeai/backend/model_management/models/base.py @@ -267,18 +267,16 @@ class DiffusersModel(ModelBase): try: # TODO: set cache_dir to /dev/null to be sure that cache not used? model = self.child_types[child_type].from_pretrained( - os.path.join(self.model_path, child_type.value), - #subfolder=child_type.value, + self.model_path, + subfolder=child_type.value, torch_dtype=torch_dtype, variant=variant, local_files_only=True, ) break except Exception as e: - print("====ERR LOAD====") - print(f"{variant}: {e}") - import traceback - traceback.print_exc() + # print("====ERR LOAD====") + # print(f"{variant}: {e}") pass else: raise Exception(f"Failed to load {self.base_model}:{self.model_type}:{child_type} model") diff --git a/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildCanvasImageToImageGraph.ts b/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildCanvasImageToImageGraph.ts index 88f762f747..42f768c107 100644 --- a/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildCanvasImageToImageGraph.ts +++ b/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildCanvasImageToImageGraph.ts @@ -20,7 +20,6 @@ import { LATENTS_TO_IMAGE, LATENTS_TO_LATENTS, MAIN_MODEL_LOADER, - ONNX_MODEL_LOADER, METADATA_ACCUMULATOR, NEGATIVE_CONDITIONING, NOISE, @@ -63,9 +62,6 @@ export const buildCanvasImageToImageGraph = ( ? shouldUseCpuNoise : initialGenerationState.shouldUseCpuNoise; - const onnx_model_type = model.model_type.includes('onnx'); - const model_loader = onnx_model_type ? ONNX_MODEL_LOADER : MAIN_MODEL_LOADER; - /** * The easiest way to build linear graphs is to do it in the node editor, then copy and paste the * full graph here as a template. Then use the parameters from app state and set friendlier node @@ -76,18 +72,17 @@ export const buildCanvasImageToImageGraph = ( */ // copy-pasted graph from node editor, filled in with state values & friendly node ids - // TODO: Actually create the graph correctly for ONNX const graph: NonNullableGraph = { id: IMAGE_TO_IMAGE_GRAPH, nodes: { [POSITIVE_CONDITIONING]: { - type: onnx_model_type ? 'prompt_onnx' : 'compel', + type: 'compel', id: POSITIVE_CONDITIONING, is_intermediate: true, prompt: positivePrompt, }, [NEGATIVE_CONDITIONING]: { - type: onnx_model_type ? 'prompt_onnx' : 'compel', + type: 'compel', id: NEGATIVE_CONDITIONING, is_intermediate: true, prompt: negativePrompt, @@ -98,9 +93,9 @@ export const buildCanvasImageToImageGraph = ( is_intermediate: true, use_cpu, }, - [model_loader]: { - type: model_loader, - id: model_loader, + [MAIN_MODEL_LOADER]: { + type: 'main_model_loader', + id: MAIN_MODEL_LOADER, is_intermediate: true, model, }, @@ -111,7 +106,7 @@ export const buildCanvasImageToImageGraph = ( skipped_layers: clipSkip, }, [LATENTS_TO_LATENTS]: { - type: onnx_model_type ? 'l2l_onnx' : 'l2l', + type: 'l2l', id: LATENTS_TO_LATENTS, is_intermediate: true, cfg_scale, @@ -120,7 +115,7 @@ export const buildCanvasImageToImageGraph = ( strength, }, [IMAGE_TO_LATENTS]: { - type: onnx_model_type ? 'i2l_onnx' : 'i2l', + type: 'i2l', id: IMAGE_TO_LATENTS, is_intermediate: true, // must be set manually later, bc `fit` parameter may require a resize node inserted @@ -137,7 +132,7 @@ export const buildCanvasImageToImageGraph = ( edges: [ { source: { - node_id: model_loader, + node_id: MAIN_MODEL_LOADER, field: 'clip', }, destination: { @@ -197,7 +192,7 @@ export const buildCanvasImageToImageGraph = ( }, { source: { - node_id: model_loader, + node_id: MAIN_MODEL_LOADER, field: 'unet', }, destination: { @@ -329,10 +324,10 @@ export const buildCanvasImageToImageGraph = ( }); // add LoRA support - addLoRAsToGraph(state, graph, LATENTS_TO_LATENTS, model_loader); + addLoRAsToGraph(state, graph, LATENTS_TO_LATENTS); // optionally add custom VAE - addVAEToGraph(state, graph, model_loader); + addVAEToGraph(state, graph); // add dynamic prompts - also sets up core iteration and seed addDynamicPromptsToGraph(state, graph); diff --git a/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildCanvasInpaintGraph.ts b/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildCanvasInpaintGraph.ts index 37506fc772..3cec76757f 100644 --- a/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildCanvasInpaintGraph.ts +++ b/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildCanvasInpaintGraph.ts @@ -17,7 +17,6 @@ import { INPAINT_GRAPH, ITERATE, MAIN_MODEL_LOADER, - ONNX_MODEL_LOADER, NEGATIVE_CONDITIONING, POSITIVE_CONDITIONING, RANDOM_INT, @@ -69,11 +68,6 @@ export const buildCanvasInpaintGraph = ( shouldAutoSave, } = state.canvas; - const model_loader = model.model_type.includes('onnx') - ? ONNX_MODEL_LOADER - : MAIN_MODEL_LOADER; - - // TODO: Actually create the graph correctly for ONNX const graph: NonNullableGraph = { id: INPAINT_GRAPH, nodes: { @@ -121,9 +115,9 @@ export const buildCanvasInpaintGraph = ( is_intermediate: true, prompt: negativePrompt, }, - [model_loader]: { - type: model_loader, - id: model_loader, + [MAIN_MODEL_LOADER]: { + type: 'main_model_loader', + id: MAIN_MODEL_LOADER, is_intermediate: true, model, }, @@ -151,7 +145,7 @@ export const buildCanvasInpaintGraph = ( edges: [ { source: { - node_id: model_loader, + node_id: MAIN_MODEL_LOADER, field: 'unet', }, destination: { @@ -161,7 +155,7 @@ export const buildCanvasInpaintGraph = ( }, { source: { - node_id: model_loader, + node_id: MAIN_MODEL_LOADER, field: 'clip', }, destination: { diff --git a/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildLinearImageToImageGraph.ts b/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildLinearImageToImageGraph.ts index d4cacc27b9..f264edc6be 100644 --- a/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildLinearImageToImageGraph.ts +++ b/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildLinearImageToImageGraph.ts @@ -19,7 +19,6 @@ import { LATENTS_TO_IMAGE, LATENTS_TO_LATENTS, MAIN_MODEL_LOADER, - ONNX_MODEL_LOADER, METADATA_ACCUMULATOR, NEGATIVE_CONDITIONING, NOISE, @@ -85,17 +84,13 @@ export const buildLinearImageToImageGraph = ( ? shouldUseCpuNoise : initialGenerationState.shouldUseCpuNoise; - const onnx_model_type = model.model_type.includes('onnx'); - const model_loader = onnx_model_type ? ONNX_MODEL_LOADER : MAIN_MODEL_LOADER; - // copy-pasted graph from node editor, filled in with state values & friendly node ids - // TODO: Actually create the graph correctly for ONNX const graph: NonNullableGraph = { id: IMAGE_TO_IMAGE_GRAPH, nodes: { - [model_loader]: { - type: model_loader, - id: model_loader, + [MAIN_MODEL_LOADER]: { + type: 'main_model_loader', + id: MAIN_MODEL_LOADER, model, }, [CLIP_SKIP]: { @@ -104,12 +99,12 @@ export const buildLinearImageToImageGraph = ( skipped_layers: clipSkip, }, [POSITIVE_CONDITIONING]: { - type: onnx_model_type ? 'prompt_onnx' : 'compel', + type: 'compel', id: POSITIVE_CONDITIONING, prompt: positivePrompt, }, [NEGATIVE_CONDITIONING]: { - type: onnx_model_type ? 'prompt_onnx' : 'compel', + type: 'compel', id: NEGATIVE_CONDITIONING, prompt: negativePrompt, }, @@ -119,12 +114,12 @@ export const buildLinearImageToImageGraph = ( use_cpu, }, [LATENTS_TO_IMAGE]: { - type: onnx_model_type ? 'l2i_onnx' : 'l2i', + type: 'l2i', id: LATENTS_TO_IMAGE, fp32: vaePrecision === 'fp32' ? true : false, }, [LATENTS_TO_LATENTS]: { - type: onnx_model_type ? 'l2l_onnx' : 'l2l', + type: 'l2l', id: LATENTS_TO_LATENTS, cfg_scale, scheduler, @@ -132,7 +127,7 @@ export const buildLinearImageToImageGraph = ( strength, }, [IMAGE_TO_LATENTS]: { - type: onnx_model_type ? 'i2l_onnx' : 'i2l', + type: 'i2l', id: IMAGE_TO_LATENTS, // must be set manually later, bc `fit` parameter may require a resize node inserted // image: { @@ -144,7 +139,7 @@ export const buildLinearImageToImageGraph = ( edges: [ { source: { - node_id: model_loader, + node_id: MAIN_MODEL_LOADER, field: 'unet', }, destination: { @@ -154,7 +149,7 @@ export const buildLinearImageToImageGraph = ( }, { source: { - node_id: model_loader, + node_id: MAIN_MODEL_LOADER, field: 'clip', }, destination: { @@ -339,10 +334,10 @@ export const buildLinearImageToImageGraph = ( }); // add LoRA support - addLoRAsToGraph(state, graph, LATENTS_TO_LATENTS, model_loader); + addLoRAsToGraph(state, graph, LATENTS_TO_LATENTS); // optionally add custom VAE - addVAEToGraph(state, graph, model_loader); + addVAEToGraph(state, graph); // add dynamic prompts - also sets up core iteration and seed addDynamicPromptsToGraph(state, graph);