Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
87789c1
add InvokeAIGenerator and InvokeAIGeneratorFactory classes
lstein Mar 8, 2023
5d37fa6
node-based txt2img working without generate
lstein Mar 9, 2023
b679a6b
model manager defaults to consistent values of device and precision
lstein Mar 9, 2023
cde0b6a
Merge branch 'main' into refactor/nodes-on-generator
lstein Mar 9, 2023
c11e823
remove unused _wrap_results
lstein Mar 9, 2023
370e828
Merge branch 'main' into refactor/nodes-on-generator
JPPhoto Mar 10, 2023
9595418
remove factory pattern
lstein Mar 11, 2023
fe75b95
Merge branch 'refactor/nodes-on-generator' of github.com:invoke-ai/In…
lstein Mar 11, 2023
7e76eea
add embiggen, remove complicated constructor
lstein Mar 11, 2023
675dd12
add attention map images to output object
lstein Mar 11, 2023
250b0ab
add seamless tiling support
lstein Mar 11, 2023
d612f11
initialize InvokeAIGenerator object with model, not manager
lstein Mar 11, 2023
c142414
move ModelManager initialization into its own module and restore embe…
lstein Mar 11, 2023
580f9ec
simplify passing of config options
lstein Mar 11, 2023
3aa1ee1
restore NSFW checker
lstein Mar 11, 2023
8ca91b1
add restoration services to nodes
lstein Mar 11, 2023
6a77634
remove unneeded generate initializer routines
lstein Mar 11, 2023
b63aefc
Merge branch 'main' into refactor/nodes-on-generator
JPPhoto Mar 11, 2023
10cbf99
add TODO comments
lstein Mar 11, 2023
c0ef546
Merge branch 'refactor/nodes-on-generator' of github.com:invoke-ai/In…
lstein Mar 11, 2023
74a480f
add back static web directory
Mar 12, 2023
1f3c024
Merge branch 'main' into refactor/nodes-on-generator
lstein Mar 12, 2023
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
20 changes: 10 additions & 10 deletions invokeai/app/api/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from argparse import Namespace

from ...backend import Globals
from ..services.generate_initializer import get_generate
from ..services.model_manager_initializer import get_model_manager
from ..services.restoration_services import RestorationServices
from ..services.graph import GraphExecutionState
from ..services.image_storage import DiskImageStorage
from ..services.invocation_queue import MemoryInvocationQueue
Expand Down Expand Up @@ -37,18 +38,16 @@ class ApiDependencies:
invoker: Invoker = None

@staticmethod
def initialize(args, config, event_handler_id: int):
Globals.try_patchmatch = args.patchmatch
Globals.always_use_cpu = args.always_use_cpu
Globals.internet_available = args.internet_available and check_internet()
Globals.disable_xformers = not args.xformers
Globals.ckpt_convert = args.ckpt_convert
def initialize(config, event_handler_id: int):
Globals.try_patchmatch = config.patchmatch
Globals.always_use_cpu = config.always_use_cpu
Globals.internet_available = config.internet_available and check_internet()
Globals.disable_xformers = not config.xformers
Globals.ckpt_convert = config.ckpt_convert

# TODO: Use a logger
print(f">> Internet connectivity is {Globals.internet_available}")

generate = get_generate(args, config)

events = FastAPIEventService(event_handler_id)

output_folder = os.path.abspath(
Expand All @@ -61,14 +60,15 @@ def initialize(args, config, event_handler_id: int):
db_location = os.path.join(output_folder, "invokeai.db")

services = InvocationServices(
generate=generate,
model_manager=get_model_manager(config),
events=events,
images=images,
queue=MemoryInvocationQueue(),
graph_execution_manager=SqliteItemStorage[GraphExecutionState](
filename=db_location, table_name="graph_executions"
),
processor=DefaultInvocationProcessor(),
restoration=RestorationServices(config),
)

ApiDependencies.invoker = Invoker(services)
Expand Down
7 changes: 3 additions & 4 deletions invokeai/app/api_app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Copyright (c) 2022 Kyle Schouviller (https://github.com/kyle0654)

import asyncio
from inspect import signature

Expand Down Expand Up @@ -53,11 +52,11 @@
# Add startup event to load dependencies
@app.on_event("startup")
async def startup_event():
args = Args()
config = args.parse_args()
config = Args()
config.parse_args()

ApiDependencies.initialize(
args=args, config=config, event_handler_id=event_handler_id
config=config, event_handler_id=event_handler_id
)


Expand Down
17 changes: 7 additions & 10 deletions invokeai/app/cli_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
from .invocations import *
from .invocations.baseinvocation import BaseInvocation
from .services.events import EventServiceBase
from .services.generate_initializer import get_generate
from .services.model_manager_initializer import get_model_manager
from .services.restoration_services import RestorationServices
from .services.graph import EdgeConnection, GraphExecutionState
from .services.image_storage import DiskImageStorage
from .services.invocation_queue import MemoryInvocationQueue
Expand Down Expand Up @@ -126,14 +127,9 @@ def invoke_all(context: CliContext):


def invoke_cli():
args = Args()
config = args.parse_args()

generate = get_generate(args, config)

# NOTE: load model on first use, uncomment to load at startup
# TODO: Make this a config option?
# generate.load_model()
config = Args()
config.parse_args()
model_manager = get_model_manager(config)

events = EventServiceBase()

Expand All @@ -145,14 +141,15 @@ def invoke_cli():
db_location = os.path.join(output_folder, "invokeai.db")

services = InvocationServices(
generate=generate,
model_manager=model_manager,
events=events,
images=DiskImageStorage(output_folder),
queue=MemoryInvocationQueue(),
graph_execution_manager=SqliteItemStorage[GraphExecutionState](
filename=db_location, table_name="graph_executions"
),
processor=DefaultInvocationProcessor(),
restoration=RestorationServices(config),
)

invoker = Invoker(services)
Expand Down
74 changes: 33 additions & 41 deletions invokeai/app/invocations/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
from ..services.invocation_services import InvocationServices
from .baseinvocation import BaseInvocation, InvocationContext
from .image import ImageField, ImageOutput
from ...backend.generator import Txt2Img, Img2Img, Inpaint, InvokeAIGenerator

SAMPLER_NAME_VALUES = Literal[
"ddim", "plms", "k_lms", "k_dpm_2", "k_dpm_2_a", "k_euler", "k_euler_a", "k_heun"
tuple(InvokeAIGenerator.schedulers())
]


# Text to image
class TextToImageInvocation(BaseInvocation):
"""Generates an image using text2img."""
Expand Down Expand Up @@ -57,19 +57,18 @@ def step_callback(sample, step=0):
# Handle invalid model parameter
# TODO: figure out if this can be done via a validator that uses the model_cache
# TODO: How to get the default model name now?
if self.model is None or self.model == "":
self.model = context.services.generate.model_name

# Set the model (if already cached, this does nothing)
context.services.generate.set_model(self.model)

results = context.services.generate.prompt2image(
# (right now uses whatever current model is set in model manager)
model= context.services.model_manager.get_model()
outputs = Txt2Img(model).generate(
prompt=self.prompt,
step_callback=step_callback,
**self.dict(
exclude={"prompt"}
), # Shorthand for passing all of the parameters above manually
)
# Outputs is an infinite iterator that will return a new InvokeAIGeneratorOutput object
# each time it is called. We only need the first one.
generate_output = next(outputs)

# Results are image and seed, unwrap for now and ignore the seed
# TODO: pre-seed?
Expand All @@ -78,7 +77,7 @@ def step_callback(sample, step=0):
image_name = context.services.images.create_name(
context.graph_execution_state_id, self.id
)
context.services.images.save(image_type, image_name, results[0][0])
context.services.images.save(image_type, image_name, generate_output.image)
return ImageOutput(
image=ImageField(image_type=image_type, image_name=image_name)
)
Expand Down Expand Up @@ -115,23 +114,20 @@ def step_callback(sample, step=0):
# Handle invalid model parameter
# TODO: figure out if this can be done via a validator that uses the model_cache
# TODO: How to get the default model name now?
if self.model is None or self.model == "":
self.model = context.services.generate.model_name

# Set the model (if already cached, this does nothing)
context.services.generate.set_model(self.model)

results = context.services.generate.prompt2image(
prompt=self.prompt,
init_img=image,
init_mask=mask,
step_callback=step_callback,
**self.dict(
exclude={"prompt", "image", "mask"}
), # Shorthand for passing all of the parameters above manually
model = context.services.model_manager.get_model()
generator_output = next(
Img2Img(model).generate(
prompt=self.prompt,
init_img=image,
init_mask=mask,
step_callback=step_callback,
**self.dict(
exclude={"prompt", "image", "mask"}
), # Shorthand for passing all of the parameters above manually
)
)

result_image = results[0][0]
result_image = generator_output.image

# Results are image and seed, unwrap for now and ignore the seed
# TODO: pre-seed?
Expand All @@ -145,7 +141,6 @@ def step_callback(sample, step=0):
image=ImageField(image_type=image_type, image_name=image_name)
)


class InpaintInvocation(ImageToImageInvocation):
"""Generates an image using inpaint."""

Expand Down Expand Up @@ -180,23 +175,20 @@ def step_callback(sample, step=0):
# Handle invalid model parameter
# TODO: figure out if this can be done via a validator that uses the model_cache
# TODO: How to get the default model name now?
if self.model is None or self.model == "":
self.model = context.services.generate.model_name

# Set the model (if already cached, this does nothing)
context.services.generate.set_model(self.model)

results = context.services.generate.prompt2image(
prompt=self.prompt,
init_img=image,
init_mask=mask,
step_callback=step_callback,
**self.dict(
exclude={"prompt", "image", "mask"}
), # Shorthand for passing all of the parameters above manually
manager = context.services.model_manager.get_model()
generator_output = next(
Inpaint(model).generate(
prompt=self.prompt,
init_img=image,
init_mask=mask,
step_callback=step_callback,
**self.dict(
exclude={"prompt", "image", "mask"}
), # Shorthand for passing all of the parameters above manually
)
)

result_image = results[0][0]
result_image = generator_output.image

# Results are image and seed, unwrap for now and ignore the seed
# TODO: pre-seed?
Expand Down
3 changes: 1 addition & 2 deletions invokeai/app/invocations/reconstruct.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from .baseinvocation import BaseInvocation, InvocationContext
from .image import ImageField, ImageOutput


class RestoreFaceInvocation(BaseInvocation):
"""Restores faces in an image."""
#fmt: off
Expand All @@ -23,7 +22,7 @@ def invoke(self, context: InvocationContext) -> ImageOutput:
image = context.services.images.get(
self.image.image_type, self.image.image_name
)
results = context.services.generate.upscale_and_reconstruct(
results = context.services.restoration.upscale_and_reconstruct(
image_list=[[image, 0]],
upscale=None,
strength=self.strength, # GFPGAN strength
Expand Down
2 changes: 1 addition & 1 deletion invokeai/app/invocations/upscale.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def invoke(self, context: InvocationContext) -> ImageOutput:
image = context.services.images.get(
self.image.image_type, self.image.image_name
)
results = context.services.generate.upscale_and_reconstruct(
results = context.services.restoration.upscale_and_reconstruct(
image_list=[[image, 0]],
upscale=(self.level, self.strength),
strength=0.0, # GFPGAN strength
Expand Down
Loading