File size: 2,461 Bytes
114dd13
 
 
 
 
 
 
 
6c5e5bd
 
 
 
114dd13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import sys
import os
import time
import argparse
import subprocess

import bunny.serve.gradio_web_server as gws

os.system("pip uninstall -y gradio")
os.system("pip install gradio")

subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-e', '.'])


def start_controller():
    controller_command = [
        sys.executable, '-m', 'bunny.serve.controller',
        '--host', '0.0.0.0',
        '--port', '10000'
    ]
    return subprocess.Popen(controller_command)


def start_worker(port: int, model_path: str, model_type: str):
    worker_command = [
        sys.executable, '-m', 'bunny.serve.model_worker',
        '--host', '0.0.0.0',
        '--controller', 'http://localhost:10000',
        '--port', f'{port}',
        '--worker', f'http://localhost:{port}',
        '--model-path', model_path,
        '--model-type', model_type
    ]
    return subprocess.Popen(worker_command)


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument("--host", type=str, default="0.0.0.0")
    parser.add_argument("--port", type=int)
    parser.add_argument("--controller-url", type=str, default="http://localhost:10000")
    parser.add_argument("--concurrency-count", type=int, default=5)
    parser.add_argument("--model-list-mode", type=str, default="reload", choices=["once", "reload"])
    parser.add_argument("--share", action="store_true")
    parser.add_argument("--moderate", action="store_true")
    parser.add_argument("--embed", action="store_true")
    gws.args = parser.parse_args()
    gws.models = []

    controller_proc = start_controller()

    worker_procs = []

    worker_procs.append(start_worker(port=40000, model_path='BAAI/Bunny-v1_1-Llama-3-8B-V', model_type='llama3-8b'))
    worker_procs.append(start_worker(port=40001, model_path='BAAI/Bunny-v1_1-4B', model_type='phi-3'))
    worker_procs.append(start_worker(port=40002, model_path='BAAI/Bunny-v1_0-3B', model_type='phi-2'))

    time.sleep(60)

    exit_status = 0
    try:
        demo = gws.build_demo(embed_mode=gws.args.embed)
        demo.launch(
            server_name=gws.args.host,
            server_port=gws.args.port,
            share=gws.args.share,
            debug=True,
            max_threads=10
        )
    except Exception as e:
        print(e)
        exit_status = 1
    finally:
        for worker_proc in worker_procs:
            worker_proc.kill()
        controller_proc.kill()
        sys.exit(exit_status)