From 8699fd7050334d89f46ac0b0264e48eb1a596c9d Mon Sep 17 00:00:00 2001 From: Brandon Rising Date: Tue, 18 Jul 2023 23:16:51 -0400 Subject: [PATCH] Fix invoke UI graphs for onnx --- .../buildCanvasImageToImageGraph.ts | 20 +++++++++---------- .../graphBuilders/buildCanvasInpaintGraph.ts | 3 +-- .../buildCanvasTextToImageGraph.ts | 18 ++++++++--------- .../buildLinearImageToImageGraph.ts | 20 +++++++++---------- .../buildLinearTextToImageGraph.ts | 3 +-- 5 files changed, 28 insertions(+), 36 deletions(-) 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 2d63f17645..2f9cd94a88 100644 --- a/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildCanvasImageToImageGraph.ts +++ b/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildCanvasImageToImageGraph.ts @@ -60,10 +60,8 @@ export const buildCanvasImageToImageGraph = ( ? shouldUseCpuNoise : initialGenerationState.shouldUseCpuNoise; - console.log(model); - const model_loader = model.model_name.includes('onnx') - ? ONNX_MODEL_LOADER - : MAIN_MODEL_LOADER; + 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 @@ -80,12 +78,12 @@ export const buildCanvasImageToImageGraph = ( id: IMAGE_TO_IMAGE_GRAPH, nodes: { [POSITIVE_CONDITIONING]: { - type: 'compel', + type: onnx_model_type ? 'prompt_onnx' : 'compel', id: POSITIVE_CONDITIONING, prompt: positivePrompt, }, [NEGATIVE_CONDITIONING]: { - type: 'compel', + type: onnx_model_type ? 'prompt_onnx' : 'compel', id: NEGATIVE_CONDITIONING, prompt: negativePrompt, }, @@ -105,11 +103,11 @@ export const buildCanvasImageToImageGraph = ( skipped_layers: clipSkip, }, [LATENTS_TO_IMAGE]: { - type: 'l2i', + type: onnx_model_type ? 'l2i_onnx' : 'l2i', id: LATENTS_TO_IMAGE, }, [LATENTS_TO_LATENTS]: { - type: 'l2l', + type: onnx_model_type ? 'l2l_onnx' : 'l2l', id: LATENTS_TO_LATENTS, cfg_scale, scheduler, @@ -117,7 +115,7 @@ export const buildCanvasImageToImageGraph = ( strength, }, [IMAGE_TO_LATENTS]: { - type: 'i2l', + type: onnx_model_type ? 'i2l_onnx' : 'i2l', id: IMAGE_TO_LATENTS, // must be set manually later, bc `fit` parameter may require a resize node inserted // image: { @@ -320,10 +318,10 @@ export const buildCanvasImageToImageGraph = ( }); // add LoRA support - addLoRAsToGraph(state, graph, LATENTS_TO_LATENTS); + addLoRAsToGraph(state, graph, LATENTS_TO_LATENTS, model_loader); // optionally add custom VAE - addVAEToGraph(state, graph); + addVAEToGraph(state, graph, model_loader); // 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 e0c62424a9..6cd61a9cb1 100644 --- a/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildCanvasInpaintGraph.ts +++ b/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildCanvasInpaintGraph.ts @@ -64,8 +64,7 @@ export const buildCanvasInpaintGraph = ( // We may need to set the inpaint width and height to scale the image const { scaledBoundingBoxDimensions, boundingBoxScaleMethod } = state.canvas; - console.log(model); - const model_loader = model.model_name.includes('onnx') + const model_loader = model.model_type.includes('onnx') ? ONNX_MODEL_LOADER : MAIN_MODEL_LOADER; diff --git a/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildCanvasTextToImageGraph.ts b/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildCanvasTextToImageGraph.ts index a1fb5f666d..e8ca3b9aa0 100644 --- a/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildCanvasTextToImageGraph.ts +++ b/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildCanvasTextToImageGraph.ts @@ -50,10 +50,8 @@ export const buildCanvasTextToImageGraph = ( const use_cpu = shouldUseNoiseSettings ? shouldUseCpuNoise : initialGenerationState.shouldUseCpuNoise; - console.log(model); - const model_loader = model.model_name.includes('onnx') - ? ONNX_MODEL_LOADER - : MAIN_MODEL_LOADER; + 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 @@ -69,12 +67,12 @@ export const buildCanvasTextToImageGraph = ( id: TEXT_TO_IMAGE_GRAPH, nodes: { [POSITIVE_CONDITIONING]: { - type: 'compel', + type: onnx_model_type ? 'prompt_onnx' : 'compel', id: POSITIVE_CONDITIONING, prompt: positivePrompt, }, [NEGATIVE_CONDITIONING]: { - type: 'compel', + type: onnx_model_type ? 'prompt_onnx' : 'compel', id: NEGATIVE_CONDITIONING, prompt: negativePrompt, }, @@ -86,7 +84,7 @@ export const buildCanvasTextToImageGraph = ( use_cpu, }, [TEXT_TO_LATENTS]: { - type: 't2l', + type: onnx_model_type ? 't2l_onnx' : 't2l', id: TEXT_TO_LATENTS, cfg_scale, scheduler, @@ -103,7 +101,7 @@ export const buildCanvasTextToImageGraph = ( skipped_layers: clipSkip, }, [LATENTS_TO_IMAGE]: { - type: 'l2i', + type: onnx_model_type ? 'l2i_onnx' : 'l2i', id: LATENTS_TO_IMAGE, }, }, @@ -224,10 +222,10 @@ export const buildCanvasTextToImageGraph = ( }); // add LoRA support - addLoRAsToGraph(state, graph, TEXT_TO_LATENTS); + addLoRAsToGraph(state, graph, TEXT_TO_LATENTS, model_loader); // optionally add custom VAE - addVAEToGraph(state, graph); + addVAEToGraph(state, graph, model_loader); // add dynamic prompts - also sets up core iteration and seed addDynamicPromptsToGraph(state, graph); 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 21f7af6a8a..6b182211ae 100644 --- a/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildLinearImageToImageGraph.ts +++ b/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildLinearImageToImageGraph.ts @@ -83,10 +83,8 @@ export const buildLinearImageToImageGraph = ( ? shouldUseCpuNoise : initialGenerationState.shouldUseCpuNoise; - console.log(model); - const model_loader = model.model_name.includes('onnx') - ? ONNX_MODEL_LOADER - : MAIN_MODEL_LOADER; + 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 @@ -104,12 +102,12 @@ export const buildLinearImageToImageGraph = ( skipped_layers: clipSkip, }, [POSITIVE_CONDITIONING]: { - type: 'compel', + type: onnx_model_type ? 'prompt_onnx' : 'compel', id: POSITIVE_CONDITIONING, prompt: positivePrompt, }, [NEGATIVE_CONDITIONING]: { - type: 'compel', + type: onnx_model_type ? 'prompt_onnx' : 'compel', id: NEGATIVE_CONDITIONING, prompt: negativePrompt, }, @@ -119,11 +117,11 @@ export const buildLinearImageToImageGraph = ( use_cpu, }, [LATENTS_TO_IMAGE]: { - type: 'l2i', + type: onnx_model_type ? 'l2i_onnx' : 'l2i', id: LATENTS_TO_IMAGE, }, [LATENTS_TO_LATENTS]: { - type: 'l2l', + type: onnx_model_type ? 'l2l_onnx' : 'l2l', id: LATENTS_TO_LATENTS, cfg_scale, scheduler, @@ -131,7 +129,7 @@ export const buildLinearImageToImageGraph = ( strength, }, [IMAGE_TO_LATENTS]: { - type: 'i2l', + type: onnx_model_type ? 'i2l_onnx' : 'i2l', id: IMAGE_TO_LATENTS, // must be set manually later, bc `fit` parameter may require a resize node inserted // image: { @@ -373,10 +371,10 @@ export const buildLinearImageToImageGraph = ( }); // add LoRA support - addLoRAsToGraph(state, graph, LATENTS_TO_LATENTS); + addLoRAsToGraph(state, graph, LATENTS_TO_LATENTS, model_loader); // optionally add custom VAE - addVAEToGraph(state, graph); + addVAEToGraph(state, graph, model_loader); // add dynamic prompts - also sets up core iteration and seed addDynamicPromptsToGraph(state, graph); diff --git a/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildLinearTextToImageGraph.ts b/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildLinearTextToImageGraph.ts index 3cfefe384e..e719eef297 100644 --- a/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildLinearTextToImageGraph.ts +++ b/invokeai/frontend/web/src/features/nodes/util/graphBuilders/buildLinearTextToImageGraph.ts @@ -49,8 +49,7 @@ export const buildLinearTextToImageGraph = ( throw new Error('No model found in state'); } - console.log(model); - const onnx_model_type = model.model_name.includes('onnx'); + 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