-
Notifications
You must be signed in to change notification settings - Fork 6
/
setup.py
143 lines (127 loc) · 4.88 KB
/
setup.py
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import os
from rich.console import Console
from rich.table import Table
from rich import box
from dotenv import set_key, dotenv_values
LOGO = (
"██████╗ █████╗ ██████╗ ██╗██╗ ██████╗ ████████╗\n"
"██╔══██╗██╔══██╗██╔══██╗██║██║ ██╔═══██╗╚══██╔══╝\n"
"██████╔╝███████║██████╔╝██║██║ ██║ ██║ ██║ \n"
"██╔═══╝ ██╔══██║██╔═══╝ ██║██║ ██║ ██║ ██║ \n"
"██║ ██║ ██║██║ ██║███████╗╚██████╔╝ ██║ \n"
"╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝ ╚═════╝ ╚═╝ \n"
)
MODELS = [
"codegen-350M-mono 2GB Python-only",
"codegen-350M-multi 2GB multi-language",
"codegen-2B-mono 7GB Python-only",
"codegen-2B-multi 7GB multi-language",
"codegen-6B-mono 13GB Python-only",
"codegen-6B-multi 13GB multi-language",
"codegen-16B-mono 32GB Python-only",
"codegen-16B-multi 32GB multi-language",
]
console = Console()
console.print(LOGO, style="bold red")
console.print("[bold blue]An open-source GitHub Copilot server based PaddleNLP")
console.print("\n")
# Model selection
MODELS_TABLE = Table(
title="Models available",
box=box.SIMPLE_HEAD,
show_header=True,
header_style="bold yellow",
)
MODELS_TABLE.add_column("ID", style="bold yellow")
MODELS_TABLE.add_column("Model", style="bold yellow")
MODELS_TABLE.add_column("VRAM", style="bold yellow")
MODELS_TABLE.add_column("Languages", style="bold yellow")
for i, model in enumerate(MODELS):
MODELS_TABLE.add_row(
str(i + 1), model.split(" ")[0], model.split(" ")[1], model.split(" ")[2]
)
console.print(MODELS_TABLE)
modelIn = console.input("[green bold]Select model \\[default: 1]: ")
if modelIn.isdigit():
set_key(
dotenv_path="papilot/config.env",
key_to_set="MODEL",
value_to_set="Salesforce/" + MODELS[int(modelIn) - 1].split(" ")[0],
)
else:
set_key(
dotenv_path="papilot/config.env",
key_to_set="MODEL",
value_to_set="Salesforce/codegen-350M-mono",
)
# GPU selection
gpus = console.input("[green bold]Enter number of GPUs \\[default: 1]: ")
if gpus.isdigit():
set_key(dotenv_path="papilot/config.env", key_to_set="NUM_GPUS", value_to_set=gpus)
else:
set_key(dotenv_path="papilot/config.env", key_to_set="NUM_GPUS", value_to_set="1")
# Lock token length
console.print("[italic yellow]Too long tokens will affect the speed.")
token = console.input("[bold green]Enter lock token length \\[default: 32]: ")
if token.isdigit():
set_key(
dotenv_path="papilot/config.env", key_to_set="TOKEN_LENGTH", value_to_set=token
)
else:
set_key(
dotenv_path="papilot/config.env", key_to_set="TOKEN_LENGTH", value_to_set="32"
)
# Deployment method selection
method_table = Table(
title="Deploy method",
box=box.SIMPLE_HEAD,
show_header=True,
header_style="bold yellow",
)
method_table.add_column("ID", style="bold yellow")
method_table.add_column("Method", style="bold yellow")
method_table.add_row("1", "Docker")
method_table.add_row("2", "localhost")
console.print(method_table)
method = console.input(
"[bold green]Where do you want to deploy the model? \\[default: localhost]: "
)
if method.isdigit():
set_key(
dotenv_path="papilot/config.env",
key_to_set="DEPLOY_METHOD",
value_to_set="Docker" if int(method) == 1 else "localhost",
)
else:
set_key(
dotenv_path="papilot/config.env",
key_to_set="DEPLOY_METHOD",
value_to_set="localhost",
)
# Port selection
port = console.input("[bold green]Enter port \\[default: 8000]: ")
if port.isdigit():
set_key(dotenv_path="papilot/config.env", key_to_set="PORT", value_to_set=port)
else:
set_key(dotenv_path="papilot/config.env", key_to_set="PORT", value_to_set="8000")
# Print config
console.print("[bold green]Configuration completed...")
config = dotenv_values(dotenv_path="papilot/config.env")
config_table = Table(
title="Configuration",
box=box.SIMPLE_HEAD,
show_header=True,
header_style="bold yellow",
)
config_table.add_column("Key", style="bold yellow")
config_table.add_column("Value", style="bold yellow")
for key, value in config.items():
config_table.add_row(key, value)
console.print(config_table)
console.input("[bold green]Enter to start deployment: ")
console.print("[bold green]Deploying model...")
if config["DEPLOY_METHOD"] == "Docker":
os.system("docker-compose up -d")
else:
os.system("cd papilot && pip install -r requirements.txt")
os.system("cd papilot && python main.py")