-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunner.cli.py
370 lines (297 loc) · 11.9 KB
/
runner.cli.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
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
import multiprocessing
import os
import time
from copy import deepcopy
import typer
from omegaconf import OmegaConf
from ray_runner import grid_run
from cookiemonster.utils import BIAS, BUDGET, LOGS_PATH
from data.criteo.creators.query_pool_creator import (
QueryPoolDatasetCreator as CriteoQueries,
)
from notebooks.utils import save_data
from plotting.criteo_plot import criteo_plot_experiments_side_by_side
from plotting.microbenchmark_plot import microbenchmark_plot_budget_consumption_bars
from plotting.patcg_plot import patcg_plot_experiments_side_by_side
app = typer.Typer()
def experiments_start_and_join(experiments):
for p in experiments:
time.sleep(5)
p.start()
for p in experiments:
p.join()
## ----------------- MICROBENCHMARK ----------------- ##
def get_path(path_base, knob1, knob2):
return f"{path_base}_knob1_{knob1}_knob2_{knob2}.csv"
def microbenchmark_varying_knob1(ray_session_dir):
dataset = "microbenchmark"
logs_dir = f"{dataset}/varying_knob1"
experiments = []
impressions_path_base = f"{dataset}/impressions"
conversions_path_base = f"{dataset}/conversions"
knob1s = [0.001, 0.01, 0.1, 1.0]
knob2 = 0.1
config = {
"baseline": ["ipa", "cookiemonster_base", "cookiemonster"],
"dataset_name": f"{dataset}",
"num_days_per_epoch": [7],
"num_days_attribution_window": [30],
"workload_size": [10],
"min_scheduling_batch_size_per_query": 2000,
"max_scheduling_batch_size_per_query": 2000,
"initial_budget": [1],
"logs_dir": logs_dir,
"loguru_level": "INFO",
"ray_session_dir": ray_session_dir,
"logging_keys": [BUDGET, BIAS],
}
for knob1 in knob1s:
config["impressions_path"] = get_path(impressions_path_base, knob1, knob2)
config["conversions_path"] = get_path(conversions_path_base, knob1, knob2)
experiments.append(
multiprocessing.Process(
target=lambda config: grid_run(**config), args=(deepcopy(config),)
)
)
experiments_start_and_join(experiments)
os.makedirs("figures", exist_ok=True)
path = "ray/microbenchmark/varying_knob1"
save_data(path, type="budget")
microbenchmark_plot_budget_consumption_bars(
"knob1", f"{LOGS_PATH.joinpath(path)}/budgets.csv", "figures/fig4_a_b.png"
)
def microbenchmark_varying_knob2(ray_session_dir):
dataset = "microbenchmark"
logs_dir = f"{dataset}/varying_knob2"
experiments = []
impressions_path_base = f"{dataset}/impressions"
conversions_path_base = f"{dataset}/conversions"
knob1 = 0.1
knob2s = [0.001, 0.01, 0.1, 1.0]
config = {
"baseline": ["ipa", "cookiemonster_base", "cookiemonster"],
"dataset_name": f"{dataset}",
"num_days_per_epoch": [7],
"num_days_attribution_window": [30],
"workload_size": [10],
"min_scheduling_batch_size_per_query": 2000,
"max_scheduling_batch_size_per_query": 2000,
"initial_budget": [1],
"logs_dir": logs_dir,
"loguru_level": "INFO",
"ray_session_dir": ray_session_dir,
"logging_keys": [BUDGET, BIAS],
}
for knob2 in knob2s:
config["impressions_path"] = get_path(impressions_path_base, knob1, knob2)
config["conversions_path"] = get_path(conversions_path_base, knob1, knob2)
experiments.append(
multiprocessing.Process(
target=lambda config: grid_run(**config), args=(deepcopy(config),)
)
)
experiments_start_and_join(experiments)
os.makedirs("figures", exist_ok=True)
path = "ray/microbenchmark/varying_knob2"
save_data(path, type="budget")
microbenchmark_plot_budget_consumption_bars(
"knob2", f"{LOGS_PATH.joinpath(path)}/budgets.csv", "figures/fig4_c_d.png"
)
def microbenchmark_varying_epoch_granularity(ray_session_dir):
dataset = "microbenchmark"
logs_dir = f"{dataset}/varying_epoch_granularity"
impressions_path_base = f"{dataset}/impressions"
conversions_path_base = f"{dataset}/conversions"
knob1 = 0.1
knob2 = 0.1
config = {
"baseline": ["ipa", "cookiemonster_base", "cookiemonster"],
"dataset_name": f"{dataset}",
"impressions_path": get_path(impressions_path_base, knob1, knob2),
"conversions_path": get_path(conversions_path_base, knob1, knob2),
"num_days_per_epoch": [1, 7, 14, 21, 28],
"num_days_attribution_window": [30],
"workload_size": [5],
"min_scheduling_batch_size_per_query": 1000,
"max_scheduling_batch_size_per_query": 1000,
"initial_budget": [1],
"logs_dir": logs_dir,
"loguru_level": "INFO",
"ray_session_dir": ray_session_dir,
"logging_keys": [BUDGET, BIAS],
}
grid_run(**config)
## ----------------- CRITEO ----------------- ##
def criteo_run(ray_session_dir):
dataset = "criteo"
impressions_path = f"{dataset}/{dataset}_query_pool_impressions.csv"
conversions_path = f"{dataset}/{dataset}_query_pool_conversions.csv"
logs_dir = f"{dataset}/bias_varying_epoch_size"
workload_generation = OmegaConf.load("data/criteo/config.json")
# augment_rate = workload_generation.get("augment_rate")
epoch_first_batch = [1, 60, 14]
epoch_second_batch = [30, 7, 21]
config = {
"baseline": ["ipa", "cookiemonster_base", "cookiemonster"],
"dataset_name": f"{dataset}",
"impressions_path": impressions_path,
"conversions_path": conversions_path,
"num_days_per_epoch": epoch_first_batch,
"num_days_attribution_window": [30],
"workload_size": [1_000], # force a high number so that we run on all queries
"max_scheduling_batch_size_per_query": workload_generation.max_batch_size,
"min_scheduling_batch_size_per_query": workload_generation.min_batch_size,
"initial_budget": [1],
"logs_dir": logs_dir,
"loguru_level": "INFO",
"ray_session_dir": ray_session_dir,
"logging_keys": [BIAS, BUDGET],
}
grid_run(**config)
config["num_days_per_epoch"] = epoch_second_batch
config["ray_init"] = False
grid_run(**config)
config["impressions_path"] = (
f"{dataset}/{dataset}_query_pool_impressions_augment_0.3.csv"
)
config["logs_dir"] = f"{dataset}/augmented_bias_varying_epoch_size"
for batch in [[1, 60], [14, 21], [30, 7]]:
config["num_days_per_epoch"] = batch
grid_run(**config)
path1 = "ray/criteo/bias_varying_epoch_size"
save_data(path1, type="filters_state")
save_data(path1, type="bias")
path2 = "ray/criteo/augmented_bias_varying_epoch_size"
save_data(path2, type="filters_state")
save_data(path2, type="bias")
os.makedirs("figures", exist_ok=True)
criteo_plot_experiments_side_by_side(
f"{LOGS_PATH.joinpath(path1)}",
f"{LOGS_PATH.joinpath(path2)}",
"figures/fig6_a_b_c_d.png",
)
def criteo_impressions_run(ray_session_dir):
dataset = "criteo"
conversions_path = f"{dataset}/{dataset}_query_pool_conversions.csv"
workload_generation = OmegaConf.load("data/criteo/config.json")
impression_augment_rates = CriteoQueries(
workload_generation
).get_impression_augment_rates()
ray_init = True
for rate in impression_augment_rates:
impressions_path = (
f"{dataset}/{dataset}_query_pool_impressions_augment_{rate}.csv"
)
logs_dir = f"{dataset}/augment_impressions_{rate}"
config = {
"baseline": ["ipa", "cookiemonster_base", "cookiemonster"],
"dataset_name": dataset,
"impressions_path": impressions_path,
"conversions_path": conversions_path,
"num_days_attribution_window": [30],
"workload_size": [
1_000
], # force a high number so that we run on all queries
"max_scheduling_batch_size_per_query": workload_generation.max_batch_size,
"min_scheduling_batch_size_per_query": workload_generation.min_batch_size,
"initial_budget": [1],
"num_days_per_epoch": [7],
"logs_dir": logs_dir,
"loguru_level": "INFO",
"ray_session_dir": ray_session_dir,
"logging_keys": [BIAS, BUDGET],
"ray_init": ray_init,
}
grid_run(**config)
ray_init = False
## ----------------- PATCG ----------------- ##
def patcg_varying_epoch_granularity(ray_session_dir):
dataset = "patcg"
logs_dir = f"{dataset}/varying_epoch_granularity_aw_7"
impressions_path = f"{dataset}/v375_{dataset}_impressions.csv"
conversions_path = f"{dataset}/v375_{dataset}_conversions.csv"
config = {
"baseline": ["ipa", "cookiemonster_base", "cookiemonster"],
"dataset_name": f"{dataset}",
"impressions_path": impressions_path,
"conversions_path": conversions_path,
"num_days_per_epoch": [21, 30],
"num_days_attribution_window": [7],
"workload_size": [80],
"max_scheduling_batch_size_per_query": 303009,
"min_scheduling_batch_size_per_query": 280000,
"initial_budget": [1],
"logs_dir": logs_dir,
"loguru_level": "INFO",
"ray_session_dir": ray_session_dir,
"logging_keys": [BUDGET, BIAS],
}
grid_run(**config)
config["num_days_per_epoch"] = [1, 60]
grid_run(**config)
config["num_days_per_epoch"] = [14, 7]
grid_run(**config)
path = "ray/patcg/varying_epoch_granularity_aw_7"
save_data(path, type="budget")
save_data(path, type="bias")
os.makedirs("figures", exist_ok=True)
patcg_plot_experiments_side_by_side(
f"{LOGS_PATH.joinpath(path)}", "figures/fig5_a_b_c.png"
)
def patcg_varying_initial_budget(ray_session_dir):
dataset = "patcg"
logs_dir = f"{dataset}/varying_initial_budget"
impressions_path = f"{dataset}/v375_{dataset}_impressions.csv"
conversions_path = f"{dataset}/v375_{dataset}_conversions.csv"
config = {
"baseline": ["ipa", "cookiemonster_base", "cookiemonster"],
"dataset_name": f"{dataset}",
"impressions_path": impressions_path,
"conversions_path": conversions_path,
"num_days_per_epoch": [7],
"num_days_attribution_window": [7],
"workload_size": [80],
"max_scheduling_batch_size_per_query": 303009,
"min_scheduling_batch_size_per_query": 280000,
"initial_budget": [1, 2, 4],
"logs_dir": logs_dir,
"loguru_level": "INFO",
"ray_session_dir": ray_session_dir,
"logging_keys": [BUDGET, BIAS],
}
grid_run(**config)
config["initial_budget"] = [6, 8, 10]
grid_run(**config)
def patcg_bias_varying_attribution_window(ray_session_dir):
dataset = "patcg"
logs_dir = f"{dataset}/bias_varying_attribution_window"
impressions_path = f"{dataset}/v375_{dataset}_impressions.csv"
conversions_path = f"{dataset}/v375_{dataset}_conversions.csv"
config = {
"baseline": ["ipa", "cookiemonster_base", "cookiemonster"],
"dataset_name": f"{dataset}",
"impressions_path": impressions_path,
"conversions_path": conversions_path,
"num_days_per_epoch": [7],
"num_days_attribution_window": [1, 7, 14, 21, 28],
"workload_size": [80],
"max_scheduling_batch_size_per_query": 303009,
"min_scheduling_batch_size_per_query": 280000,
"initial_budget": [1],
"logs_dir": logs_dir,
"loguru_level": "INFO",
"ray_session_dir": ray_session_dir,
"logging_keys": [BUDGET, BIAS],
}
grid_run(**config)
@app.command()
def run(
exp: str = "budget_consumption_vary_conversions_rate",
ray_session_dir: str = "",
loguru_level: str = "INFO",
):
os.environ["LOGURU_LEVEL"] = loguru_level
os.environ["TUNE_DISABLE_AUTO_CALLBACK_LOGGERS"] = "1"
globals()[f"{exp}"](ray_session_dir)
if __name__ == "__main__":
app()