/
test_configuration.py
68 lines (59 loc) · 2.25 KB
/
test_configuration.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
from tempfile import NamedTemporaryFile
from bentoml._internal.configuration.containers import BentoMLConfiguration
OVERRIDE_RUNNERS = """
runners:
batching:
enabled: False
max_batch_size: 10
resources:
cpu: 4
logging:
access:
enabled: False
test_runner_1:
resources: system
test_runner_2:
resources:
cpu: 2
test_runner_gpu:
resources:
nvidia.com/gpu: 1
test_runner_batching:
batching:
enabled: True
logging:
access:
enabled: True
"""
def test_bentoml_configuration_runner_override():
tmpfile = NamedTemporaryFile(mode="w+", delete=False)
tmpfile.write(OVERRIDE_RUNNERS)
tmpfile.flush()
tmpfile.close()
bentoml_cfg = BentoMLConfiguration(override_config_file=tmpfile.name).as_dict()
runner_cfg = bentoml_cfg["runners"]
# test_runner_1
test_runner_1 = runner_cfg["test_runner_1"]
assert test_runner_1["batching"]["enabled"] is False
assert test_runner_1["batching"]["max_batch_size"] == 10
assert test_runner_1["logging"]["access"]["enabled"] is False
# assert test_runner_1["resources"]["cpu"] == 4
# test_runner_2
test_runner_2 = runner_cfg["test_runner_2"]
assert test_runner_2["batching"]["enabled"] is False
assert test_runner_2["batching"]["max_batch_size"] == 10
assert test_runner_2["logging"]["access"]["enabled"] is False
assert test_runner_2["resources"]["cpu"] == 2
# test_runner_gpu
test_runner_gpu = runner_cfg["test_runner_gpu"]
assert test_runner_gpu["batching"]["enabled"] is False
assert test_runner_gpu["batching"]["max_batch_size"] == 10
assert test_runner_gpu["logging"]["access"]["enabled"] is False
assert test_runner_gpu["resources"]["cpu"] == 4 # should use global
assert test_runner_gpu["resources"]["nvidia.com/gpu"] == 1
# test_runner_batching
test_runner_batching = runner_cfg["test_runner_batching"]
assert test_runner_batching["batching"]["enabled"] is True
assert test_runner_batching["batching"]["max_batch_size"] == 10
assert test_runner_batching["logging"]["access"]["enabled"] is True
assert test_runner_batching["resources"]["cpu"] == 4 # should use global