Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcd98d88

Browse files
committed
[nodes] Removed InvokerServices, simplying service model
1 parent34e3aa1 commitcd98d88

File tree

8 files changed

+81
-89
lines changed

8 files changed

+81
-89
lines changed

‎ldm/invoke/app/api/dependencies.py‎

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from ..services.image_storageimportDiskImageStorage
1414
from ..services.invocation_queueimportMemoryInvocationQueue
1515
from ..services.invocation_servicesimportInvocationServices
16-
from ..services.invokerimportInvoker,InvokerServices
16+
from ..services.invokerimportInvoker
1717
from ..services.generate_initializerimportget_generate
1818
from .eventsimportFastAPIEventService
1919

@@ -60,22 +60,19 @@ def initialize(
6060

6161
images=DiskImageStorage(output_folder)
6262

63-
services=InvocationServices(
64-
generate=generate,
65-
events=events,
66-
images=images
67-
)
68-
6963
# TODO: build a file/path manager?
7064
db_location=os.path.join(output_folder,'invokeai.db')
7165

72-
invoker_services=InvokerServices(
73-
queue=MemoryInvocationQueue(),
66+
services=InvocationServices(
67+
generate=generate,
68+
events=events,
69+
images=images,
70+
queue=MemoryInvocationQueue(),
7471
graph_execution_manager=SqliteItemStorage[GraphExecutionState](filename=db_location,table_name='graph_executions'),
75-
processor=DefaultInvocationProcessor()
72+
processor=DefaultInvocationProcessor()
7673
)
7774

78-
ApiDependencies.invoker=Invoker(services,invoker_services)
75+
ApiDependencies.invoker=Invoker(services)
7976

8077
@staticmethod
8178
defshutdown():

‎ldm/invoke/app/api/routers/sessions.py‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ async def list_sessions(
4444
)->PaginatedResults[GraphExecutionState]:
4545
"""Gets a list of sessions, optionally searching"""
4646
iffilter=='':
47-
result=ApiDependencies.invoker.invoker_services.graph_execution_manager.list(page,per_page)
47+
result=ApiDependencies.invoker.services.graph_execution_manager.list(page,per_page)
4848
else:
49-
result=ApiDependencies.invoker.invoker_services.graph_execution_manager.search(query,page,per_page)
49+
result=ApiDependencies.invoker.services.graph_execution_manager.search(query,page,per_page)
5050
returnresult
5151

5252

@@ -60,7 +60,7 @@ async def get_session(
6060
session_id:str=Path(description="The id of the session to get")
6161
)->GraphExecutionState:
6262
"""Gets a session"""
63-
session=ApiDependencies.invoker.invoker_services.graph_execution_manager.get(session_id)
63+
session=ApiDependencies.invoker.services.graph_execution_manager.get(session_id)
6464
ifsessionisNone:
6565
returnResponse(status_code=404)
6666
else:
@@ -80,13 +80,13 @@ async def add_node(
8080
node:Annotated[Union[BaseInvocation.get_invocations()],Field(discriminator="type")]=Body(description="The node to add")
8181
)->str:
8282
"""Adds a node to the graph"""
83-
session=ApiDependencies.invoker.invoker_services.graph_execution_manager.get(session_id)
83+
session=ApiDependencies.invoker.services.graph_execution_manager.get(session_id)
8484
ifsessionisNone:
8585
returnResponse(status_code=404)
8686

8787
try:
8888
session.add_node(node)
89-
ApiDependencies.invoker.invoker_services.graph_execution_manager.set(session)# TODO: can this be done automatically, or add node through an API?
89+
ApiDependencies.invoker.services.graph_execution_manager.set(session)# TODO: can this be done automatically, or add node through an API?
9090
returnsession.id
9191
exceptNodeAlreadyExecutedError:
9292
returnResponse(status_code=400)
@@ -108,13 +108,13 @@ async def update_node(
108108
node:Annotated[Union[BaseInvocation.get_invocations()],Field(discriminator="type")]=Body(description="The new node")
109109
)->GraphExecutionState:
110110
"""Updates a node in the graph and removes all linked edges"""
111-
session=ApiDependencies.invoker.invoker_services.graph_execution_manager.get(session_id)
111+
session=ApiDependencies.invoker.services.graph_execution_manager.get(session_id)
112112
ifsessionisNone:
113113
returnResponse(status_code=404)
114114

115115
try:
116116
session.update_node(node_path,node)
117-
ApiDependencies.invoker.invoker_services.graph_execution_manager.set(session)# TODO: can this be done automatically, or add node through an API?
117+
ApiDependencies.invoker.services.graph_execution_manager.set(session)# TODO: can this be done automatically, or add node through an API?
118118
returnsession
119119
exceptNodeAlreadyExecutedError:
120120
returnResponse(status_code=400)
@@ -135,13 +135,13 @@ async def delete_node(
135135
node_path:str=Path(description="The path to the node to delete")
136136
)->GraphExecutionState:
137137
"""Deletes a node in the graph and removes all linked edges"""
138-
session=ApiDependencies.invoker.invoker_services.graph_execution_manager.get(session_id)
138+
session=ApiDependencies.invoker.services.graph_execution_manager.get(session_id)
139139
ifsessionisNone:
140140
returnResponse(status_code=404)
141141

142142
try:
143143
session.delete_node(node_path)
144-
ApiDependencies.invoker.invoker_services.graph_execution_manager.set(session)# TODO: can this be done automatically, or add node through an API?
144+
ApiDependencies.invoker.services.graph_execution_manager.set(session)# TODO: can this be done automatically, or add node through an API?
145145
returnsession
146146
exceptNodeAlreadyExecutedError:
147147
returnResponse(status_code=400)
@@ -162,13 +162,13 @@ async def add_edge(
162162
edge:tuple[EdgeConnection,EdgeConnection]=Body(description="The edge to add")
163163
)->GraphExecutionState:
164164
"""Adds an edge to the graph"""
165-
session=ApiDependencies.invoker.invoker_services.graph_execution_manager.get(session_id)
165+
session=ApiDependencies.invoker.services.graph_execution_manager.get(session_id)
166166
ifsessionisNone:
167167
returnResponse(status_code=404)
168168

169169
try:
170170
session.add_edge(edge)
171-
ApiDependencies.invoker.invoker_services.graph_execution_manager.set(session)# TODO: can this be done automatically, or add node through an API?
171+
ApiDependencies.invoker.services.graph_execution_manager.set(session)# TODO: can this be done automatically, or add node through an API?
172172
returnsession
173173
exceptNodeAlreadyExecutedError:
174174
returnResponse(status_code=400)
@@ -193,14 +193,14 @@ async def delete_edge(
193193
to_field:str=Path(description="The field of the node the edge is going to")
194194
)->GraphExecutionState:
195195
"""Deletes an edge from the graph"""
196-
session=ApiDependencies.invoker.invoker_services.graph_execution_manager.get(session_id)
196+
session=ApiDependencies.invoker.services.graph_execution_manager.get(session_id)
197197
ifsessionisNone:
198198
returnResponse(status_code=404)
199199

200200
try:
201201
edge= (EdgeConnection(node_id=from_node_id,field=from_field),EdgeConnection(node_id=to_node_id,field=to_field))
202202
session.delete_edge(edge)
203-
ApiDependencies.invoker.invoker_services.graph_execution_manager.set(session)# TODO: can this be done automatically, or add node through an API?
203+
ApiDependencies.invoker.services.graph_execution_manager.set(session)# TODO: can this be done automatically, or add node through an API?
204204
returnsession
205205
exceptNodeAlreadyExecutedError:
206206
returnResponse(status_code=400)
@@ -221,7 +221,7 @@ async def invoke_session(
221221
all:bool=Query(default=False,description="Whether or not to invoke all remaining invocations")
222222
)->None:
223223
"""Invokes a session"""
224-
session=ApiDependencies.invoker.invoker_services.graph_execution_manager.get(session_id)
224+
session=ApiDependencies.invoker.services.graph_execution_manager.get(session_id)
225225
ifsessionisNone:
226226
returnResponse(status_code=404)
227227

‎ldm/invoke/app/cli_app.py‎

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from .services.invocation_queueimportMemoryInvocationQueue
2121
from .invocations.baseinvocationimportBaseInvocation
2222
from .services.invocation_servicesimportInvocationServices
23-
from .services.invokerimportInvoker,InvokerServices
23+
from .services.invokerimportInvoker
2424
from .invocationsimport*
2525
from ..argsimportArgs
2626
from .services.eventsimportEventServiceBase
@@ -171,28 +171,25 @@ def invoke_cli():
171171

172172
output_folder=os.path.abspath(os.path.join(os.path.dirname(__file__),'../../../outputs'))
173173

174-
services=InvocationServices(
175-
generate=generate,
176-
events=events,
177-
images=DiskImageStorage(output_folder)
178-
)
179-
180174
# TODO: build a file/path manager?
181175
db_location=os.path.join(output_folder,'invokeai.db')
182176

183-
invoker_services=InvokerServices(
184-
queue=MemoryInvocationQueue(),
177+
services=InvocationServices(
178+
generate=generate,
179+
events=events,
180+
images=DiskImageStorage(output_folder),
181+
queue=MemoryInvocationQueue(),
185182
graph_execution_manager=SqliteItemStorage[GraphExecutionState](filename=db_location,table_name='graph_executions'),
186-
processor=DefaultInvocationProcessor()
183+
processor=DefaultInvocationProcessor()
187184
)
188185

189-
invoker=Invoker(services,invoker_services)
186+
invoker=Invoker(services)
190187
session=invoker.create_execution_state()
191188

192189
parser=get_invocation_parser()
193190

194191
# Uncomment to print out previous sessions at startup
195-
# print(invoker_services.session_manager.list())
192+
# print(services.session_manager.list())
196193

197194
# Defaults storage
198195
defaults:Dict[str,Any]=dict()
@@ -213,7 +210,7 @@ def invoke_cli():
213210

214211
try:
215212
# Refresh the state of the session
216-
session=invoker.invoker_services.graph_execution_manager.get(session.id)
213+
session=invoker.services.graph_execution_manager.get(session.id)
217214
history=list(get_graph_execution_history(session))
218215

219216
# Split the command for piping
@@ -289,7 +286,7 @@ def invoke_cli():
289286
invoker.invoke(session,invoke_all=True)
290287
whilenotsession.is_complete():
291288
# Wait some time
292-
session=invoker.invoker_services.graph_execution_manager.get(session.id)
289+
session=invoker.services.graph_execution_manager.get(session.id)
293290
time.sleep(0.1)
294291

295292
exceptInvalidArgs:

‎ldm/invoke/app/services/invocation_services.py‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# Copyright (c) 2022 Kyle Schouviller (https://github.com/kyle0654)
2+
from .invocation_queueimportInvocationQueueABC
3+
from .item_storageimportItemStorageABC
24
from .image_storageimportImageStorageBase
35
from .eventsimportEventServiceBase
46
from ....generateimportGenerate
@@ -9,12 +11,23 @@ class InvocationServices():
911
generate:Generate# TODO: wrap Generate, or split it up from model?
1012
events:EventServiceBase
1113
images:ImageStorageBase
14+
queue:InvocationQueueABC
15+
16+
# NOTE: we must forward-declare any types that include invocations, since invocations can use services
17+
graph_execution_manager:ItemStorageABC['GraphExecutionState']
18+
processor:'InvocationProcessorABC'
1219

1320
def__init__(self,
1421
generate:Generate,
1522
events:EventServiceBase,
16-
images:ImageStorageBase
23+
images:ImageStorageBase,
24+
queue:InvocationQueueABC,
25+
graph_execution_manager:ItemStorageABC['GraphExecutionState'],
26+
processor:'InvocationProcessorABC'
1727
):
1828
self.generate=generate
1929
self.events=events
2030
self.images=images
31+
self.queue=queue
32+
self.graph_execution_manager=graph_execution_manager
33+
self.processor=processor

‎ldm/invoke/app/services/invoker.py‎

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,15 @@
99
from .invocation_queueimportInvocationQueueABC,InvocationQueueItem
1010

1111

12-
classInvokerServices:
13-
"""Services used by the Invoker for execution"""
14-
15-
queue:InvocationQueueABC
16-
graph_execution_manager:ItemStorageABC[GraphExecutionState]
17-
processor:'InvocationProcessorABC'
18-
19-
def__init__(self,
20-
queue:InvocationQueueABC,
21-
graph_execution_manager:ItemStorageABC[GraphExecutionState],
22-
processor:'InvocationProcessorABC'):
23-
self.queue=queue
24-
self.graph_execution_manager=graph_execution_manager
25-
self.processor=processor
26-
27-
2812
classInvoker:
2913
"""The invoker, used to execute invocations"""
3014

3115
services:InvocationServices
32-
invoker_services:InvokerServices
3316

3417
def__init__(self,
35-
services:InvocationServices,# Services used by nodes to perform invocations
36-
invoker_services:InvokerServices# Services used by the invoker for orchestration
18+
services:InvocationServices
3719
):
3820
self.services=services
39-
self.invoker_services=invoker_services
4021
self._start()
4122

4223

@@ -49,11 +30,11 @@ def invoke(self, graph_execution_state: GraphExecutionState, invoke_all: bool =
4930
returnNone
5031

5132
# Save the execution state
52-
self.invoker_services.graph_execution_manager.set(graph_execution_state)
33+
self.services.graph_execution_manager.set(graph_execution_state)
5334

5435
# Queue the invocation
5536
print(f'queueing item{invocation.id}')
56-
self.invoker_services.queue.put(InvocationQueueItem(
37+
self.services.queue.put(InvocationQueueItem(
5738
#session_id = session.id,
5839
graph_execution_state_id=graph_execution_state.id,
5940
invocation_id=invocation.id,
@@ -66,7 +47,7 @@ def invoke(self, graph_execution_state: GraphExecutionState, invoke_all: bool =
6647
defcreate_execution_state(self,graph:Graph|None=None)->GraphExecutionState:
6748
"""Creates a new execution state for the given graph"""
6849
new_state=GraphExecutionState(graph=Graph()ifgraphisNoneelsegraph)
69-
self.invoker_services.graph_execution_manager.set(new_state)
50+
self.services.graph_execution_manager.set(new_state)
7051
returnnew_state
7152

7253

@@ -86,8 +67,8 @@ def __stop_service(self, service) -> None:
8667

8768
def_start(self)->None:
8869
"""Starts the invoker. This is called automatically when the invoker is created."""
89-
forserviceinvars(self.invoker_services):
90-
self.__start_service(getattr(self.invoker_services,service))
70+
forserviceinvars(self.services):
71+
self.__start_service(getattr(self.services,service))
9172

9273
forserviceinvars(self.services):
9374
self.__start_service(getattr(self.services,service))
@@ -99,10 +80,10 @@ def stop(self) -> None:
9980
forserviceinvars(self.services):
10081
self.__stop_service(getattr(self.services,service))
10182

102-
forserviceinvars(self.invoker_services):
103-
self.__stop_service(getattr(self.invoker_services,service))
83+
forserviceinvars(self.services):
84+
self.__stop_service(getattr(self.services,service))
10485

105-
self.invoker_services.queue.put(None)
86+
self.services.queue.put(None)
10687

10788

10889
classInvocationProcessorABC(ABC):

‎ldm/invoke/app/services/processor.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ def stop(self, *args, **kwargs) -> None:
2828
def__process(self,stop_event:Event):
2929
try:
3030
whilenotstop_event.is_set():
31-
queue_item:InvocationQueueItem=self.__invoker.invoker_services.queue.get()
31+
queue_item:InvocationQueueItem=self.__invoker.services.queue.get()
3232
ifnotqueue_item:# Probably stopping
3333
continue
3434

35-
graph_execution_state=self.__invoker.invoker_services.graph_execution_manager.get(queue_item.graph_execution_state_id)
35+
graph_execution_state=self.__invoker.services.graph_execution_manager.get(queue_item.graph_execution_state_id)
3636
invocation=graph_execution_state.execution_graph.get_node(queue_item.invocation_id)
3737

3838
# Send starting event
@@ -52,7 +52,7 @@ def __process(self, stop_event: Event):
5252
graph_execution_state.complete(invocation.id,outputs)
5353

5454
# Save the state changes
55-
self.__invoker.invoker_services.graph_execution_manager.set(graph_execution_state)
55+
self.__invoker.services.graph_execution_manager.set(graph_execution_state)
5656

5757
# Send complete event
5858
self.__invoker.services.events.emit_invocation_complete(

‎tests/nodes/test_graph_execution_state.py‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from .test_invokerimportcreate_edge
22
from .test_nodesimportImageTestInvocation,ListPassThroughInvocation,PromptTestInvocation,PromptCollectionTestInvocation
33
fromldm.invoke.app.invocations.baseinvocationimportBaseInvocation,BaseInvocationOutput,InvocationContext
4+
fromldm.invoke.app.services.processorimportDefaultInvocationProcessor
5+
fromldm.invoke.app.services.sqliteimportSqliteItemStorage,sqlite_memory
6+
fromldm.invoke.app.services.invocation_queueimportMemoryInvocationQueue
47
fromldm.invoke.app.services.invocation_servicesimportInvocationServices
58
fromldm.invoke.app.services.graphimportGraph,GraphInvocation,InvalidEdgeError,NodeAlreadyInGraphError,NodeNotFoundError,are_connections_compatible,EdgeConnection,CollectInvocation,IterateInvocation,GraphExecutionState
6-
fromldm.invoke.app.invocations.generateimportImageToImageInvocation,TextToImageInvocation
7-
fromldm.invoke.app.invocations.upscaleimportUpscaleInvocation
89
importpytest
910

1011

@@ -19,7 +20,14 @@ def simple_graph():
1920
@pytest.fixture
2021
defmock_services():
2122
# NOTE: none of these are actually called by the test invocations
22-
returnInvocationServices(generate=None,events=None,images=None)
23+
returnInvocationServices(
24+
generate=None,
25+
events=None,
26+
images=None,
27+
queue=MemoryInvocationQueue(),
28+
graph_execution_manager=SqliteItemStorage[GraphExecutionState](filename=sqlite_memory,table_name='graph_executions'),
29+
processor=DefaultInvocationProcessor()
30+
)
2331

2432
definvoke_next(g:GraphExecutionState,services:InvocationServices)->tuple[BaseInvocation,BaseInvocationOutput]:
2533
n=g.next()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp