@@ -38,16 +38,16 @@ class Client(StrictRedis):
38
38
>>> from redisai import Client
39
39
>>> con = Client(host='localhost', port=6379)
40
40
"""
41
- REDISAI_COMMANDS_RESPONSE_CALLBACKS = {
42
- }
41
+
42
+ REDISAI_COMMANDS_RESPONSE_CALLBACKS = { }
43
43
44
44
def __init__ (self , debug = False , enable_postprocess = True , * args , ** kwargs ):
45
45
super ().__init__ (* args , ** kwargs )
46
46
if debug :
47
47
self .execute_command = enable_debug (super ().execute_command )
48
48
self .enable_postprocess = enable_postprocess
49
49
50
- def pipeline (self , transaction : bool = True , shard_hint : bool = None ) -> ' Pipeline' :
50
+ def pipeline (self , transaction : bool = True , shard_hint : bool = None ) -> " Pipeline" :
51
51
"""
52
52
It follows the same pipeline implementation of native redis client but enables it
53
53
to access redisai operation as well. This function is experimental in the
@@ -61,13 +61,17 @@ def pipeline(self, transaction: bool = True, shard_hint: bool = None) -> 'Pipeli
61
61
>>> pipe.execute()
62
62
[True, b'OK']
63
63
"""
64
- return Pipeline (self .enable_postprocess ,
65
- self .connection_pool ,
66
- self .response_callbacks ,
67
- transaction = True , shard_hint = None )
64
+ return Pipeline (
65
+ self .enable_postprocess ,
66
+ self .connection_pool ,
67
+ self .response_callbacks ,
68
+ transaction = True ,
69
+ shard_hint = None ,
70
+ )
68
71
69
- def dag (self , load : Sequence = None , persist : Sequence = None ,
70
- readonly : bool = False ) -> 'Dag' :
72
+ def dag (
73
+ self , load : Sequence = None , persist : Sequence = None , readonly : bool = False
74
+ ) -> "Dag" :
71
75
"""
72
76
It returns a DAG object on which other DAG-allowed operations can be called. For
73
77
more details about DAG in RedisAI, refer to the RedisAI documentation.
@@ -101,7 +105,9 @@ def dag(self, load: Sequence = None, persist: Sequence = None,
101
105
>>> # You can even chain the operations
102
106
>>> result = dag.tensorset(**akwargs).modelrun(**bkwargs).tensorget(**ckwargs).run()
103
107
"""
104
- return Dag (load , persist , self .execute_command , readonly , self .enable_postprocess )
108
+ return Dag (
109
+ load , persist , self .execute_command , readonly , self .enable_postprocess
110
+ )
105
111
106
112
def loadbackend (self , identifier : AnyStr , path : AnyStr ) -> str :
107
113
"""
@@ -130,16 +136,18 @@ def loadbackend(self, identifier: AnyStr, path: AnyStr) -> str:
130
136
res = self .execute_command (* args )
131
137
return res if not self .enable_postprocess else processor .loadbackend (res )
132
138
133
- def modelset (self ,
134
- key : AnyStr ,
135
- backend : str ,
136
- device : str ,
137
- data : ByteString ,
138
- batch : int = None ,
139
- minbatch : int = None ,
140
- tag : AnyStr = None ,
141
- inputs : Union [AnyStr , List [AnyStr ]] = None ,
142
- outputs : Union [AnyStr , List [AnyStr ]] = None ) -> str :
139
+ def modelset (
140
+ self ,
141
+ key : AnyStr ,
142
+ backend : str ,
143
+ device : str ,
144
+ data : ByteString ,
145
+ batch : int = None ,
146
+ minbatch : int = None ,
147
+ tag : AnyStr = None ,
148
+ inputs : Union [AnyStr , List [AnyStr ]] = None ,
149
+ outputs : Union [AnyStr , List [AnyStr ]] = None ,
150
+ ) -> str :
143
151
"""
144
152
Set the model on provided key.
145
153
@@ -184,8 +192,9 @@ def modelset(self,
184
192
... inputs=['a', 'b'], outputs=['mul'], tag='v1.0')
185
193
'OK'
186
194
"""
187
- args = builder .modelset (key , backend , device , data ,
188
- batch , minbatch , tag , inputs , outputs )
195
+ args = builder .modelset (
196
+ key , backend , device , data , batch , minbatch , tag , inputs , outputs
197
+ )
189
198
res = self .execute_command (* args )
190
199
return res if not self .enable_postprocess else processor .modelset (res )
191
200
@@ -238,10 +247,12 @@ def modeldel(self, key: AnyStr) -> str:
238
247
res = self .execute_command (* args )
239
248
return res if not self .enable_postprocess else processor .modeldel (res )
240
249
241
- def modelrun (self ,
242
- key : AnyStr ,
243
- inputs : Union [AnyStr , List [AnyStr ]],
244
- outputs : Union [AnyStr , List [AnyStr ]]) -> str :
250
+ def modelrun (
251
+ self ,
252
+ key : AnyStr ,
253
+ inputs : Union [AnyStr , List [AnyStr ]],
254
+ outputs : Union [AnyStr , List [AnyStr ]],
255
+ ) -> str :
245
256
"""
246
257
Run the model using input(s) which are already in the scope and are associated
247
258
to some keys. Modelrun also needs the output key name(s) to store the output
@@ -296,17 +307,22 @@ def modelscan(self) -> List[List[AnyStr]]:
296
307
>>> con.modelscan()
297
308
[['pt_model', ''], ['m', 'v1.2']]
298
309
"""
299
- warnings .warn ("Experimental: Model List API is experimental and might change "
300
- "in the future without any notice" , UserWarning )
310
+ warnings .warn (
311
+ "Experimental: Model List API is experimental and might change "
312
+ "in the future without any notice" ,
313
+ UserWarning ,
314
+ )
301
315
args = builder .modelscan ()
302
316
res = self .execute_command (* args )
303
317
return res if not self .enable_postprocess else processor .modelscan (res )
304
318
305
- def tensorset (self ,
306
- key : AnyStr ,
307
- tensor : Union [np .ndarray , list , tuple ],
308
- shape : Sequence [int ] = None ,
309
- dtype : str = None ) -> str :
319
+ def tensorset (
320
+ self ,
321
+ key : AnyStr ,
322
+ tensor : Union [np .ndarray , list , tuple ],
323
+ shape : Sequence [int ] = None ,
324
+ dtype : str = None ,
325
+ ) -> str :
310
326
"""
311
327
Set the tensor to a key in RedisAI
312
328
@@ -338,9 +354,13 @@ def tensorset(self,
338
354
res = self .execute_command (* args )
339
355
return res if not self .enable_postprocess else processor .tensorset (res )
340
356
341
- def tensorget (self ,
342
- key : AnyStr , as_numpy : bool = True , as_numpy_mutable : bool = False ,
343
- meta_only : bool = False ) -> Union [dict , np .ndarray ]:
357
+ def tensorget (
358
+ self ,
359
+ key : AnyStr ,
360
+ as_numpy : bool = True ,
361
+ as_numpy_mutable : bool = False ,
362
+ meta_only : bool = False ,
363
+ ) -> Union [dict , np .ndarray ]:
344
364
"""
345
365
Retrieve the value of a tensor from the server. By default it returns the numpy
346
366
array but it can be controlled using the `as_type` and `meta_only` argument.
@@ -375,9 +395,15 @@ def tensorget(self,
375
395
"""
376
396
args = builder .tensorget (key , as_numpy , meta_only )
377
397
res = self .execute_command (* args )
378
- return res if not self .enable_postprocess else processor .tensorget (res , as_numpy , as_numpy_mutable , meta_only )
398
+ return (
399
+ res
400
+ if not self .enable_postprocess
401
+ else processor .tensorget (res , as_numpy , as_numpy_mutable , meta_only )
402
+ )
379
403
380
- def scriptset (self , key : AnyStr , device : str , script : str , tag : AnyStr = None ) -> str :
404
+ def scriptset (
405
+ self , key : AnyStr , device : str , script : str , tag : AnyStr = None
406
+ ) -> str :
381
407
"""
382
408
Set the script to RedisAI. Action similar to Modelset. RedisAI uses the TorchScript
383
409
engine to execute the script. So the script should have only TorchScript supported
@@ -469,12 +495,13 @@ def scriptdel(self, key: AnyStr) -> str:
469
495
res = self .execute_command (* args )
470
496
return res if not self .enable_postprocess else processor .scriptdel (res )
471
497
472
- def scriptrun (self ,
473
- key : AnyStr ,
474
- function : AnyStr ,
475
- inputs : Union [AnyStr , Sequence [AnyStr ]],
476
- outputs : Union [AnyStr , Sequence [AnyStr ]]
477
- ) -> str :
498
+ def scriptrun (
499
+ self ,
500
+ key : AnyStr ,
501
+ function : AnyStr ,
502
+ inputs : Union [AnyStr , Sequence [AnyStr ]],
503
+ outputs : Union [AnyStr , Sequence [AnyStr ]],
504
+ ) -> str :
478
505
"""
479
506
Run an already set script. Similar to modelrun
480
507
@@ -520,8 +547,11 @@ def scriptscan(self) -> List[List[AnyStr]]:
520
547
>>> con.scriptscan()
521
548
[['ket1', 'v1.0'], ['ket2', '']]
522
549
"""
523
- warnings .warn ("Experimental: Script List API is experimental and might change "
524
- "in the future without any notice" , UserWarning )
550
+ warnings .warn (
551
+ "Experimental: Script List API is experimental and might change "
552
+ "in the future without any notice" ,
553
+ UserWarning ,
554
+ )
525
555
args = builder .scriptscan ()
526
556
res = self .execute_command (* args )
527
557
return res if not self .enable_postprocess else processor .scriptscan (res )
@@ -584,4 +614,5 @@ def enable_debug(f):
584
614
def wrapper (* args ):
585
615
print (* args )
586
616
return f (* args )
617
+
587
618
return wrapper
0 commit comments