Skip to content

Commit 9d44dc8

Browse files
committed
basic ray ingress launcher up
1 parent 9f0c338 commit 9d44dc8

File tree

4 files changed

+19
-64
lines changed

4 files changed

+19
-64
lines changed

Diff for: launch.py

+1-21
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
prepare_environment = launch_utils.prepare_environment
2323
configure_for_tests = launch_utils.configure_for_tests
2424
start = launch_utils.start
25-
ray = launch_utils.ray
25+
2626

2727

2828
def main():
@@ -44,25 +44,5 @@ def main():
4444

4545
start()
4646

47-
48-
def ray_launch():
49-
if args.dump_sysinfo:
50-
filename = launch_utils.dump_sysinfo()
51-
52-
print(f"Sysinfo saved as {filename}. Exiting...")
53-
54-
exit(0)
55-
56-
launch_utils.startup_timer.record("initial startup")
57-
58-
with launch_utils.startup_timer.subcategory("prepare environment"):
59-
if not args.skip_prepare_environment:
60-
prepare_environment()
61-
62-
if args.test_server:
63-
configure_for_tests()
64-
65-
ray()
66-
6747
if __name__ == "__main__":
6848
main()

Diff for: modules/api/ray.py

+15-27
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22
import ray
33
from fastapi import FastAPI
44
from modules.api.api import Api
5-
from modules.call_queue import queue_lock
5+
66
from modules import initialize_util
77
from modules import script_callbacks
88
from modules import initialize
9-
9+
import time
1010

1111

1212
ray.init()
1313
#ray.init("ray://localhost:10001")
1414

15+
16+
1517
NUM_REPLICAS: int = 1
1618
if NUM_REPLICAS > ray.available_resources()["GPU"]:
1719
print(
@@ -21,39 +23,25 @@
2123
)
2224

2325
app = FastAPI()
26+
initialize_util.setup_middleware(app)
27+
script_callbacks.app_started_callback(None, app)
2428

2529
@serve.deployment(
2630
ray_actor_options={"num_gpus": 1},
2731
num_replicas=NUM_REPLICAS,
2832
)
2933
@serve.ingress(app)
30-
class APIIngress(Api):
34+
class APIIngress:
3135
def __init__(self, *args, **kwargs) -> None:
32-
from launch import ray_launch
33-
#from modules import sd_samplers
34-
ray_launch()
35-
#sd_samplers.set_samplers()
36-
initialize.imports()
37-
initialize.check_versions()
38-
39-
initialize.initialize()
40-
app = FastAPI()
41-
initialize_util.setup_middleware(app)
42-
43-
44-
api = Api(app)
45-
46-
script_callbacks.before_ui_callback()
47-
script_callbacks.app_started_callback(None, app)
48-
49-
print(f"Startup time: {startup_timer.summary()}.")
50-
api.launch(
51-
server_name="0.0.0.0" if cmd_opts.listen else "127.0.0.1",
52-
port=cmd_opts.port if cmd_opts.port else 7861,
53-
root_path=f"/{cmd_opts.subpath}" if cmd_opts.subpath else ""
54-
)
36+
pass
5537

56-
super().__init__(*args, **kwargs)
5738

39+
def ray_only():
40+
# Shutdown any existing Serve replicas, if they're still around.
41+
serve.shutdown()
42+
serve.run(APIIngress.bind(), port=8000, name="serving_stable_diffusion_template")
43+
print("Done setting up replicas! Now accepting requests...")
44+
while True:
45+
time.sleep(1000)
5846

5947

Diff for: modules/launch_utils.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -430,20 +430,15 @@ def configure_for_tests():
430430
def start():
431431
print(f"Launching {'API server' if '--nowebui' or '--ray' in sys.argv else 'Web UI'} with arguments: {' '.join(sys.argv[1:])}")
432432
import webui
433+
from modules.api.ray import ray_only
433434
if '--nowebui' in sys.argv:
434435
webui.api_only()
435436
elif '--ray' in sys.argv:
436-
webui.ray_only()
437+
ray_only()
437438
else:
438439
webui.webui()
439440

440441

441-
def ray():
442-
print(f"Launching {'API server' if '--nowebui' or '--ray' in sys.argv else 'Web UI'} with arguments: {' '.join(sys.argv[1:])}")
443-
import webui
444-
webui.ray_only()
445-
446-
447442
def dump_sysinfo():
448443
from modules import sysinfo
449444
import datetime

Diff for: webui.py

+1-9
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,6 @@ def api_only():
4545
root_path=f"/{cmd_opts.subpath}" if cmd_opts.subpath else ""
4646
)
4747

48-
def ray_only():
49-
from modules.api.ray import APIIngress
50-
from ray import serve
51-
52-
# Shutdown any existing Serve replicas, if they're still around.
53-
serve.shutdown()
54-
serve.run(APIIngress.bind(), port=8000, name="serving_stable_diffusion_template")
55-
print("Done setting up replicas! Now accepting requests...")
56-
5748

5849
def webui():
5950
from modules.shared_cmd_options import cmd_opts
@@ -165,6 +156,7 @@ def webui():
165156

166157
if __name__ == "__main__":
167158
from modules.shared_cmd_options import cmd_opts
159+
from modules.api.ray import ray_only
168160

169161
if cmd_opts.nowebui:
170162
api_only()

0 commit comments

Comments
 (0)