forked from triton-inference-server/client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
executable file
·2221 lines (1931 loc) · 80 KB
/
__init__.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
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright 2020-2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of NVIDIA CORPORATION nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
try:
from geventhttpclient import HTTPClient
from geventhttpclient.url import URL
import gevent
import gevent.pool
from urllib.parse import quote, quote_plus
import rapidjson as json
import numpy as np
import struct
import gzip, zlib
import base64
except ModuleNotFoundError as error:
raise RuntimeError(
'The installation does not include http support. Specify \'http\' or \'all\' while installing the tritonclient package to include the support'
) from error
from tritonclient.utils import *
def _get_error(response):
"""
Returns the InferenceServerException object if response
indicates the error. If no error then return None
"""
if response.status_code != 200:
error_response = json.loads(response.read())
return InferenceServerException(msg=error_response["error"])
else:
return None
def _raise_if_error(response):
"""
Raise InferenceServerException if received non-Success
response from the server
"""
error = _get_error(response)
if error is not None:
raise error
def _get_query_string(query_params):
params = []
for key, value in query_params.items():
if isinstance(value, list):
for item in value:
params.append("%s=%s" %
(quote_plus(key), quote_plus(str(item))))
else:
params.append("%s=%s" % (quote_plus(key), quote_plus(str(value))))
if params:
return "&".join(params)
return ''
def _get_inference_request(inputs, request_id, outputs, sequence_id,
sequence_start, sequence_end, priority, timeout):
infer_request = {}
parameters = {}
if request_id != "":
infer_request['id'] = request_id
if sequence_id != 0 and sequence_id != "":
parameters['sequence_id'] = sequence_id
parameters['sequence_start'] = sequence_start
parameters['sequence_end'] = sequence_end
if priority != 0:
parameters['priority'] = priority
if timeout is not None:
parameters['timeout'] = timeout
infer_request['inputs'] = [
this_input._get_tensor() for this_input in inputs
]
if outputs:
infer_request['outputs'] = [
this_output._get_tensor() for this_output in outputs
]
else:
# no outputs specified so set 'binary_data_output' True in the
# request so that all outputs are returned in binary format
parameters['binary_data_output'] = True
if parameters:
infer_request['parameters'] = parameters
request_body = json.dumps(infer_request)
json_size = len(request_body)
binary_data = None
for input_tensor in inputs:
raw_data = input_tensor._get_binary_data()
if raw_data is not None:
if binary_data is not None:
binary_data += raw_data
else:
binary_data = raw_data
if binary_data is not None:
request_body = struct.pack(
'{}s{}s'.format(len(request_body), len(binary_data)),
request_body.encode(), binary_data)
return request_body, json_size
return request_body, None
class InferenceServerClient:
"""An InferenceServerClient object is used to perform any kind of
communication with the InferenceServer using http protocol. None
of the methods are thread safe. The object is intended to be used
by a single thread and simultaneously calling different methods
with different threads is not supported and will cause undefined
behavior.
Parameters
----------
url : str
The inference server name, port and optional base path
in the following format: host:port/<base-path>, e.g.
'localhost:8000'.
verbose : bool
If True generate verbose output. Default value is False.
concurrency : int
The number of connections to create for this client.
Default value is 1.
connection_timeout : float
The timeout value for the connection. Default value
is 60.0 sec.
network_timeout : float
The timeout value for the network. Default value is
60.0 sec
max_greenlets : int
Determines the maximum allowed number of worker greenlets
for handling asynchronous inference requests. Default value
is None, which means there will be no restriction on the
number of greenlets created.
ssl : bool
If True, channels the requests to encrypted https scheme.
Some improper settings may cause connection to prematurely
terminate with an unsuccessful handshake. See
`ssl_context_factory` option for using secure default
settings. Default value for this option is False.
ssl_options : dict
Any options supported by `ssl.wrap_socket` specified as
dictionary. The argument is ignored if 'ssl' is specified
False.
ssl_context_factory : SSLContext callable
It must be a callbable that returns a SSLContext. Set to
`gevent.ssl.create_default_context` to use contexts with
secure default settings. This should most likely resolve
connection issues in a secure way. The default value for
this option is None which directly wraps the socket with
the options provided via `ssl_options`. The argument is
ignored if 'ssl' is specified False.
insecure : bool
If True, then does not match the host name with the certificate.
Default value is False. The argument is ignored if 'ssl' is
specified False.
Raises
------
Exception
If unable to create a client.
"""
def __init__(self,
url,
verbose=False,
concurrency=1,
connection_timeout=60.0,
network_timeout=60.0,
max_greenlets=None,
ssl=False,
ssl_options=None,
ssl_context_factory=None,
insecure=False):
if url.startswith("http://") or url.startswith("https://"):
raise_error("url should not include the scheme")
scheme = "https://" if ssl else "http://"
self._parsed_url = URL(scheme + url)
self._base_uri = self._parsed_url.request_uri.rstrip('/')
self._client_stub = HTTPClient.from_url(
self._parsed_url,
concurrency=concurrency,
connection_timeout=connection_timeout,
network_timeout=network_timeout,
ssl_options=ssl_options,
ssl_context_factory=ssl_context_factory,
insecure=insecure)
self._pool = gevent.pool.Pool(max_greenlets)
self._verbose = verbose
def __enter__(self):
return self
def __exit__(self, type, value, traceback):
self.close()
def __del__(self):
self.close()
def close(self):
"""Close the client. Any future calls to server
will result in an Error.
"""
self._pool.join()
self._client_stub.close()
def _get(self, request_uri, headers, query_params):
"""Issues the GET request to the server
Parameters
----------
request_uri: str
The request URI to be used in GET request.
headers: dict
Additional HTTP headers to include in the request.
query_params: dict
Optional url query parameters to use in network
transaction.
Returns
-------
geventhttpclient.response.HTTPSocketPoolResponse
The response from server.
"""
self._validate_headers(headers)
if self._base_uri is not None:
request_uri = self._base_uri + "/" + request_uri
if query_params is not None:
request_uri = request_uri + "?" + _get_query_string(query_params)
if self._verbose:
print("GET {}, headers {}".format(request_uri, headers))
if headers is not None:
response = self._client_stub.get(request_uri, headers=headers)
else:
response = self._client_stub.get(request_uri)
if self._verbose:
print(response)
return response
def _post(self, request_uri, request_body, headers, query_params):
"""Issues the POST request to the server
Parameters
----------
request_uri: str
The request URI to be used in POST request.
request_body: str
The body of the request
headers: dict
Additional HTTP headers to include in the request.
query_params: dict
Optional url query parameters to use in network
transaction.
Returns
-------
geventhttpclient.response.HTTPSocketPoolResponse
The response from server.
"""
self._validate_headers(headers)
if self._base_uri is not None:
request_uri = self._base_uri + "/" + request_uri
if query_params is not None:
request_uri = request_uri + "?" + _get_query_string(query_params)
if self._verbose:
print("POST {}, headers {}\n{}".format(request_uri, headers,
request_body))
if headers is not None:
response = self._client_stub.post(request_uri=request_uri,
body=request_body,
headers=headers)
else:
response = self._client_stub.post(request_uri=request_uri,
body=request_body)
if self._verbose:
print(response)
return response
def _validate_headers(self, headers):
"""Checks for any unsupported HTTP headers before processing a request.
Parameters
----------
headers: dict
HTTP headers to validate before processing the request.
Raises
------
InferenceServerException
If an unsupported HTTP header is included in a request.
"""
if not headers:
return
# HTTP headers are case-insensitive, so force lowercase for comparison
headers_lowercase = {k.lower(): v for k, v in headers.items()}
# The python client lirary (and geventhttpclient) do not encode request
# data based on "Transfer-Encoding" header, so reject this header if
# included. Other libraries may do this encoding under the hood.
# The python client library does expose special arguments to support
# some "Content-Encoding" headers.
if "transfer-encoding" in headers_lowercase:
raise_error("Unsupported HTTP header: 'Transfer-Encoding' is not "
"supported in the Python client library. Use raw HTTP "
"request libraries or the C++ client instead for this "
"header.")
def is_server_live(self, headers=None, query_params=None):
"""Contact the inference server and get liveness.
Parameters
----------
headers: dict
Optional dictionary specifying additional HTTP
headers to include in the request.
query_params: dict
Optional url query parameters to use in network
transaction.
Returns
-------
bool
True if server is live, False if server is not live.
Raises
------
Exception
If unable to get liveness.
"""
request_uri = "v2/health/live"
response = self._get(request_uri=request_uri,
headers=headers,
query_params=query_params)
return response.status_code == 200
def is_server_ready(self, headers=None, query_params=None):
"""Contact the inference server and get readiness.
Parameters
----------
headers: dict
Optional dictionary specifying additional HTTP
headers to include in the request.
query_params: dict
Optional url query parameters to use in network
transaction.
Returns
-------
bool
True if server is ready, False if server is not ready.
Raises
------
Exception
If unable to get readiness.
"""
request_uri = "v2/health/ready"
response = self._get(request_uri=request_uri,
headers=headers,
query_params=query_params)
return response.status_code == 200
def is_model_ready(self,
model_name,
model_version="",
headers=None,
query_params=None):
"""Contact the inference server and get the readiness of specified model.
Parameters
----------
model_name: str
The name of the model to check for readiness.
model_version: str
The version of the model to check for readiness. The default value
is an empty string which means then the server will choose a version
based on the model and internal policy.
headers: dict
Optional dictionary specifying additional HTTP
headers to include in the request.
query_params: dict
Optional url query parameters to use in network
transaction.
Returns
-------
bool
True if the model is ready, False if not ready.
Raises
------
Exception
If unable to get model readiness.
"""
if type(model_version) != str:
raise_error("model version must be a string")
if model_version != "":
request_uri = "v2/models/{}/versions/{}/ready".format(
quote(model_name), model_version)
else:
request_uri = "v2/models/{}/ready".format(quote(model_name))
response = self._get(request_uri=request_uri,
headers=headers,
query_params=query_params)
return response.status_code == 200
def get_server_metadata(self, headers=None, query_params=None):
"""Contact the inference server and get its metadata.
Parameters
----------
headers: dict
Optional dictionary specifying additional HTTP
headers to include in the request.
query_params: dict
Optional url query parameters to use in network
transaction.
Returns
-------
dict
The JSON dict holding the metadata.
Raises
------
InferenceServerException
If unable to get server metadata.
"""
request_uri = "v2"
response = self._get(request_uri=request_uri,
headers=headers,
query_params=query_params)
_raise_if_error(response)
content = response.read()
if self._verbose:
print(content)
return json.loads(content)
def get_model_metadata(self,
model_name,
model_version="",
headers=None,
query_params=None):
"""Contact the inference server and get the metadata for specified model.
Parameters
----------
model_name: str
The name of the model
model_version: str
The version of the model to get metadata. The default value
is an empty string which means then the server will choose
a version based on the model and internal policy.
headers: dict
Optional dictionary specifying additional
HTTP headers to include in the request
query_params: dict
Optional url query parameters to use in network
transaction
Returns
-------
dict
The JSON dict holding the metadata.
Raises
------
InferenceServerException
If unable to get model metadata.
"""
if type(model_version) != str:
raise_error("model version must be a string")
if model_version != "":
request_uri = "v2/models/{}/versions/{}".format(
quote(model_name), model_version)
else:
request_uri = "v2/models/{}".format(quote(model_name))
response = self._get(request_uri=request_uri,
headers=headers,
query_params=query_params)
_raise_if_error(response)
content = response.read()
if self._verbose:
print(content)
return json.loads(content)
def get_model_config(self,
model_name,
model_version="",
headers=None,
query_params=None):
"""Contact the inference server and get the configuration for specified model.
Parameters
----------
model_name: str
The name of the model
model_version: str
The version of the model to get configuration. The default value
is an empty string which means then the server will choose
a version based on the model and internal policy.
headers: dict
Optional dictionary specifying additional
HTTP headers to include in the request
query_params: dict
Optional url query parameters to use in network
transaction
Returns
-------
dict
The JSON dict holding the model config.
Raises
------
InferenceServerException
If unable to get model configuration.
"""
if model_version != "":
request_uri = "v2/models/{}/versions/{}/config".format(
quote(model_name), model_version)
else:
request_uri = "v2/models/{}/config".format(quote(model_name))
response = self._get(request_uri=request_uri,
headers=headers,
query_params=query_params)
_raise_if_error(response)
content = response.read()
if self._verbose:
print(content)
return json.loads(content)
def get_model_repository_index(self, headers=None, query_params=None):
"""Get the index of model repository contents
Parameters
----------
headers: dict
Optional dictionary specifying additional
HTTP headers to include in the request
query_params: dict
Optional url query parameters to use in network
transaction
Returns
-------
dict
The JSON dict holding the model repository index.
Raises
------
InferenceServerException
If unable to get the repository index.
"""
request_uri = "v2/repository/index"
response = self._post(request_uri=request_uri,
request_body="",
headers=headers,
query_params=query_params)
_raise_if_error(response)
content = response.read()
if self._verbose:
print(content)
return json.loads(content)
def load_model(self,
model_name,
headers=None,
query_params=None,
config=None,
files=None):
"""Request the inference server to load or reload specified model.
Parameters
----------
model_name : str
The name of the model to be loaded.
headers: dict
Optional dictionary specifying additional
HTTP headers to include in the request.
query_params: dict
Optional url query parameters to use in network
transaction.
config: str
Optional JSON representation of a model config provided for
the load request, if provided, this config will be used for
loading the model.
files: dict
Optional dictionary specifying file path (with "file:" prefix) in
the override model directory to the file content as bytes.
The files will form the model directory that the model will be
loaded from. If specified, 'config' must be provided to be
the model configuration of the override model directory.
Raises
------
InferenceServerException
If unable to load the model.
"""
request_uri = "v2/repository/models/{}/load".format(quote(model_name))
load_request = {}
if config is not None:
if "parameters" not in load_request:
load_request["parameters"] = {}
load_request["parameters"]["config"] = config
if files is not None:
for path, content in files.items():
if "parameters" not in load_request:
load_request["parameters"] = {}
load_request["parameters"][path] = base64.b64encode(content)
response = self._post(request_uri=request_uri,
request_body=json.dumps(load_request),
headers=headers,
query_params=query_params)
_raise_if_error(response)
if self._verbose:
print("Loaded model '{}'".format(model_name))
def unload_model(self,
model_name,
headers=None,
query_params=None,
unload_dependents=False):
"""Request the inference server to unload specified model.
Parameters
----------
model_name : str
The name of the model to be unloaded.
headers: dict
Optional dictionary specifying additional
HTTP headers to include in the request
query_params: dict
Optional url query parameters to use in network
transaction
unload_dependents : bool
Whether the dependents of the model should also be unloaded.
Raises
------
InferenceServerException
If unable to unload the model.
"""
request_uri = "v2/repository/models/{}/unload".format(quote(model_name))
unload_request = {
"parameters": {
"unload_dependents": unload_dependents
}
}
response = self._post(request_uri=request_uri,
request_body=json.dumps(unload_request),
headers=headers,
query_params=query_params)
_raise_if_error(response)
if self._verbose:
print("Loaded model '{}'".format(model_name))
def get_inference_statistics(self,
model_name="",
model_version="",
headers=None,
query_params=None):
"""Get the inference statistics for the specified model name and
version.
Parameters
----------
model_name : str
The name of the model to get statistics. The default value is
an empty string, which means statistics of all models will
be returned.
model_version: str
The version of the model to get inference statistics. The
default value is an empty string which means then the server
will return the statistics of all available model versions.
headers: dict
Optional dictionary specifying additional HTTP
headers to include in the request.
query_params: dict
Optional url query parameters to use in network
transaction
Returns
-------
dict
The JSON dict holding the model inference statistics.
Raises
------
InferenceServerException
If unable to get the model inference statistics.
"""
if model_name != "":
if type(model_version) != str:
raise_error("model version must be a string")
if model_version != "":
request_uri = "v2/models/{}/versions/{}/stats".format(
quote(model_name), model_version)
else:
request_uri = "v2/models/{}/stats".format(quote(model_name))
else:
request_uri = "v2/models/stats"
response = self._get(request_uri=request_uri,
headers=headers,
query_params=query_params)
_raise_if_error(response)
content = response.read()
if self._verbose:
print(content)
return json.loads(content)
def update_trace_settings(self,
model_name=None,
settings={},
headers=None,
query_params=None):
"""Update the trace settings for the specified model name, or
global trace settings if model name is not given.
Returns the trace settings after the update.
Parameters
----------
model_name : str
The name of the model to update trace settings. Specifying None or
empty string will update the global trace settings.
The default value is None.
settings: dict
The new trace setting values. Only the settings listed will be
updated. If a trace setting is listed in the dictionary with
a value of 'None', that setting will be cleared.
headers: dict
Optional dictionary specifying additional HTTP
headers to include in the request.
query_params: dict
Optional url query parameters to use in network
transaction
Returns
-------
dict
The JSON dict holding the updated trace settings.
Raises
------
InferenceServerException
If unable to update the trace settings.
"""
if (model_name is not None) and (model_name != ""):
request_uri = "v2/models/{}/trace/setting".format(quote(model_name))
else:
request_uri = "v2/trace/setting"
response = self._post(request_uri=request_uri,
request_body=json.dumps(settings),
headers=headers,
query_params=query_params)
_raise_if_error(response)
content = response.read()
if self._verbose:
print(content)
return json.loads(content)
def get_trace_settings(self,
model_name=None,
headers=None,
query_params=None):
"""Get the trace settings for the specified model name, or global trace
settings if model name is not given
Parameters
----------
model_name : str
The name of the model to get trace settings. Specifying None or
empty string will return the global trace settings.
The default value is None.
headers: dict
Optional dictionary specifying additional HTTP
headers to include in the request.
query_params: dict
Optional url query parameters to use in network
transaction
Returns
-------
dict
The JSON dict holding the trace settings.
Raises
------
InferenceServerException
If unable to get the trace settings.
"""
if (model_name is not None) and (model_name != ""):
request_uri = "v2/models/{}/trace/setting".format(quote(model_name))
else:
request_uri = "v2/trace/setting"
response = self._get(request_uri=request_uri,
headers=headers,
query_params=query_params)
_raise_if_error(response)
content = response.read()
if self._verbose:
print(content)
return json.loads(content)
def update_log_settings(self, settings, headers=None, query_params=None):
"""Update the global log settings of the Triton server.
Parameters
----------
settings: dict
The new log setting values. Only the settings listed will be
updated.
headers: dict
Optional dictionary specifying additional HTTP
headers to include in the request.
query_params: dict
Optional url query parameters to use in network
transaction
Returns
-------
dict
The JSON dict holding the updated log settings.
Raises
------
InferenceServerException
If unable to update the log settings.
"""
request_uri = "v2/logging"
response = self._post(request_uri=request_uri,
request_body=json.dumps(settings),
headers=headers,
query_params=query_params)
_raise_if_error(response)
content = response.read()
if self._verbose:
print(content)
return json.loads(content)
def get_log_settings(self, headers=None, query_params=None):
"""Get the global log settings for the Triton server
Parameters
----------
headers: dict
Optional dictionary specifying additional HTTP
headers to include in the request.
query_params: dict
Optional url query parameters to use in network
transaction
Returns
-------
dict
The JSON dict holding the log settings.
Raises
------
InferenceServerException
If unable to get the log settings.
"""
request_uri = "v2/logging"
response = self._get(request_uri=request_uri,
headers=headers,
query_params=query_params)
_raise_if_error(response)
content = response.read()
if self._verbose:
print(content)
return json.loads(content)
def get_system_shared_memory_status(self,
region_name="",
headers=None,
query_params=None):
"""Request system shared memory status from the server.
Parameters
----------
region_name : str
The name of the region to query status. The default
value is an empty string, which means that the status
of all active system shared memory will be returned.
headers: dict
Optional dictionary specifying additional HTTP
headers to include in the request
query_params: dict
Optional url query parameters to use in network
transaction
Returns
-------
dict
The JSON dict holding system shared memory status.
Raises
------
InferenceServerException
If unable to get the status of specified shared memory.
"""
if region_name != "":
request_uri = "v2/systemsharedmemory/region/{}/status".format(
quote(region_name))
else:
request_uri = "v2/systemsharedmemory/status"
response = self._get(request_uri=request_uri,
headers=headers,
query_params=query_params)
_raise_if_error(response)
content = response.read()
if self._verbose:
print(content)
return json.loads(content)