6
6
import torch
7
7
import platform
8
8
9
- from click import ClickException
10
9
from .version import get_version
11
10
from .basic import BasicBenchmark
11
+ from .exceptions import DeviceError
12
12
from .moondream import MoonDreamBenchmark
13
+ from .datasets .manifest import generate_manifest
14
+ from .datasets .path import get_data_home , FIXTURES
13
15
14
16
15
17
CONTEXT_SETTINGS = {
34
36
envvar = ["CONSTRUE_ENV" , "ENV" ],
35
37
help = "name of the experimental environment for comparison (default is hostname)" ,
36
38
)
39
+ @click .option (
40
+ "-D" ,
41
+ "--datadir" ,
42
+ default = None ,
43
+ envvar = "CONSTRUE_DATA" ,
44
+ help = "specify the location to download datasets to" ,
45
+ )
46
+ @click .option (
47
+ "-C" ,
48
+ "--cleanup/--no-cleanup" ,
49
+ default = True ,
50
+ help = "cleanup all downloaded datasets after the benchmark is run" ,
51
+ )
37
52
@click .pass_context
38
- def main (ctx , env = None , device = None ):
53
+ def main (ctx , env = None , device = None , datadir = None , cleanup = True ):
39
54
if device is not None :
40
55
try :
41
56
torch .set_default_device (device )
42
57
except RuntimeError as e :
43
- raise ClickException ( str ( e ) )
58
+ raise DeviceError ( e )
44
59
45
60
click .echo (f"using torch.device(\" { device } \" )" )
46
61
@@ -50,6 +65,8 @@ def main(ctx, env=None, device=None):
50
65
ctx .ensure_object (dict )
51
66
ctx .obj ["device" ] = device
52
67
ctx .obj ["env" ] = env
68
+ ctx .obj ["data_home" ] = get_data_home (datadir )
69
+ ctx .obj ["cleanup" ] = cleanup
53
70
54
71
55
72
@main .command ()
@@ -89,11 +106,30 @@ def basic(ctx, **kwargs):
89
106
@main .command ()
90
107
@click .pass_context
91
108
def moondream (ctx , ** kwargs ):
92
- kwargs ["env" ] = ctx ["env" ]
109
+ kwargs ["env" ] = ctx . obj ["env" ]
93
110
benchmark = MoonDreamBenchmark (** kwargs )
94
111
benchmark .run ()
95
112
96
113
114
+ @main .command ()
115
+ @click .option (
116
+ "-f" ,
117
+ "--fixtures" ,
118
+ type = str ,
119
+ default = FIXTURES ,
120
+ help = "path to fixtures directory to generate manifest from" ,
121
+ )
122
+ @click .option (
123
+ "-o" ,
124
+ "--out" ,
125
+ type = str ,
126
+ default = None ,
127
+ help = "path to write the manifest to" ,
128
+ )
129
+ def manifest (fixtures = FIXTURES , out = None ):
130
+ generate_manifest (fixtures , out )
131
+
132
+
97
133
if __name__ == "__main__" :
98
134
main (
99
135
obj = {},
0 commit comments