11
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
# See the License for the specific language governing permissions and
13
13
# limitations under the License.
14
-
15
- """
16
- There are two sub-commands for the server:
17
- 1. `deepsparse.server config [OPTIONS] <config path>`
18
- 2. `deepsparse.server task [OPTIONS] <task>
19
- ```
20
- """
21
-
22
14
import os
23
- import warnings
24
15
from tempfile import TemporaryDirectory
25
16
from typing import Optional , Union
26
17
@@ -223,6 +214,7 @@ def main(
223
214
# if the --model_path option is provided, use that
224
215
# otherwise if the argument is given and --model_path is not used, use the
225
216
# argument instead
217
+
226
218
if model and model_path == "default" :
227
219
model_path = model
228
220
@@ -236,6 +228,10 @@ def main(
236
228
if task is None and config_file is None :
237
229
raise ValueError ("Must specify either --task or --config_file. Found neither" )
238
230
231
+ if config_file is not None :
232
+ server = _fetch_server (integration = integration , config = config_file )
233
+ server .start_server (host , port , log_level , hot_reload_config = hot_reload_config )
234
+
239
235
if task is not None :
240
236
cfg = ServerConfig (
241
237
num_cores = num_cores ,
@@ -263,98 +259,6 @@ def main(
263
259
host , port , log_level , hot_reload_config = hot_reload_config
264
260
)
265
261
266
- if config_file is not None :
267
- server = _fetch_server (integration = integration , config = config_file )
268
- server .start_server (host , port , log_level , hot_reload_config = hot_reload_config )
269
-
270
-
271
- @main .command (
272
- context_settings = dict (
273
- token_normalize_func = lambda x : x .replace ("-" , "_" ), show_default = True
274
- ),
275
- )
276
- @click .argument ("config-path" , type = str )
277
- @HOST_OPTION
278
- @PORT_OPTION
279
- @LOG_LEVEL_OPTION
280
- @HOT_RELOAD_OPTION
281
- def config (
282
- config_path : str , host : str , port : int , log_level : str , hot_reload_config : bool
283
- ):
284
- "[DEPRECATED] Run the server using configuration from a .yaml file."
285
- warnings .simplefilter ("always" , DeprecationWarning )
286
- warnings .warn (
287
- "Using the `config` sub command is deprecated. "
288
- "Use the `--config_file` argument instead." ,
289
- category = DeprecationWarning ,
290
- )
291
-
292
-
293
- @main .command (
294
- context_settings = dict (
295
- token_normalize_func = lambda x : x .replace ("-" , "_" ), show_default = True
296
- ),
297
- )
298
- @click .argument (
299
- "task" ,
300
- type = click .Choice (SupportedTasks .task_names (), case_sensitive = False ),
301
- )
302
- @MODEL_OPTION
303
- @BATCH_OPTION
304
- @CORES_OPTION
305
- @WORKERS_OPTION
306
- @HOST_OPTION
307
- @PORT_OPTION
308
- @LOG_LEVEL_OPTION
309
- @HOT_RELOAD_OPTION
310
- @INTEGRATION_OPTION
311
- def task (
312
- task : str ,
313
- model_path : str ,
314
- batch_size : int ,
315
- num_cores : int ,
316
- num_workers : int ,
317
- host : str ,
318
- port : int ,
319
- log_level : str ,
320
- hot_reload_config : bool ,
321
- integration : str ,
322
- ):
323
- """
324
- [DEPRECATED] Run the server using configuration with CLI options,
325
- which can only serve a single model.
326
- """
327
-
328
- warnings .simplefilter ("always" , DeprecationWarning )
329
- warnings .warn (
330
- "Using the `task` sub command is deprecated. "
331
- "Use the `--task` argument instead." ,
332
- category = DeprecationWarning ,
333
- )
334
-
335
- cfg = ServerConfig (
336
- num_cores = num_cores ,
337
- num_workers = num_workers ,
338
- integration = integration ,
339
- endpoints = [
340
- EndpointConfig (
341
- task = task ,
342
- name = f"{ task } " ,
343
- model = model_path ,
344
- batch_size = batch_size ,
345
- )
346
- ],
347
- loggers = {},
348
- )
349
-
350
- with TemporaryDirectory () as tmp_dir :
351
- config_path = os .path .join (tmp_dir , "server-config.yaml" )
352
- with open (config_path , "w" ) as fp :
353
- yaml .dump (cfg .dict (), fp )
354
-
355
- server = _fetch_server (integration = integration , config = config_path )
356
- server .start_server (host , port , log_level , hot_reload_config = hot_reload_config )
357
-
358
262
359
263
def _fetch_server (integration : str , config : Union [ServerConfig , str ]):
360
264
if isinstance (config , str ):
0 commit comments