-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.py
191 lines (131 loc) · 5.42 KB
/
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
import argparse
import sys
import ludwig.contrib
from ludwig.globals import LUDWIG_VERSION
from ludwig.utils.print_utils import get_logo
class CLI:
"""CLI describes a command line interface for interacting with Ludwig.
Functions are described below.
"""
def __init__(self):
parser = argparse.ArgumentParser(
description="ludwig cli runner",
usage=f"""\n{get_logo("ludwig cli", LUDWIG_VERSION)}
ludwig <command> [<args>]
Available sub-commands:
train Trains a model
predict Predicts using a pretrained model
evaluate Evaluate a pretrained model's performance
forecast Forecast the next n data points in a timeseries using a pretrained model
experiment Runs a full experiment training a model and evaluating it
hyperopt Perform hyperparameter optimization
benchmark Run and track experiments on a number of datasets and configs, and export experiment artifacts.
serve Serves a pretrained model
visualize Visualizes experimental results
collect_summary Prints names of weights and layers activations to use with other collect commands
collect_weights Collects tensors containing a pretrained model weights
collect_activations Collects tensors for each datapoint using a pretrained model
datasets Downloads and lists Ludwig-ready datasets
export_torchscript Exports Ludwig models to Torchscript
export_triton Exports Ludwig models to Triton
export_carton Exports Ludwig models to Carton
export_neuropod Exports Ludwig models to Neuropod
export_mlflow Exports Ludwig models to MLflow
preprocess Preprocess data and saves it into HDF5 and JSON format
synthesize_dataset Creates synthetic data for testing purposes
init_config Initialize a user config from a dataset and targets
render_config Renders the fully populated config with all defaults set
check_install Runs a quick training run on synthetic data to verify installation status
upload Push trained model artifacts to a registry (e.g., Predibase, HuggingFace Hub)
""",
)
parser.add_argument("command", help="Subcommand to run")
# parse_args defaults to [1:] for args, but you need to
# exclude the rest of the args too, or validation will fail
args = parser.parse_args(sys.argv[1:2])
if not hasattr(self, args.command):
print("Unrecognized command")
parser.print_help()
exit(1)
# use dispatch pattern to invoke method with same name
getattr(self, args.command)()
def train(self):
from ludwig import train
train.cli(sys.argv[2:])
def predict(self):
from ludwig import predict
predict.cli(sys.argv[2:])
def evaluate(self):
from ludwig import evaluate
evaluate.cli(sys.argv[2:])
def forecast(self):
from ludwig import forecast
forecast.cli(sys.argv[2:])
def experiment(self):
from ludwig import experiment
experiment.cli(sys.argv[2:])
def hyperopt(self):
from ludwig import hyperopt_cli
hyperopt_cli.cli(sys.argv[2:])
def benchmark(self):
from ludwig.benchmarking import benchmark
benchmark.cli(sys.argv[2:])
def serve(self):
from ludwig import serve
serve.cli(sys.argv[2:])
def multi_serve(self):
from ludwig import multi_serve
multi_serve.cli(sys.argv[2:])
def visualize(self):
from ludwig import visualize
visualize.cli(sys.argv[2:])
def collect_summary(self):
from ludwig import collect
collect.cli_collect_summary(sys.argv[2:])
def collect_weights(self):
from ludwig import collect
collect.cli_collect_weights(sys.argv[2:])
def collect_activations(self):
from ludwig import collect
collect.cli_collect_activations(sys.argv[2:])
def export_torchscript(self):
from ludwig import export
export.cli_export_torchscript(sys.argv[2:])
def export_triton(self):
from ludwig import export
export.cli_export_triton(sys.argv[2:])
def export_carton(self):
from ludwig import export
export.cli_export_carton(sys.argv[2:])
def export_neuropod(self):
from ludwig import export
export.cli_export_neuropod(sys.argv[2:])
def export_mlflow(self):
from ludwig import export
export.cli_export_mlflow(sys.argv[2:])
def preprocess(self):
from ludwig import preprocess
preprocess.cli(sys.argv[2:])
def synthesize_dataset(self):
from ludwig.data import dataset_synthesizer
dataset_synthesizer.cli(sys.argv[2:])
def init_config(self):
from ludwig import automl
automl.cli_init_config(sys.argv[2:])
def render_config(self):
from ludwig.utils import defaults
defaults.cli_render_config(sys.argv[2:])
def check_install(self):
from ludwig import check
check.cli(sys.argv[2:])
def datasets(self):
from ludwig import datasets
datasets.cli(sys.argv[2:])
def upload(self):
from ludwig import upload
upload.cli(sys.argv[2:])
def main():
ludwig.contrib.preload(sys.argv)
CLI()
if __name__ == "__main__":
main()