Skip to content

Commit 94bcd18

Browse files
Extended testing for tensorset and modelrun (#320)
* [add] extended testing for tensorset and modelrun * [fix] adding numpy version to make sure we have rng * [add] updated numpy test requirements to 1.17 (use rng ) * [fix] proper naming for tensorflow modelrun added test
1 parent c10c8bb commit 94bcd18

File tree

7 files changed

+10095
-11
lines changed

7 files changed

+10095
-11
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ commands:
3636
name: Test
3737
command: |
3838
mkdir -p ~/workspace/tests
39-
make -C opt test SHOW=1 VERBOSE=1
39+
make -C opt test SHOW=1
4040
- run:
4141
name: Package
4242
command: make -C opt pack BRANCH="${CIRCLE_BRANCH//[^A-Za-z0-9._-]/_}" INTO=~/workspace/packages SHOW=1

test/includes.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import time
66
from multiprocessing import Process
77
import threading
8-
8+
from numpy.random import default_rng
99
import numpy as np
1010
from skimage.io import imread
1111
from skimage.transform import resize
@@ -84,6 +84,22 @@ def load_mobilenet_test_data():
8484

8585
return model_pb, labels, img
8686

87+
def load_creditcardfraud_data(env,max_tensors=10000):
88+
test_data_path = os.path.join(os.path.dirname(__file__), 'test_data')
89+
model_filename = os.path.join(test_data_path, 'creditcardfraud.pb')
90+
creditcard_transaction_filename = os.path.join(test_data_path, 'creditcard_10K.csv')
91+
rg = default_rng()
92+
93+
creditcard_transactions = np.genfromtxt(creditcard_transaction_filename, delimiter=',', dtype='float32', skip_header=1, usecols=range(0,30))
94+
95+
creditcard_referencedata = []
96+
for tr in range(0,max_tensors):
97+
creditcard_referencedata.append(rg.random((1,256), dtype='float32'))
98+
99+
with open(model_filename, 'rb') as f:
100+
model_pb = f.read()
101+
102+
return model_pb, creditcard_transactions, creditcard_referencedata
87103

88104
def run_mobilenet(con, img, input_var, output_var):
89105
time.sleep(0.5 * random.randint(0, 10))

test/test_data/creditcard_10K.csv

Lines changed: 10001 additions & 0 deletions
Large diffs are not rendered by default.

test/test_data/creditcardfraud.pb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:96ef0da3497866b726ac88928ed876d9647ca6a77b80d80f08513a8daaa38e07
3+
size 12251

test/test_requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
numpy
1+
numpy>=1.17.1
22
scikit-image
33
redis-py-cluster

test/tests_common.py

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,23 @@ def test_common_tensorset_error_replies(env):
6161
except Exception as e:
6262
exception = e
6363
env.assertEqual(type(exception), redis.exceptions.ResponseError)
64-
env.assertEqual(exception.__str__(), "negative value found in tensor shape")
64+
env.assertEqual("negative value found in tensor shape",exception.__str__())
6565

66-
# ERR unsupported data format
66+
# ERR invalid argument found in tensor shape
6767
try:
6868
con.execute_command('AI.TENSORSET', 'z', 'INT32', 2, 'unsupported', 2, 3)
6969
except Exception as e:
7070
exception = e
7171
env.assertEqual(type(exception), redis.exceptions.ResponseError)
72-
env.assertEqual(exception.__str__(), "invalid argument found in tensor shape")
72+
env.assertEqual("invalid argument found in tensor shape",exception.__str__())
7373

7474
# ERR invalid value
7575
try:
7676
con.execute_command('AI.TENSORSET', 'z', 'FLOAT', 2, 'VALUES', 2, 'A')
7777
except Exception as e:
7878
exception = e
7979
env.assertEqual(type(exception), redis.exceptions.ResponseError)
80-
env.assertEqual(exception.__str__(), "invalid value")
80+
env.assertEqual("invalid value",exception.__str__())
8181

8282
# ERR invalid value
8383
try:
@@ -198,14 +198,14 @@ def test_common_tensorget_error_replies(env):
198198
env.assertEqual(exception.__str__(), "WRONGTYPE Operation against a key holding the wrong kind of value")
199199

200200
# ERR unsupported data format
201+
ret = con.execute_command('AI.TENSORSET', "T_FLOAT", "FLOAT", 2, 'VALUES', 1, 1)
202+
env.assertEqual(ret, b'OK')
201203
try:
202-
ret = con.execute_command('AI.TENSORSET', "T_FLOAT", "FLOAT", 2, 'VALUES', 1, 1)
203-
env.assertEqual(ret, b'OK')
204204
con.execute_command('AI.TENSORGET', 'T_FLOAT', 'unsupported')
205205
except Exception as e:
206206
exception = e
207207
env.assertEqual(type(exception), redis.exceptions.ResponseError)
208-
env.assertEqual(exception.__str__(), "unsupported data format")
208+
env.assertEqual("unsupported data format",exception.__str__())
209209

210210

211211
def test_common_tensorset_multiproc(env):
@@ -219,6 +219,38 @@ def test_common_tensorset_multiproc(env):
219219
env.assertEqual(values, [b'2', b'3'])
220220

221221

222+
def test_common_tensorset_multiproc_blob(env):
223+
con = env.getConnection()
224+
tested_datatypes = ["FLOAT", "DOUBLE", "INT8", "INT16", "INT32", "INT64", "UINT8", "UINT16"]
225+
tested_datatypes_map = {}
226+
for datatype in tested_datatypes:
227+
ret = con.execute_command('AI.TENSORSET', 'tensor_{0}'.format(datatype), datatype, 1, 256)
228+
env.assertEqual(ret, b'OK')
229+
230+
ensureSlaveSynced(con, env)
231+
232+
# AI.TENSORGET in BLOB format and set in a new key
233+
for datatype in tested_datatypes:
234+
tensor_dtype, tensor_dim, tensor_blob = con.execute_command('AI.TENSORGET', 'tensor_{0}'.format(datatype),
235+
'BLOB')
236+
ret = con.execute_command('AI.TENSORSET', 'tensor_blob_{0}'.format(datatype), datatype, 1, 256, 'BLOB', tensor_blob)
237+
tested_datatypes_map[datatype]=tensor_blob
238+
env.assertEqual(ret, b'OK')
239+
240+
def funcname(env, blob, repetitions, same_key):
241+
for _ in range(1,same_key):
242+
for repetion in range(1,repetitions):
243+
env.execute_command('AI.TENSORSET', 'tensor_{0}'.format(repetitions), 'FLOAT', 1, 256, 'BLOB', blob)
244+
245+
tensor_blob = tested_datatypes_map["FLOAT"]
246+
t = time.time()
247+
run_test_multiproc(env, 10,
248+
lambda env: funcname(env,tensor_blob,10000,10) )
249+
elapsed_time = time.time() - t
250+
avg_ops_sec = 100000*10/elapsed_time
251+
env.debugPrint("AI.TENSORSET elapsed time(sec) {:6.2f}\tAvg. ops/sec {:10.2f}".format(elapsed_time, avg_ops_sec), True)
252+
253+
222254
def test_tensorset_disconnect(env):
223255
red = env.getConnection()
224256
ret = send_and_disconnect(('AI.TENSORSET', 't_FLOAT', 'FLOAT', 2, 'VALUES', 2, 3), red)

test/tests_tensorflow.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ def test_tensorflow_modelrun_disconnect(env):
605605

606606

607607
@skip_if_no_TF
608-
def test_with_batch_and_minbatch(env):
608+
def test_tensorflow_modelrun_with_batch_and_minbatch(env):
609609
con = env.getConnection()
610610
batch_size = 2
611611
minbatch_size = 2
@@ -663,4 +663,36 @@ def run(name=model_name, output_name='output'):
663663

664664
p3.terminate()
665665

666+
@skip_if_no_TF
667+
def test_tensorflow_modelrun_financialNet(env):
668+
con = env.getConnection()
669+
670+
model_pb, creditcard_transactions, creditcard_referencedata = load_creditcardfraud_data(env)
671+
672+
tensor_number = 1
673+
for transaction_tensor in creditcard_transactions:
674+
ret = con.execute_command('AI.TENSORSET', 'transactionTensor:{0}'.format(tensor_number),
675+
'FLOAT', 1, 30,
676+
'BLOB', transaction_tensor.tobytes())
677+
env.assertEqual(ret, b'OK')
678+
tensor_number = tensor_number + 1
679+
680+
tensor_number = 1
681+
for reference_tensor in creditcard_referencedata:
682+
ret = con.execute_command('AI.TENSORSET', 'referenceTensor:{0}'.format(tensor_number),
683+
'FLOAT', 1, 256,
684+
'BLOB', reference_tensor.tobytes())
685+
env.assertEqual(ret, b'OK')
686+
tensor_number = tensor_number + 1
687+
688+
ret = con.execute_command('AI.MODELSET', 'financialNet', 'TF', "CPU",
689+
'INPUTS', 'transaction', 'reference', 'OUTPUTS', 'output', model_pb)
690+
env.assertEqual(ret, b'OK')
666691

692+
for tensor_number in range(1, 10001):
693+
for repetition in range(0, 10):
694+
ret = con.execute_command('AI.MODELRUN', 'financialNet', 'INPUTS',
695+
'transactionTensor:{}'.format(tensor_number),
696+
'referenceTensor:{}'.format(tensor_number), 'OUTPUTS',
697+
'classificationTensor:{}_{}'.format(tensor_number, repetition))
698+
env.assertEqual(ret, b'OK')

0 commit comments

Comments
 (0)