11import os
22os .environ ['RAY_DEBUG' ] = '1'
3- import ray
4- from omegaconf import OmegaConf
5- from ray import serve
6- from twinkle .server .tinker import build_model_app , build_sampler_app , build_server_app
73
8- ray .init (namespace = "twinkle_cluster" )
9- serve .shutdown ()
10- import time
11- time .sleep (5 )
4+ from twinkle .server import launch_server
125
136file_dir = os .path .abspath (os .path .dirname (__file__ ))
14- config = OmegaConf . load ( os .path .join (file_dir , 'server_config.yaml' ) )
7+ config_path = os .path .join (file_dir , 'server_config.yaml' )
158
16- # Start Ray Serve with http_options from config
17- http_options = OmegaConf .to_container (config .http_options , resolve = True )
18- serve .start (http_options = http_options )
19-
20- APP_BUILDERS = {
21- 'main:build_server_app' : build_server_app ,
22- 'main:build_model_app' : build_model_app ,
23- # 'main:build_sampler_app': build_sampler_app,
24- }
25-
26- for app_config in config .applications :
27- print (f"Starting { app_config .name } at { app_config .route_prefix } ..." )
28-
29- if app_config .import_path not in APP_BUILDERS :
30- continue
31-
32- builder = APP_BUILDERS [app_config .import_path ]
33- args = OmegaConf .to_container (app_config .args , resolve = True ) if app_config .args else {}
34-
35- deploy_options = {}
36- deploy_config = app_config .deployments [0 ]
37- if 'autoscaling_config' in deploy_config :
38- deploy_options ['autoscaling_config' ] = OmegaConf .to_container (deploy_config .autoscaling_config )
39- if 'ray_actor_options' in deploy_config :
40- deploy_options ['ray_actor_options' ] = OmegaConf .to_container (deploy_config .ray_actor_options )
41-
42- app = builder (
43- deploy_options = deploy_options ,
44- ** {k : v for k , v in args .items ()}
45- )
46-
47- serve .run (app , name = app_config .name , route_prefix = app_config .route_prefix )
48-
49- print ("\n All applications started!" )
50- print ("Endpoints:" )
51- for app_config in config .applications :
52- print (f" - http://localhost:8000{ app_config .route_prefix } " )
53-
54- input ("\n Press Enter to stop the server..." )
9+ launch_server (config_path = config_path )
0 commit comments