forked from LeelaChessZero/lczero-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.sql
More file actions
227 lines (206 loc) · 6.42 KB
/
schema.sql
File metadata and controls
227 lines (206 loc) · 6.42 KB
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
-- schema.sql
CREATE TABLE users ( -- Read only DB, legacy table that stores HTTP version of user credentials. Only used to migrate existing credentials to tokens.
id BIGSERIAL PRIMARY KEY,
username TEXT,
password TEXT,
assigned_training_run_id BIGINT
);
CREATE TABLE clients ( -- Read only DB, legacy table that stores HTTP version of client information. Only used to migrate existing clients to tokens.
id BIGSERIAL PRIMARY KEY,
user_id BIGINT REFERENCES users(id),
client_name TEXT,
last_version BIGINT,
last_engine_version TEXT,
last_game_at TIMESTAMPTZ,
gpu_name TEXT
);
CREATE INDEX idx_clients_user_id ON clients(user_id);
CREATE TABLE networks (
id BIGSERIAL PRIMARY KEY,
created_at TIMESTAMPTZ NOT NULL,
training_run_id BIGINT,
network_number BIGINT,
sha TEXT,
path TEXT,
layers INTEGER,
filters INTEGER,
games_played INTEGER,
elo DOUBLE PRECISION,
anchor BOOLEAN,
elo_set BOOLEAN
);
CREATE TABLE training_runs (
id BIGSERIAL PRIMARY KEY,
best_network_id BIGINT REFERENCES networks(id),
description TEXT,
train_parameters TEXT,
match_parameters TEXT,
train_book TEXT,
match_book TEXT,
active BOOLEAN,
last_network BIGINT,
last_game BIGINT,
permission_expr TEXT,
multi_net_mode BOOLEAN
);
CREATE TABLE matches (
id BIGSERIAL PRIMARY KEY,
training_run_id BIGINT,
parameters TEXT,
candidate_id BIGINT REFERENCES networks(id),
current_best_id BIGINT REFERENCES networks(id),
games_created INTEGER,
wins INTEGER,
losses INTEGER,
draws INTEGER,
game_cap INTEGER,
done BOOLEAN,
passed BOOLEAN,
test_only BOOLEAN,
special_params BOOLEAN,
target_slice INTEGER
);
CREATE TABLE match_games (
id BIGSERIAL PRIMARY KEY,
created_at TIMESTAMPTZ NOT NULL,
user_id BIGINT,
match_id BIGINT REFERENCES matches(id),
version BIGINT,
pgn TEXT,
result INTEGER,
done BOOLEAN,
flip BOOLEAN,
engine_version TEXT
);
CREATE TABLE training_games (
id BIGSERIAL PRIMARY KEY,
created_at TIMESTAMPTZ,
user_id BIGINT REFERENCES users(id),
client_id BIGINT REFERENCES clients(id),
training_run_id BIGINT REFERENCES training_runs(id),
network_id BIGINT REFERENCES networks(id),
game_number BIGINT,
version BIGINT,
compacted BOOLEAN,
engine_version TEXT,
resign_fp_threshold DOUBLE PRECISION
);
CREATE INDEX idx_training_games_created_at ON training_games(created_at);
CREATE INDEX idx_training_games_user_id ON training_games(user_id);
CREATE INDEX idx_training_games_client_id ON training_games(client_id);
CREATE INDEX idx_training_games_network_id ON training_games(network_id);
CREATE TABLE server_data (
id BIGSERIAL PRIMARY KEY,
training_pgn_uploaded INTEGER
);
-- New tables, can be modified as needed
CREATE TABLE auth_tokens (
id BIGSERIAL PRIMARY KEY,
token TEXT UNIQUE,
created_at TIMESTAMPTZ NOT NULL,
updated_at TIMESTAMPTZ NOT NULL,
user_id BIGINT REFERENCES users(id), -- Potentially null for anonymous tokens
-- Potentially break the foreign key to connect to django's auth system
last_used_at TIMESTAMPTZ,
issued_reason TEXT, -- e.g., "anonymous", "migrated_credentials", "django_auth"
client_version TEXT,
client_host TEXT,
gpu_type TEXT,
gpu_id INTEGER
);
CREATE INDEX idx_auth_tokens_user_id ON auth_tokens(user_id);
CREATE INDEX idx_auth_tokens_last_used_at ON auth_tokens(last_used_at);
-- Book table
CREATE TABLE books (
id BIGSERIAL PRIMARY KEY,
created_at TIMESTAMPTZ NOT NULL,
updated_at TIMESTAMPTZ NOT NULL,
sha256 TEXT UNIQUE NOT NULL,
url TEXT,
size_bytes BIGINT,
format TEXT
);
-- Task table (base for all high-level tasks)
CREATE TABLE tasks (
id BIGSERIAL PRIMARY KEY,
created_at TIMESTAMPTZ NOT NULL,
updated_at TIMESTAMPTZ NOT NULL,
task_type TEXT, -- e.g., "TRAINING", "SPRT", "TUNE"
status TEXT,
description TEXT
);
-- TrainingTask table
CREATE TABLE training_tasks (
id BIGSERIAL PRIMARY KEY,
created_at TIMESTAMPTZ NOT NULL,
updated_at TIMESTAMPTZ NOT NULL,
task_id BIGINT UNIQUE REFERENCES tasks(id) ON DELETE CASCADE,
training_run_id BIGINT REFERENCES training_runs(id),
train_book_id BIGINT REFERENCES books(id),
match_book_id BIGINT REFERENCES books(id),
train_parameters TEXT,
match_parameters TEXT,
best_network_id BIGINT REFERENCES networks(id)
);
-- MatchTask table
CREATE TABLE match_tasks (
id BIGSERIAL PRIMARY KEY,
created_at TIMESTAMPTZ NOT NULL,
updated_at TIMESTAMPTZ NOT NULL,
task_id BIGINT UNIQUE REFERENCES tasks(id) ON DELETE CASCADE,
training_task_id BIGINT REFERENCES training_tasks(id),
candidate_network_id BIGINT REFERENCES networks(id),
current_best_network_id BIGINT REFERENCES networks(id),
games_created INTEGER,
wins INTEGER,
losses INTEGER,
draws INTEGER,
done BOOLEAN,
passed BOOLEAN
);
-- SprtTask table
CREATE TABLE sprt_tasks (
id BIGSERIAL PRIMARY KEY,
created_at TIMESTAMPTZ NOT NULL,
updated_at TIMESTAMPTZ NOT NULL,
task_id BIGINT UNIQUE REFERENCES tasks(id) ON DELETE CASCADE,
baseline_network_id BIGINT REFERENCES networks(id),
baseline_params_args TEXT,
baseline_params_uci_options TEXT,
candidate_network_id BIGINT REFERENCES networks(id),
candidate_params_args TEXT,
candidate_params_uci_options TEXT,
opening_book_id BIGINT REFERENCES books(id),
time_control_type VARCHAR(32),
base_time_seconds DOUBLE PRECISION,
increment_seconds DOUBLE PRECISION,
nodes_per_move BIGINT
);
-- See https://github.com/LeelaChessZero/OpenBench/blob/master/OpenBench/models.py for better table definitions. Must decide what is needed. At minimum, the following tables should be considered:
-- Result (Most importantly, the wins, losses, draws, games (WDL all added up, maybe dont count, compute at run time), crashes, timeouts)
-- TuneTask table
CREATE TABLE tune_tasks (
id BIGSERIAL PRIMARY KEY,
created_at TIMESTAMPTZ NOT NULL,
updated_at TIMESTAMPTZ NOT NULL,
task_id BIGINT UNIQUE REFERENCES tasks(id) ON DELETE CASCADE,
build_repo_url TEXT,
build_commit_hash TEXT,
build_params TEXT,
tune_network_id BIGINT REFERENCES networks(id),
opening_book_id BIGINT REFERENCES books(id),
games_per_param_set INTEGER,
time_control_type VARCHAR(32),
base_time_seconds DOUBLE PRECISION,
increment_seconds DOUBLE PRECISION,
nodes_per_move BIGINT
);
-- TuneParamSet table
CREATE TABLE tune_param_sets (
id BIGSERIAL PRIMARY KEY,
tune_task_id BIGINT REFERENCES tune_tasks(id),
param_set_id TEXT,
params_args TEXT,
params_uci_options TEXT
);
-- Notes: Tuning tasks will store data into Redis for processing externally.