diff --git a/c_reference/include/fastgrnn.h b/c_reference/include/fastgrnn.h index fbcf893b6..051f154a0 100644 --- a/c_reference/include/fastgrnn.h +++ b/c_reference/include/fastgrnn.h @@ -21,8 +21,8 @@ * @var uRank rank of U matrix * @var Bg pointer to bias for sigmoid * @var Bh pointer to bias for tanh - * @var zeta first weight parameter for update from input from next step - * @var nu second weight parameter for update from input from next step + * @var sigmoid_zeta first weight parameter for update from input from next step + * @var sigmoid_nu second weight parameter for update from input from next step */ typedef struct FastGRNN_LR_Params { float* mean; @@ -35,8 +35,8 @@ typedef struct FastGRNN_LR_Params { unsigned uRank; float* Bg; float* Bh; - float zeta; - float nu; + float sigmoid_zeta; + float sigmoid_nu; } FastGRNN_LR_Params; /** @@ -82,8 +82,8 @@ int fastgrnn_lr(float* const hiddenState, unsigned hiddenDims, * @var U pointer U matrix * @var Bg pointer to bias for sigmoid * @var Bh pointer to bias for tanh - * @var zeta first weight parameter for update from input from next step - * @var nu second weight parameter for update from input from next step + * @var sigmoid_zeta first weight parameter for update from input from next step + * @var sigmoid_nu second weight parameter for update from input from next step */ typedef struct FastGRNN_Params { float* mean; @@ -92,8 +92,8 @@ typedef struct FastGRNN_Params { float* U; float* Bg; float* Bh; - float zeta; - float nu; + float sigmoid_zeta; + float sigmoid_nu; } FastGRNN_Params; /** diff --git a/c_reference/include/utils.h b/c_reference/include/utils.h index 4c5eef5ac..26d5242ba 100644 --- a/c_reference/include/utils.h +++ b/c_reference/include/utils.h @@ -36,7 +36,7 @@ void v_add(float scalar1, const float* const vec1, float scalar2, const float* const vec2, unsigned len, float* const ret); -// point-wise vector division ret = vec2 / vec1 +// point-wise vector multiplication ret = vec2 * vec1 void v_mult(const float* const vec1, const float* const vec2, unsigned len, float* const ret); @@ -44,6 +44,10 @@ void v_mult(const float* const vec1, const float* const vec2, void v_div(const float* const vec1, const float* const vec2, unsigned len, float* const ret); +// Return squared Euclidean distance between vec1 and vec2 +float l2squared(const float* const vec1, + const float* const vec2, unsigned dim); + // Return index with max value, if tied, return first tied index. unsigned argmax(const float* const vec, unsigned len); diff --git a/c_reference/src/fastgrnn.c b/c_reference/src/fastgrnn.c index 8dfcc2f07..135e39150 100644 --- a/c_reference/src/fastgrnn.c +++ b/c_reference/src/fastgrnn.c @@ -19,7 +19,7 @@ int fastgrnn_lr(float* const hiddenState, unsigned hiddenDims, // #steps iterations of the RNN cell starting from hiddenState for (unsigned t = 0; t < steps; t++) { // Normalize the features - unsigned offset = backward ? steps - t : t; + unsigned offset = backward ? steps - 1 - t : t; if (normalize) { v_add(1.0f, input + offset * inputDims, -1.0f, tparams->mean + t * inputDims, inputDims, tbuffers->normFeatures); @@ -45,7 +45,7 @@ int fastgrnn_lr(float* const hiddenState, unsigned hiddenDims, for (unsigned i = 0; i < hiddenDims; i++) { float gate = sigmoid(tbuffers->preComp[i] + tparams->Bg[i]); float update = tanh(tbuffers->preComp[i] + tparams->Bh[i]); - hiddenState[i] = gate * hiddenState[i] + (tparams->zeta * (1.0 - gate) + tparams->nu) * update; + hiddenState[i] = gate * hiddenState[i] + (tparams->sigmoid_zeta * (1.0 - gate) + tparams->sigmoid_nu) * update; } } return 0; @@ -63,7 +63,7 @@ int fastgrnn(float* const hiddenState, unsigned hiddenDims, for (unsigned t = 0; t < steps; t++) { // Normalize the features - unsigned offset = backward ? steps - t : t; + unsigned offset = backward ? steps - 1 - t : t; if (normalize) { v_add(1.0f, input + offset * inputDims, -1.0f, tparams->mean + t * inputDims, inputDims, tbuffers->normFeatures); @@ -86,7 +86,7 @@ int fastgrnn(float* const hiddenState, unsigned hiddenDims, for (unsigned i = 0; i < hiddenDims; i++) { float gate = sigmoid(tbuffers->preComp[i] + tparams->Bg[i]); float update = tanh(tbuffers->preComp[i] + tparams->Bh[i]); - hiddenState[i] = gate * hiddenState[i] + (tparams->zeta * (1.0 - gate) + tparams->nu) * update; + hiddenState[i] = gate * hiddenState[i] + (tparams->sigmoid_zeta * (1.0 - gate) + tparams->sigmoid_nu) * update; } } return 0; diff --git a/c_reference/src/utils.c b/c_reference/src/utils.c index 880cb0068..dc58a5fa0 100644 --- a/c_reference/src/utils.c +++ b/c_reference/src/utils.c @@ -90,6 +90,14 @@ void v_div(const float* const vec1, const float* const vec2, ret[i] = vec2[i] / vec1[i]; } +float l2squared(const float* const vec1, + const float* const vec2, unsigned dim) { + float sum = 0.0f; + for (unsigned i = 0; i < dim; i++) + sum += (vec1[i] - vec2[i]) * (vec1[i] - vec2[i]); + return sum; +} + unsigned argmax(const float* const vec, unsigned len) { unsigned maxId = 0; float maxScore = FLT_MIN; diff --git a/c_reference/tests/Makefile b/c_reference/tests/Makefile index ef6c5e395..10486f9b9 100644 --- a/c_reference/tests/Makefile +++ b/c_reference/tests/Makefile @@ -7,7 +7,7 @@ INCLUDE_DIR=../include SRC_DIR=../src IFLAGS = -I $(INCLUDE_DIR) -all: test_fastgrnn_lr test_rnnpool +all: test_fastgrnn_lr test_rnnpool test_rnnpool_face FASTGRNN_DIR=fastgrnn test_fastgrnn_lr: $(FASTGRNN_DIR)/test_fastgrnn_lr.c $(SRC_DIR)/utils.o $(SRC_DIR)/fastgrnn.o $(SRC_DIR)/classifier.o @@ -17,6 +17,9 @@ RNNPOOL_DIR=rnnpool test_rnnpool: $(RNNPOOL_DIR)/test_rnnpool.c $(SRC_DIR)/utils.o $(SRC_DIR)/fastgrnn.o $(SRC_DIR)/rnnpool.o $(CC) -o $@ $^ $(IFLAGS) $(CFLAGS) -lm +test_rnnpool_face: $(RNNPOOL_DIR)/test_rnnpool_face.c $(SRC_DIR)/utils.o $(SRC_DIR)/fastgrnn.o $(SRC_DIR)/rnnpool.o + $(CC) -o $@ $^ $(IFLAGS) $(CFLAGS) -lm + .PHONY: clean cleanest diff --git a/c_reference/tests/converters/ConvertNumpytoHeaderFilesRNNPool.py b/c_reference/tests/converters/ConvertNumpytoHeaderFilesRNNPool.py new file mode 100644 index 000000000..906fedc24 --- /dev/null +++ b/c_reference/tests/converters/ConvertNumpytoHeaderFilesRNNPool.py @@ -0,0 +1,189 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT license. + +import numpy as np +import argparse +import os +import sys + +def sigmoid(x): + return 1.0 / (1.0 + np.exp(-x)) + +def saveTraces(tracesInputDir, tracesOutputDir): + if os.path.isdir(tracesOutputDir) is False: + try: + os.mkdir(tracesOutputDir) + except OSError: + print("Creation of the directory %s failed" % tracesOutputDir) + return + input_files = os.listdir(tracesInputDir+'/inputs/') + + for file in input_files: + trace_input = np.load(tracesInputDir + "/inputs/" + file) + trace_output = np.load(tracesInputDir + "/outputs/" + file) + + inputDims = trace_input.shape[-1] + patchDim = trace_input.shape[-2] + hiddenDims2 = int(trace_output.shape[0]/4) + + f_input = open(tracesOutputDir+'/'+str(file)[:-4]+'_input.h','w') + f_output = open(tracesOutputDir+'/'+str(file)[:-4]+'_output.h','w') + f_input.write('#define INPUT_DIMS '+str(inputDims)+'\n#define PATCH_DIM '+ str(patchDim)+'\n\n') + f_output.write('#define HIDDEN_DIMS2 '+str(hiddenDims2)+'\n\n') + + f_input.write('static float input[INPUT_DIMS * PATCH_DIM * PATCH_DIM] = ' + convertMatrixToVecString(trace_input) + ';') + f_output.write('static float output[4 * HIDDEN_DIMS2] = ' + convertMatrixToVecString(trace_output) + ';') + + f_input.flush() + f_input.close() + f_output.flush() + f_output.close() + + + + +def loadModel(modelDir): + model = { + "W1": np.transpose(np.load(modelDir + "/W1.npy")), + "W2": np.transpose(np.load(modelDir + "/W2.npy")), + "U1": np.transpose(np.load(modelDir + "/U1.npy")), + "U2": np.transpose(np.load(modelDir + "/U2.npy")), + "Bg1": np.load(modelDir + "/Bg1.npy"), + "Bh1": np.load(modelDir + "/Bh1.npy"), + "Bg2": np.load(modelDir + "/Bg2.npy"), + "Bh2": np.load(modelDir + "/Bh2.npy"), + "zeta1": sigmoid(np.load(modelDir + "/zeta1.npy")), + "nu1": sigmoid(np.load(modelDir + "/nu1.npy")), + "zeta2": sigmoid(np.load(modelDir + "/zeta2.npy")), + "nu2": sigmoid(np.load(modelDir + "/nu2.npy")), + } + + return model + + +def getArgs(): + ''' + Function to parse arguments for FastCells + ''' + parser = argparse.ArgumentParser( + description='HyperParams for RNNPool inference') + + parser.add_argument('-mdir', '--model-dir', required=False, default=None, + help='Model directory containing' + + 'RNNPool model') + + parser.add_argument('-tidir', '--trace-input-dir', required=False, default=None, + help='Directory containing RnnPool input output numpy traces') + + parser.add_argument('-todir', '--trace-output-dir', required=False, default=None, + help='Output Directory for saving RnnPool input output .h traces') + + parser.add_argument('-rnn1oF', '--rnn1-out-file', default=None, + help='Give a output header file name for the model to dump rnn1 weights' + + 'default: stdout') + + parser.add_argument('-rnn2oF', '--rnn2-out-file', default=None, + help='Give a output header file name for the model to dump rnn2 weights' + + 'default: stdout') + + + return parser.parse_args() + + +def saveReadableModel(modelDir, model): + if os.path.isdir(modelDir + '/ReadableModel') is False: + try: + os.mkdir(modelDir + '/ReadableModel') + except OSError: + print("Creation of the directory %s failed" % + modelDir + '/ReadableModel') + currDir = modelDir + '/ReadableModel' + + np.savetxt(currDir + "/W1.txt", + np.reshape(model["W1"], [1, -1]), delimiter=',') + np.savetxt(currDir + "/W2.txt", + np.reshape(model["W2"], [1, -1]), delimiter=',') + np.savetxt(currDir + "/U1.txt", + np.reshape(model["U1"], [1, -1]), delimiter=',') + np.savetxt(currDir + "/U2.txt", + np.reshape(model["U2"], [1, -1]), delimiter=',') + np.savetxt(currDir + "/Bg1.txt", + np.reshape(model["Bg1"], [1, -1]), delimiter=',') + np.savetxt(currDir + "/Bh1.txt", + np.reshape(model["Bh1"], [1, -1]), delimiter=',') + np.savetxt(currDir + "/Bg2.txt", + np.reshape(model["Bg2"], [1, -1]), delimiter=',') + np.savetxt(currDir + "/Bh2.txt", + np.reshape(model["Bh2"], [1, -1]), delimiter=',') + np.savetxt(currDir + "/zeta1.txt", + np.reshape(model["zeta1"], [1, -1]), delimiter=',') + np.savetxt(currDir + "/nu1.txt", + np.reshape(model["nu1"], [1, -1]), delimiter=',') + np.savetxt(currDir + "/zeta2.txt", + np.reshape(model["zeta2"], [1, -1]), delimiter=',') + np.savetxt(currDir + "/nu2.txt", + np.reshape(model["nu2"], [1, -1]), delimiter=',') + + return currDir + + +def convertMatrixToVecString(mat): + mat = str(np.reshape(mat, [1, -1])[0, :].tolist()) + mat = '{' + mat[1:-1] + '}' + return mat + + +def saveModelHeader(rnn1OutFile, rnn2OutFile, model): + rnn1OutFile = open(rnn1OutFile, 'w') + rnn2OutFile = open(rnn2OutFile, 'w') + + print ("#define HIDDEN_DIMS1 8\n", file=rnn1OutFile) + + print("static float W1[INPUT_DIMS * HIDDEN_DIMS1] = " + convertMatrixToVecString(model['W1']) + ";", file=rnn1OutFile) + + print("static float U1[HIDDEN_DIMS1 * HIDDEN_DIMS1] = " + convertMatrixToVecString(model['U1']) + ";", file=rnn1OutFile) + + print("static float Bg1[HIDDEN_DIMS1] = " + convertMatrixToVecString(model['Bg1']) + ";", file=rnn1OutFile) + print("static float Bh1[HIDDEN_DIMS1] = " + + convertMatrixToVecString(model['Bh1']) + ";\n", file=rnn1OutFile) + + print("static float sigmoid_zeta1 = " + str(model['zeta1'][0][0]) + ";", file=rnn1OutFile) + print("static float sigmoid_nu1 = " + str(model['nu1'][0][0]) + ";\n", file=rnn1OutFile) + + + print("static float W2[HIDDEN_DIMS1 * HIDDEN_DIMS2] = " + convertMatrixToVecString(model['W2']) + ";", file=rnn2OutFile) + + print("static float U2[HIDDEN_DIMS2 * HIDDEN_DIMS2] = " + convertMatrixToVecString(model['U2']) + ";\n", file=rnn2OutFile) + + print("static float Bg2[HIDDEN_DIMS2] = " + convertMatrixToVecString(model['Bg2']) + ";", file=rnn2OutFile) + print("static float Bh2[HIDDEN_DIMS2] = " + + convertMatrixToVecString(model['Bh2']) + ";\n", file=rnn2OutFile) + + print("static float sigmoid_zeta2 = " + str(model['zeta2'][0][0]) + ";", file=rnn2OutFile) + print("static float sigmoid_nu2 = " + str(model['nu2'][0][0]) + ";\n", file=rnn2OutFile) + + + rnn1OutFile.flush() + rnn1OutFile.close() + rnn2OutFile.flush() + rnn2OutFile.close() + + +def main(): + args = getArgs() + + if args.model_dir is not None: + model = loadModel(args.model_dir) + currDir = saveReadableModel(args.model_dir, model) + if args.rnn1_out_file is not None and args.rnn2_out_file is not None: + saveModelHeader(args.rnn1_out_file, args.rnn2_out_file, model) + else: + print('Not saving output header files as names are not specified') + + + if args.trace_input_dir is not None and args.trace_output_dir is not None: + saveTraces(args.trace_input_dir, args.trace_output_dir) + + + +main() \ No newline at end of file diff --git a/c_reference/tests/converters/README.md b/c_reference/tests/converters/README.md new file mode 100644 index 000000000..135903c48 --- /dev/null +++ b/c_reference/tests/converters/README.md @@ -0,0 +1,19 @@ +# Code for Converting Numpy Model Weights/Traces to Header Files + + +## RNNPool + +Specify the path to model weights saved in numpy format in and path to input output traces saved in numpy format in . Specify folder to save converted header files for first rnn (which does the row-wise/column-wise traversal) of RNNPool in and that of second rnn (which does the bidirectional summarization of outputs of first rnn pass) in . + +```shell + +python3 ConvertNumpytoHeaderFilesRNNPool.py --model-dir -tidir -todir -rnn1oF -rnn2oF + +``` + +eg. +```shell + +python3 ConvertNumpytoHeaderFilesRNNPool.py --model-dir ./model_weights_face -tidir ./model_traces_face -todir ./traces_headers -rnn1oF rnn1.h -rnn2oF rnn2.h + +``` \ No newline at end of file diff --git a/c_reference/tests/fastgrnn/test_fastgrnn_lr.c b/c_reference/tests/fastgrnn/test_fastgrnn_lr.c index ebee68d26..0c04d41b7 100644 --- a/c_reference/tests/fastgrnn/test_fastgrnn_lr.c +++ b/c_reference/tests/fastgrnn/test_fastgrnn_lr.c @@ -32,8 +32,8 @@ static float USPS_U2[USPS_URANK * HIDDEN_DIMS] = { -1.1701158285140991, -0.15880 static float USPS_Bg[HIDDEN_DIMS] = { 4.59620475769043, 0.1966695934534073, 1.9611409902572632, 3.5603864192962646, 4.187475204467773, 4.361924648284912, 0.3600460886955261, 1.3823245763778687, -0.677017092704773, 4.105582237243652, 5.264251232147217, -0.5598424077033997, 5.148655414581299, 2.0772266387939453, 4.553979873657227, 5.08613920211792, 4.782368183135986, 0.7364211678504944, 5.434220314025879, 3.580031394958496, 3.1102733612060547, -0.7808840870857239, 0.7291825413703918, 4.574047565460205, 3.3059921264648438, 0.3563838303089142, 2.718221664428711, 3.580395460128784, 3.4779181480407715, 2.5830607414245605, 2.9951508045196533, 0.9241535663604736 }; static float USPS_Bh[HIDDEN_DIMS] = { 0.4606550931930542, 0.790073573589325, -0.017053354531526566, 0.9936599731445312, 1.7931172847747803, 1.5456229448318481, 1.1712238788604736, 0.25801223516464233, 0.31747567653656006, 0.19287768006324768, 2.0994107723236084, 1.0495734214782715, 1.4762489795684814, 1.309980034828186, 0.3596293032169342, 1.5582088232040405, 0.40993940830230713, 1.8783470392227173, 1.493168830871582, -0.24529218673706055, 1.1273030042648315, 0.2839592695236206, 1.9818940162658691, 1.6705248355865479, 0.6683108806610107, 1.1119632720947266, 1.71348237991333, 2.004892110824585, 2.6525025367736816, 1.5513267517089844, 1.5202845335006714, -0.5777350068092346 }; -static float USPS_zeta = 0.8710977; -static float USPS_nu = 0.077582605; +static float USPS_sigmoid_zeta = 0.8710977; +static float USPS_sigmoid_nu = 0.077582605; static float FC_weights[HIDDEN_DIMS * NUM_CLASSES] = { -0.24747183918952942, -0.055960506200790405, 1.3475773334503174, -0.2660730183124542, 0.08773329854011536, 2.71574068069458, -1.4928890466690063, 1.5905754566192627, 1.4361884593963623, 1.3066115379333496, -0.41571110486984253, 0.9617563486099243, 0.40012961626052856, 0.8696961998939514, -1.6383168697357178, 0.7999024391174316, -0.16858834028244019, -1.0727401971817017, 0.7396827340126038, 0.3806271553039551, -0.8257421255111694, 0.1623869240283966, -0.39433446526527405, -3.482332468032837, -0.08032357692718506, 0.994373083114624, 0.9860239028930664, -5.6317973136901855, -3.062581777572632, -3.2377049922943115, -1.088222861289978, 0.7581420540809631, -0.1045861691236496, 1.0123625993728638, 2.7781565189361572, 4.226351737976074, -0.4395594894886017, -1.9928295612335205, -0.03426577150821686, 0.2318461388349533, -3.200232982635498, 0.7830891013145447, -2.003850221633911, -1.0072307586669922, -0.09394438564777374, -0.402126282453537, 2.8108479976654053, 0.027125360444188118, 1.893704891204834, -0.03775143623352051, 0.6053617596626282, 0.3430182933807373, -3.2976200580596924, -1.1353939771652222, 0.024645693600177765, 0.3784751296043396, 1.4342879056930542, -0.7492150664329529, -1.0270135402679443, 2.5554628372192383, 0.6594746112823486, 0.7780766487121582, 0.8985974788665771, -0.0034258293453603983, 0.21751202642917633, -2.3399763107299805, 1.1613740921020508, -1.447609305381775, -1.3636846542358398, 1.7248963117599487, -0.3620492219924927, -2.375091075897217, -1.3364042043685913, 1.359509825706482, -2.648242235183716, 1.4566280841827393, 0.6185098886489868, 0.9421749711036682, -1.8496538400650024, -1.3294904232025146, -0.565808892250061, -1.6445082426071167, 1.2565573453903198, 2.4306249618530273, -1.6949048042297363, 2.2069883346557617, 1.103385329246521, -0.9351933598518372, -0.824954628944397, -0.7599087953567505, -0.6911792755126953, 2.7740914821624756, 1.6341619491577148, 1.849193811416626, 1.146787166595459, -1.4661681652069092, 2.0738017559051514, -1.9961793422698975, -1.1605796813964844, 0.9941896200180054, 0.3308192789554596, 2.13922119140625, -0.17217597365379333, -0.9082329869270325, 0.7720779180526733, -1.0596287250518799, 1.586103081703186, -2.9859485626220703, 1.55707585811615, 1.1488341093063354, -3.2394535541534424, 1.169393539428711, -0.13278652727603912, 1.6355780363082886, -0.1245696097612381, 1.808440923690796, -1.1002291440963745, -0.3053940534591675, 1.6078038215637207, 3.8395557403564453, 0.019826073199510574, -0.3926658034324646, -1.9981871843338013, -0.6696834564208984, 0.08870892226696014, 1.6605280637741089, 0.5209671854972839, -2.3854024410247803, 1.5786619186401367, 1.8952832221984863, -1.304535150527954, 0.2743481695652008, 2.8763298988342285, -0.6256309747695923, 3.8730015754699707, -0.32314497232437134, -0.6618545651435852, -3.0481762886047363, -2.8654234409332275, -0.8415182828903198, -1.3170037269592285, 1.3599309921264648, 1.2142889499664307, 0.07019823044538498, -0.5422642827033997, 0.23863810300827026, 3.584157943725586, 0.7111842036247253, 0.9668632745742798, 1.3011258840560913, -0.003976037260144949, 1.7265373468399048, -0.48193755745887756, 0.463483989238739, -0.3804154098033905, 2.4481565952301025, -1.081111192703247, 1.9583369493484497, -3.963627338409424, 0.729573667049408, -0.4898405373096466, -0.5738614201545715, -1.7461729049682617, -1.8392359018325806, -0.4148902893066406, -1.158633828163147, -1.6964939832687378, 0.5787208080291748, 1.4248132705688477, -0.4257330894470215, 3.0490269660949707, -1.1780657768249512, 1.0951701402664185, 0.8462642431259155, 0.9555350542068481, 2.9707250595092773, -1.3199042081832886, 1.8216924667358398, -0.6233108639717102, 1.5412005186080933, 0.334654837846756, 0.2763754725456238, 1.3666235208511353, 1.851394534111023, -1.7485069036483765, 1.0322270393371582, -1.8656693696975708, -1.1901252269744873, 1.0325310230255127, -0.8999790549278259, 0.22713708877563477, -3.3022899627685547, -2.718987464904785, 0.6280394792556763, 0.7579594254493713, -2.2618398666381836, -1.1550352573394775, 1.0463181734085083, -0.2427310198545456, -0.1560579091310501, -0.19294323027133942, 0.3897946774959564, -1.5712190866470337, 1.0458306074142456, -0.7470991015434265, 1.2837566137313843, 2.3155717849731445, 2.0378687381744385, 0.7463016510009766, 1.3255469799041748, -1.7185251712799072, -0.1644330620765686, 2.248473882675171, -0.05582746863365173, -0.39194202423095703, -1.050262212753296, 1.1556638479232788, 0.03496933728456497, 1.5286030769348145, 0.01176676619797945, -1.1746597290039062, -0.038728803396224976, -0.3821633458137512, 0.9377774596214294, -0.3956509530544281, 1.074571967124939, -1.6802961826324463, -0.3645908534526825, -1.4564014673233032, 0.6331769227981567, 2.4816489219665527, 0.32858720421791077, 1.5533283948898315, 1.6947213411331177, 0.3252701461315155, 3.2225258350372314, 1.1926754713058472, 0.3901558518409729, -0.8612796664237976, -4.8346662521362305, -1.9908527135849, 0.7937301993370056, -1.5082682371139526, 0.4805694818496704, -1.419480323791504, 0.157501682639122, 2.0960652828216553, 0.005156002938747406, -2.6489176750183105, 1.263648271560669, -1.3384476900100708, 1.4031224250793457, 0.4655438959598541, 1.8326048851013184, 3.110736131668091, 0.26125067472457886, 2.7024500370025635, -0.9119302034378052, -0.6820136308670044, 3.8541572093963623, -1.3096107244491577, 1.7389343976974487, 2.067892551422119, 1.1543680429458618, 0.03984083607792854, 0.6176361441612244, -0.8746475577354431, 0.40996477007865906, -2.3278424739837646, 0.5317244529724121, -1.1554235219955444, 0.8648607730865479, 0.5743665099143982, 0.9955512881278992, 0.8316799998283386, -1.9429028034210205, 0.6146461367607117, -4.532263278961182, -0.8694373965263367, -0.31155335903167725, -0.030860910192131996, 1.173535704612732, 0.8387981057167053, -1.3379566669464111, 1.902561902999878, 2.197434663772583, 1.3871995210647583, -1.6537810564041138, -2.7861647605895996, -0.005632062442600727, -2.181979179382324, 2.3240818977355957, 0.914097785949707, 0.10216601192951202, 2.52095103263855, 0.6039048433303833, -1.1367847919464111, -2.309983015060425, 2.7826766967773438, -0.6315389275550842, -3.811366319656372, 2.09122633934021, -0.6774390339851379, -0.9190919995307922, 0.9899649620056152, 1.0903472900390625, -0.7736498713493347, -1.3925520181655884, 0.6861974596977234, 3.141139268875122, 0.7085739970207214, 0.35131436586380005, 1.6807632446289062, 1.0083352327346802, -0.38794782757759094, -1.839680790901184, -0.7718075513839722, 0.41827693581581116, 1.8001973628997803, 1.2126221656799316 }; static float FCbias[NUM_CLASSES] = { 0.7145490646362305, 0.2392704039812088, 0.7243489027023315, -0.3943518102169037, -0.7943000793457031, 0.18482555449008942, 0.29146698117256165, -0.04441819712519646, 1.5886560678482056, -0.8504140377044678 }; @@ -70,8 +70,8 @@ int main() { .uRank = USPS_URANK, .Bg = USPS_Bg, .Bh = USPS_Bh, - .zeta = USPS_zeta, - .nu = USPS_nu + .sigmoid_zeta = USPS_sigmoid_zeta, + .sigmoid_nu = USPS_sigmoid_nu }; float preComp[HIDDEN_DIMS] = { 0.0 }; diff --git a/c_reference/tests/rnnpool/face_model/rnn1.h b/c_reference/tests/rnnpool/face_model/rnn1.h new file mode 100644 index 000000000..cc258c3da --- /dev/null +++ b/c_reference/tests/rnnpool/face_model/rnn1.h @@ -0,0 +1,10 @@ +#define HIDDEN_DIMS1 8 + +static float W1[INPUT_DIMS * HIDDEN_DIMS1] = {0.05728379637002945, -0.017023758962750435, 0.25396355986595154, -0.5767111778259277, 0.0729413703083992, -0.06401490420103073, 0.016082603484392166, -0.17516161501407623, -0.9113835096359253, -0.3674522042274475, 0.10634513199329376, 0.36516982316970825, -0.31638288497924805, 0.48142242431640625, 0.052355583757162094, -0.2822858393192291, 0.020806409418582916, 0.08521196246147156, 0.05745209380984306, -0.12961868941783905, 0.646435022354126, 0.37815287709236145, -0.16816243529319763, -0.561792254447937, -0.08903513103723526, 0.17326748371124268, 0.23540081083774567, 0.18699470162391663, 0.7498922348022461, -0.6905604600906372, -0.10880530625581741, 0.15561559796333313}; +static float U1[HIDDEN_DIMS1 * HIDDEN_DIMS1] = {0.0885470062494278, 0.10189718753099442, 0.011457864195108414, -0.0054266913793981075, -0.11213689297437668, 0.055597949773073196, 0.023726800456643105, -0.04273271933197975, -0.646082878112793, 0.23134475946426392, -0.5081114768981934, 0.7146762609481812, -0.5283030271530151, 0.3773706555366516, 0.2069741189479828, 0.11082419008016586, 0.38814792037010193, 0.2782214879989624, -0.10075654089450836, -0.2194112241268158, 0.420135498046875, 0.3382737636566162, -0.10525326430797577, -0.15444065630435944, -0.09867070615291595, 0.03839907795190811, 0.14474035799503326, 0.1666630655527115, -0.06800684332847595, -0.11181867122650146, -0.06382069736719131, -0.03409789502620697, 0.02659057267010212, 0.21766456961631775, -0.057335011661052704, -0.10353385657072067, 0.03269200772047043, 0.018621621653437614, -0.18908125162124634, 0.3619883954524994, -0.6322037577629089, -0.1528451144695282, 0.5752084255218506, -0.26842501759529114, -0.3435758948326111, -0.05781722441315651, -0.14717720448970795, -0.013333129696547985, 0.095060795545578, -0.21655549108982086, 0.5354421138763428, 0.15595898032188416, -0.5853599905967712, 0.21818533539772034, 0.07148981094360352, 0.2145569622516632, -0.2858271598815918, -0.29919153451919556, -0.0278799906373024, 1.235137939453125, -0.17514251172542572, -0.03214624151587486, 0.08009274303913116, 0.03380195423960686}; +static float Bg1[HIDDEN_DIMS1] = {0.08699623495340347, 0.10146532207727432, 0.1157333254814148, -0.5457881689071655, -0.12949803471565247, -0.0922124832868576, 0.05129539594054222, 0.20176301896572113}; +static float Bh1[HIDDEN_DIMS1] = {0.529672384262085, 0.2443077713251114, 0.6968744993209839, 0.3934999406337738, 1.0972073078155518, 0.4284772276878357, 0.2538343369960785, 0.29379019141197205}; + +static float sigmoid_zeta1 = 1.0; +static float sigmoid_nu1 = 2.6489594e-30; + diff --git a/c_reference/tests/rnnpool/face_model/rnn2.h b/c_reference/tests/rnnpool/face_model/rnn2.h new file mode 100644 index 000000000..12115e64b --- /dev/null +++ b/c_reference/tests/rnnpool/face_model/rnn2.h @@ -0,0 +1,9 @@ +static float W2[HIDDEN_DIMS1 * HIDDEN_DIMS2] = {-0.27843931317329407, 0.7430717945098877, -0.0653676837682724, 0.0661972314119339, -0.5902142524719238, 0.13223540782928467, 0.19362707436084747, -0.4009245038032532, -0.1389789581298828, -0.21446110308170319, -0.23559026420116425, 0.39521726965904236, -0.5871433615684509, -0.40856194496154785, -0.48501619696617126, -0.02906256541609764, 0.508455216884613, -0.8196758031845093, 0.12408386170864105, -0.21606920659542084, -0.6777727007865906, 0.018213029950857162, -0.19179263710975647, 0.03546636179089546, 0.05343775078654289, 0.11252386122941971, -0.12614335119724274, -0.034954532980918884, -0.3433290421962738, -0.02379862777888775, -0.15605230629444122, -0.6679574847221375, 0.1207231655716896, 0.05915882810950279, -0.11480199545621872, 0.07342526316642761, -0.21928471326828003, -0.03171790391206741, -0.10479358583688736, -0.2953641712665558, 0.2769709527492523, -0.1657114028930664, -0.2848057448863983, -0.30946552753448486, -0.13970626890659332, -0.2841068506240845, -0.6684054732322693, -0.29907721281051636, -0.6760978102684021, -0.33453479409217834, 0.11317259073257446, -0.12374911457300186, -0.6061263680458069, 0.030005907639861107, -0.09125818312168121, 0.14368315041065216, -0.03244452923536301, 0.2922135591506958, -0.08628516644239426, 0.41961148381233215, -0.5010040402412415, -0.39320141077041626, 0.44576042890548706, 0.11532633751630783}; +static float U2[HIDDEN_DIMS2 * HIDDEN_DIMS2] = {0.11734726279973984, 0.38112249970436096, 0.7858313918113708, 0.07527834177017212, -0.25792068243026733, 0.15327812731266022, -0.07941184192895889, 0.012267069891095161, -0.09274256229400635, 0.36783820390701294, 0.3409440815448761, -0.0008370502619072795, -0.12084104120731354, 0.11360836029052734, -0.05575798079371452, 0.03235398605465889, 0.08827289938926697, -0.328266978263855, -0.0290474034845829, -0.040406424552202225, 0.3042513132095337, 0.08566228300333023, 0.15502256155014038, 0.0895792543888092, 0.14711031317710876, -0.035015176981687546, -0.19980542361736298, 0.27223655581474304, 0.21671053767204285, 0.14100730419158936, -0.4369487762451172, -0.2991533577442169, -0.12695346772670746, 0.06976692378520966, -0.8318540453910828, -0.11838176846504211, 0.27047157287597656, -0.4010297656059265, -0.11338013410568237, 0.24676059186458588, -0.022850319743156433, 0.036909811198711395, -0.2776567339897156, -0.01747751794755459, -0.03485561162233353, 0.19962218403816223, 0.09315236657857895, -0.09986457973718643, -0.05474138259887695, 0.09654474258422852, -0.15123814344406128, 0.18227840960025787, -0.029120849445462227, -0.23944710195064545, 0.21565955877304077, 0.10081177204847336, -0.0407288521528244, 0.27885398268699646, 0.2105490118265152, 0.27249160408973694, -0.14735695719718933, 0.23237888514995575, -0.3467356562614441, -0.11808214336633682}; + +static float Bg2[HIDDEN_DIMS2] = {-0.009815464727580547, 0.1790345311164856, 0.15949344635009766, 0.07449029386043549, 0.2533033490180969, -0.015116404742002487, 0.13510125875473022, 0.3280749022960663}; +static float Bh2[HIDDEN_DIMS2] = {0.5673038363456726, 0.7345506548881531, 0.699255108833313, 0.8589223027229309, 0.8605647683143616, 0.9171470403671265, 0.7011861205101013, 0.4001118838787079}; + +static float sigmoid_zeta2 = 1.0; +static float sigmoid_nu2 = 2.6489594e-30; + diff --git a/c_reference/tests/rnnpool/test_rnnpool.c b/c_reference/tests/rnnpool/test_rnnpool.c index f5b4f4b10..5e4f5f11f 100644 --- a/c_reference/tests/rnnpool/test_rnnpool.c +++ b/c_reference/tests/rnnpool/test_rnnpool.c @@ -16,51 +16,53 @@ int main() { FastGRNN_Params rnn1_params = { - .mean = mean1, - .stdDev = stdDev1, + .mean = NULL, + .stdDev = NULL, .W = W1, .U = U1, .Bg = Bg1, .Bh = Bh1, - .zeta = zeta1, - .nu = nu1 + .sigmoid_zeta = sigmoid_zeta1, + .sigmoid_nu = sigmoid_nu1 }; FastGRNN_Params rnn2_params = { - .mean = mean2, - .stdDev = stdDev2, + .mean = NULL, + .stdDev = NULL, .W = W2, .U = U2, .Bg = Bg2, .Bh = Bh2, - .zeta = zeta2, - .nu = nu2 + .sigmoid_zeta = sigmoid_zeta2, + .sigmoid_nu = sigmoid_nu2 }; - float preComp1[HIDDEN_DIMS1] = { 0.0f }; - float normFeatures1[INPUT_DIMS] = { 0.0f }; + float preComp1[HIDDEN_DIMS1]; + float normFeatures1[INPUT_DIMS]; + memset(preComp1, 0, sizeof(float) * HIDDEN_DIMS1); + memset(normFeatures1, 0, sizeof(float) * INPUT_DIMS); FastGRNN_Buffers rnn1_buffers = { .preComp = preComp1, .normFeatures = normFeatures1 }; - float preComp2[HIDDEN_DIMS2] = { 0.0f }; - float normFeatures2[HIDDEN_DIMS1] = { 0.0f }; + float preComp2[HIDDEN_DIMS2]; + float normFeatures2[HIDDEN_DIMS1]; + memset(preComp2, 0, sizeof(float) * HIDDEN_DIMS2); + memset(normFeatures2, 0, sizeof(float) * HIDDEN_DIMS1); FastGRNN_Buffers rnn2_buffers = { .preComp = preComp2, .normFeatures = normFeatures2 }; - float output_test[4 * HIDDEN_DIMS2] = { 0.0f }; + float output_test[4 * HIDDEN_DIMS2]; float buffer[HIDDEN_DIMS1 * PATCH_DIM]; - + memset(output_test, 0, sizeof(float) * 4 * HIDDEN_DIMS2); + memset(buffer, 0, sizeof(float) * HIDDEN_DIMS1 * PATCH_DIM); rnnpool_block(input, INPUT_DIMS, PATCH_DIM, PATCH_DIM, fastgrnn, HIDDEN_DIMS1, (const void*)(&rnn1_params), (void*)(&rnn1_buffers), fastgrnn, HIDDEN_DIMS2, (const void*)(&rnn2_params), (void*)(&rnn2_buffers), output_test, buffer); - float error = 0.0f; - for (unsigned d = 0; d < 4 * HIDDEN_DIMS2; ++d) - error += (output[d] - output_test[d]) * (output[d] - output_test[d]); - printf("Error: %f\n", error); + printf("Error: %f\n", l2squared(output, output_test, 4 * HIDDEN_DIMS2)); } diff --git a/c_reference/tests/rnnpool/test_rnnpool_face.c b/c_reference/tests/rnnpool/test_rnnpool_face.c new file mode 100644 index 000000000..977fd56d5 --- /dev/null +++ b/c_reference/tests/rnnpool/test_rnnpool_face.c @@ -0,0 +1,68 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. + +#include +#include + +#include "utils.h" +#include "fastgrnn.h" +#include "rnnpool.h" + +#include "traces_face/trace_0_0_input.h" +#include "traces_face/trace_0_0_output.h" + +#include "face_model/rnn1.h" +#include "face_model/rnn2.h" + +int main() { + FastGRNN_Params rnn1_params = { + .mean = NULL, + .stdDev = NULL, + .W = W1, + .U = U1, + .Bg = Bg1, + .Bh = Bh1, + .sigmoid_zeta = sigmoid_zeta1, + .sigmoid_nu = sigmoid_nu1 + }; + + FastGRNN_Params rnn2_params = { + .mean = NULL, + .stdDev = NULL, + .W = W2, + .U = U2, + .Bg = Bg2, + .Bh = Bh2, + .sigmoid_zeta = sigmoid_zeta2, + .sigmoid_nu = sigmoid_nu2 + }; + + float preComp1[HIDDEN_DIMS1]; + float normFeatures1[INPUT_DIMS]; + memset(preComp1, 0, sizeof(float) * HIDDEN_DIMS1); + memset(normFeatures1, 0, sizeof(float) * INPUT_DIMS); + FastGRNN_Buffers rnn1_buffers = { + .preComp = preComp1, + .normFeatures = normFeatures1 + }; + + float preComp2[HIDDEN_DIMS2]; + float normFeatures2[HIDDEN_DIMS1]; + memset(preComp2, 0, sizeof(float) * HIDDEN_DIMS2); + memset(normFeatures2, 0, sizeof(float) * HIDDEN_DIMS1); + FastGRNN_Buffers rnn2_buffers = { + .preComp = preComp2, + .normFeatures = normFeatures2 + }; + + float output_test[4 * HIDDEN_DIMS2]; + float buffer[HIDDEN_DIMS1 * PATCH_DIM]; + memset(output_test, 0, sizeof(float) * 4 * HIDDEN_DIMS2); + memset(buffer, 0, sizeof(float) * HIDDEN_DIMS1 * PATCH_DIM); + rnnpool_block(input, INPUT_DIMS, PATCH_DIM, PATCH_DIM, + fastgrnn, HIDDEN_DIMS1, (const void*)(&rnn1_params), (void*)(&rnn1_buffers), + fastgrnn, HIDDEN_DIMS2, (const void*)(&rnn2_params), (void*)(&rnn2_buffers), + output_test, buffer); + + printf("Error: %f\n", l2squared(output, output_test, 4 * HIDDEN_DIMS2)); +} diff --git a/c_reference/tests/rnnpool/traces_face/trace_0_0_input.h b/c_reference/tests/rnnpool/traces_face/trace_0_0_input.h new file mode 100644 index 000000000..ef84d2ba7 --- /dev/null +++ b/c_reference/tests/rnnpool/traces_face/trace_0_0_input.h @@ -0,0 +1,4 @@ +#define INPUT_DIMS 4 +#define PATCH_DIM 8 + +static float input[INPUT_DIMS * PATCH_DIM * PATCH_DIM] = {6.0, 3.864753484725952, 0.5032913684844971, 3.255429744720459, 3.4451184272766113, 6.0, 0.0, 0.6251522898674011, 2.5907797813415527, 6.0, 0.0, 0.6076173782348633, 2.5656816959381104, 6.0, 0.0, 0.5852630138397217, 2.495943307876587, 6.0, 0.0, 0.6127088665962219, 2.5315134525299072, 6.0, 0.0, 0.6456913948059082, 2.6090714931488037, 6.0, 0.0, 0.625369131565094, 2.5917551517486572, 6.0, 0.0, 0.5990842580795288, 6.0, 2.52181339263916, 2.0759196281433105, 2.896498203277588, 2.7697253227233887, 1.2512624263763428, 0.0, 0.07762821763753891, 1.819283127784729, 0.8549618124961853, 0.28929558396339417, 0.11453191936016083, 1.770524501800537, 0.9794550538063049, 0.2607428729534149, 0.07501084357500076, 1.6674928665161133, 0.9763496518135071, 0.2539285123348236, 0.11171048134565353, 1.7360005378723145, 1.0677502155303955, 0.28240182995796204, 0.08302449434995651, 1.7945091724395752, 1.0302512645721436, 0.26797160506248474, 0.06604445725679398, 1.818042278289795, 0.9007982611656189, 0.33631449937820435, 0.04834849387407303, 6.0, 2.857222318649292, 1.7300541400909424, 2.761772632598877, 1.7147572040557861, 1.0199624300003052, 0.0, 0.0, 0.8881229758262634, 0.7385762929916382, 0.2987729609012604, 0.0, 0.8871542811393738, 0.8776090145111084, 0.2119949907064438, 0.0, 0.7790001034736633, 0.8657834529876709, 0.22355401515960693, 0.0, 0.8204374313354492, 0.8970885872840881, 0.17433103919029236, 0.0, 0.7232602834701538, 0.8705824017524719, 0.17848879098892212, 0.0, 0.8223532438278198, 0.821057915687561, 0.20487169921398163, 0.0, 6.0, 2.889732837677002, 1.73497474193573, 2.7736072540283203, 1.6566625833511353, 0.9712777137756348, 0.0, 0.0, 1.0266156196594238, 0.6869328022003174, 0.38472726941108704, 0.0, 1.0866038799285889, 0.5747660994529724, 0.3301611840724945, 0.0, 0.9952712059020996, 0.540087103843689, 0.4362652003765106, 0.0, 0.9960271120071411, 0.5620536208152771, 0.3680923581123352, 0.0, 0.8625692129135132, 0.6513324975967407, 0.3328498601913452, 0.0, 0.8319399952888489, 0.8554271459579468, 0.22382153570652008, 0.0, 6.0, 2.863884449005127, 1.7456568479537964, 2.7763559818267822, 1.6321651935577393, 0.9665762782096863, 0.0, 0.0, 0.8071596026420593, 0.7250034213066101, 0.29839715361595154, 0.0, 0.8920531272888184, 0.4664871394634247, 0.2740165889263153, 0.0, 0.8944334387779236, 0.49432384967803955, 0.38937121629714966, 0.0, 0.9263056516647339, 0.552474319934845, 0.355324387550354, 0.0, 1.0150401592254639, 0.6216723918914795, 0.3391576409339905, 0.0, 0.9298738837242126, 0.7536592483520508, 0.24314981698989868, 0.0, 6.0, 2.888258457183838, 1.746010661125183, 2.7819788455963135, 1.6302540302276611, 1.062531590461731, 0.0, 0.0, 0.5961711406707764, 0.8987787365913391, 0.21776816248893738, 0.0, 0.6889306306838989, 0.804358959197998, 0.24634431302547455, 0.0, 0.8192529082298279, 0.8337866067886353, 0.22248630225658417, 0.0, 0.8940339684486389, 0.8404994010925293, 0.24657337367534637, 0.0, 1.022047996520996, 0.8240443468093872, 0.250453919172287, 0.0, 0.9583666324615479, 0.6557619571685791, 0.28978031873703003, 0.0, 6.0, 2.871509075164795, 1.7325565814971924, 2.785510301589966, 1.7297027111053467, 1.039949655532837, 0.0, 0.0, 0.6579188704490662, 0.7792840600013733, 0.2451086938381195, 0.0, 0.7413042187690735, 0.8059958219528198, 0.25876089930534363, 0.0, 0.7776035666465759, 0.8340652585029602, 0.19460541009902954, 0.0, 0.8829543590545654, 0.8143356442451477, 0.20926976203918457, 0.0, 0.838544487953186, 0.7972683310508728, 0.2223927527666092, 0.0, 0.8580051064491272, 0.5966948866844177, 0.391480416059494, 0.0, 6.0, 2.843898296356201, 1.7411582469940186, 2.779827356338501, 1.7269408702850342, 0.906764030456543, 0.0, 0.00856995489448309, 0.7447397112846375, 0.608645498752594, 0.37833335995674133, 0.0, 0.8624472618103027, 0.7215278744697571, 0.4094668924808502, 0.012554308399558067, 0.8872826099395752, 0.7605844736099243, 0.3559991717338562, 0.015747377648949623, 0.977584183216095, 0.9043928384780884, 0.30597585439682007, 0.0, 0.6844930052757263, 0.8694248795509338, 0.257193386554718, 0.0, 0.7443139553070068, 0.8488321304321289, 0.3280007243156433, 0.0}; \ No newline at end of file diff --git a/c_reference/tests/rnnpool/traces_face/trace_0_0_output.h b/c_reference/tests/rnnpool/traces_face/trace_0_0_output.h new file mode 100644 index 000000000..8b481492e --- /dev/null +++ b/c_reference/tests/rnnpool/traces_face/trace_0_0_output.h @@ -0,0 +1,3 @@ +#define HIDDEN_DIMS2 8 + +static float output[4 * HIDDEN_DIMS2] = {0.18747223913669586, 0.11261644959449768, 0.37986981868743896, 0.31620317697525024, 0.24251127243041992, 0.20095956325531006, -0.19935834407806396, 0.2894618511199951, 0.4219159483909607, 0.34062182903289795, -0.17108939588069916, 0.5273934602737427, 0.42910921573638916, 0.55300372838974, -0.4337252378463745, 0.2671497166156769, 0.17525342106819153, 0.13307057321071625, 0.4045558571815491, 0.32742565870285034, 0.24330148100852966, 0.22258351743221283, -0.1840265989303589, 0.2804866433143616, 0.30392521619796753, 0.14001306891441345, 0.10221753269433975, 0.399106502532959, 0.15672656893730164, 0.5337148308753967, 0.11137562245130539, 0.03801737353205681}; \ No newline at end of file diff --git a/c_reference/tests/rnnpool/vww_model/rnn1.h b/c_reference/tests/rnnpool/vww_model/rnn1.h index a9e8c1b00..7357f2664 100644 --- a/c_reference/tests/rnnpool/vww_model/rnn1.h +++ b/c_reference/tests/rnnpool/vww_model/rnn1.h @@ -1,12 +1,9 @@ #define HIDDEN_DIMS1 8 -static float mean1[INPUT_DIMS * PATCH_DIM * PATCH_DIM] = {0.0}; -static float stdDev1[INPUT_DIMS * PATCH_DIM * PATCH_DIM] = {1.0}; - static float W1[INPUT_DIMS * HIDDEN_DIMS1] = { -6.669194251298904419e-02,4.241880401968955994e-02,1.779496856033802032e-02,2.434188500046730042e-02,2.040588408708572388e-01,-6.289862841367721558e-02,8.665277808904647827e-02,-4.211997613310813904e-02,-4.081934988498687744e-01,3.874431252479553223e-01,-9.131602197885513306e-02,-4.231898188591003418e-01,1.137487962841987610e-01,-7.153615355491638184e-02,1.098951250314712524e-01,-5.568345189094543457e-01,-9.548854231834411621e-01,6.743898242712020874e-02,1.308344118297100067e-02,-5.101327300071716309e-01,-2.034226208925247192e-01,-3.552019000053405762e-01,3.574696481227874756e-01,-1.339200735092163086e-01,-1.199822783470153809e+00,4.235469996929168701e-01,-2.176112309098243713e-02,-5.763933062553405762e-01,-4.363142326474189758e-02,-3.619972467422485352e-01,4.203165769577026367e-01,-1.205071806907653809e+00,3.212589919567108154e-01,7.616437077522277832e-01,7.672815918922424316e-01,2.576289772987365723e-01,1.962029747664928436e-02,6.437804698944091797e-01,1.115008115768432617e+00,8.542865514755249023e-02,-8.398564457893371582e-01,-3.183248341083526611e-01,-3.293828964233398438e-01,-1.621776819229125977e-01,5.834429860115051270e-01,3.947886824607849121e-01,-6.720532774925231934e-01,3.155398648232221603e-03,1.377462625503540039e+00,-6.704510450363159180e-01,8.417400717735290527e-02,6.603993773460388184e-01,-1.158756241202354431e-01,4.007513821125030518e-01,-4.624451696872711182e-01,1.793413400650024414e+00,1.293107271194458008e-01,3.916886448860168457e-01,-4.810366034507751465e-01,-2.212110720574855804e-02,-6.547657251358032227e-01,3.415162265300750732e-01,-3.584066927433013916e-01,3.155157715082168579e-02 }; static float U1[HIDDEN_DIMS1 * HIDDEN_DIMS1] = { 4.257509708404541016e-01,-2.243996411561965942e-01,4.599139690399169922e-01,-3.530698418617248535e-01,2.927841432392597198e-02,1.921992599964141846e-01,7.122249808162450790e-03,2.478006668388843536e-02,2.090227305889129639e-01,6.178687140345573425e-02,-8.031798005104064941e-01,-9.047465324401855469e-01,1.150295138359069824e-01,-1.216369643807411194e-01,8.977604657411575317e-02,-3.528899326920509338e-02,-9.029741585254669189e-02,1.964072138071060181e-02,-2.055168338119983673e-02,5.608395114541053772e-02,-1.545069087296724319e-02,-3.085457533597946167e-02,7.987973280251026154e-03,-8.097411133348941803e-03,-1.581576466560363770e-01,-7.558400928974151611e-02,-1.338823318481445312e+00,1.076061371713876724e-02,7.246796786785125732e-02,-6.944761611521244049e-03,-8.065721951425075531e-03,-2.095492556691169739e-02,-2.624719589948654175e-02,-3.073738422244787216e-03,1.721778139472007751e-02,-3.143182024359703064e-03,1.096169114112854004e+00,-4.858187958598136902e-02,-8.912781253457069397e-03,-3.243596106767654419e-02,-1.679758429527282715e-01,-7.507130037993192673e-03,-1.409216374158859253e-01,1.100406423211097717e-01,-1.400157362222671509e-01,1.513722836971282959e-01,-1.210445910692214966e-02,-8.220742642879486084e-02,1.883537024259567261e-01,5.114595890045166016e-01,1.616048932075500488e+00,1.620839357376098633e+00,-1.330980509519577026e-01,9.179102256894111633e-03,7.160065323114395142e-02,2.354629104956984520e-03,8.153508603572845459e-02,9.405165910720825195e-03,1.780232340097427368e-01,-5.950598046183586121e-02,-5.966191366314888000e-02,1.019131317734718323e-01,2.581899240612983704e-02,1.182158961892127991e-01 }; static float Bg1[HIDDEN_DIMS1] = { -1.213001132011413574e+00,-3.357241451740264893e-01,-1.219372987747192383e+00,-2.052456587553024292e-01,-7.755046486854553223e-01,-7.103578448295593262e-01,-8.887031674385070801e-01,-5.140971541404724121e-01}; static float Bh1[HIDDEN_DIMS1] = { -2.761822193861007690e-02,3.516794741153717041e-01,7.828953266143798828e-01,7.023379206657409668e-01,5.146764516830444336e-01,7.880625128746032715e-01,1.113372668623924255e-01,6.815895438194274902e-02 }; -static float zeta1 = 9.999979734420776367e-01; -static float nu1 = 1.968302512977970764e-06; +static float sigmoid_zeta1 = 9.999979734420776367e-01; +static float sigmoid_nu1 = 1.968302512977970764e-06; diff --git a/c_reference/tests/rnnpool/vww_model/rnn2.h b/c_reference/tests/rnnpool/vww_model/rnn2.h index ac9c55efd..1d6efca32 100644 --- a/c_reference/tests/rnnpool/vww_model/rnn2.h +++ b/c_reference/tests/rnnpool/vww_model/rnn2.h @@ -1,11 +1,8 @@ -static float mean2[HIDDEN_DIMS1 * PATCH_DIM] = {0.0}; -static float stdDev2[HIDDEN_DIMS1 * PATCH_DIM] = {1.0}; - static float W2[HIDDEN_DIMS1 * HIDDEN_DIMS2] = { 3.328921273350715637e-02,4.839901626110076904e-02,8.630067855119705200e-02,-3.623228371143341064e-01,3.617477416992187500e-02,-1.013135910034179688e-01,-1.616892337799072266e+00,9.920979291200637817e-02,-3.237796723842620850e-01,-2.648477256298065186e-01,2.549230158329010010e-01,1.056594774127006531e-01,-5.211604386568069458e-02,-5.569029450416564941e-01,7.901080884039402008e-03,4.476135373115539551e-01,-6.069063544273376465e-01,4.720874130725860596e-01,5.098583698272705078e-01,4.149395599961280823e-02,-2.221289835870265961e-02,2.892487943172454834e-01,1.637366861104965210e-01,-4.640549048781394958e-02,3.176147341728210449e-01,-2.042243480682373047e-01,3.439170718193054199e-01,2.087370865046977997e-02,2.785135433077812195e-02,3.186852931976318359e-01,5.935984104871749878e-02,-3.889196217060089111e-01,-8.808585256338119507e-02,1.615403443574905396e-01,-4.946086406707763672e-01,-1.174109801650047302e-02,2.072153845801949501e-03,4.303685724735260010e-01,-7.063516974449157715e-02,-3.901343047618865967e-01,4.995678067207336426e-01,4.996369481086730957e-01,-8.396717905998229980e-02,-3.785453736782073975e-01,1.230286993086338043e-02,-3.816023766994476318e-01,1.118507459759712219e-01,1.944433003664016724e-01,-8.141241967678070068e-02,-5.713146924972534180e-02,6.110856309533119202e-02,2.926556952297687531e-02,-1.405209898948669434e-01,-5.008732676506042480e-01,5.522043444216251373e-03,-8.167469501495361328e-01,-5.527251958847045898e-02,-6.109619140625000000e-02,2.462622970342636108e-01,-1.656581298448145390e-04,1.710500240325927734e+00,-6.598105430603027344e-01,2.383397147059440613e-02,-5.196015834808349609e-01 }; static float U2[HIDDEN_DIMS2 * HIDDEN_DIMS2] = { 3.934212923049926758e-01,-4.295524582266807556e-02,1.002475544810295105e-01,-1.167084053158760071e-01,7.208147644996643066e-02,7.301057875156402588e-02,7.414811104536056519e-02,-1.667873002588748932e-02,2.627835571765899658e-01,2.479245215654373169e-01,-2.347197830677032471e-01,2.314671277999877930e-01,1.421915292739868164e-01,-4.386771023273468018e-01,4.338171705603599548e-02,1.125133633613586426e-01,-9.242479503154754639e-02,1.447719633579254150e-01,3.752615749835968018e-01,2.763805091381072998e-01,-7.362117618322372437e-02,-1.142739504575729370e-01,1.064843088388442993e-01,-8.647724986076354980e-03,1.917631626129150391e-01,8.766186982393264771e-02,-2.752942740917205811e-01,2.459737062454223633e-01,4.787993803620338440e-02,8.056888729333877563e-02,2.883537299931049347e-02,6.972444709390401840e-03,2.150612622499465942e-01,2.176617681980133057e-01,-9.746207296848297119e-02,3.679830208420753479e-02,2.094942629337310791e-01,-2.684409022331237793e-01,6.217004358768463135e-02,-3.187925368547439575e-02,7.392763346433639526e-02,4.104424268007278442e-03,-1.972307413816452026e-01,-2.362748086452484131e-01,3.649697601795196533e-01,3.465250432491302490e-01,7.446446269750595093e-02,5.720932036638259888e-02,-5.659309402108192444e-02,-4.538772255182266235e-02,6.283282488584518433e-02,-3.104292228817939758e-02,-1.333466079086065292e-02,-7.922663539648056030e-02,6.666561216115951538e-02,4.965405911207199097e-02,-4.473730921745300293e-02,-2.271021008491516113e-01,1.190942153334617615e-02,-6.096216291189193726e-02,2.375180423259735107e-01,-1.497552990913391113e-01,-4.494012892246246338e-01,-6.579961627721786499e-02 }; static float Bg2[HIDDEN_DIMS2] = { -1.537145614624023438e+00,-6.593755483627319336e-01,-8.165745735168457031e-01,-1.047435641288757324e+00,-1.003585577011108398e+00,-1.275580763816833496e+00,-9.717565178871154785e-01,-1.349884271621704102e+00 }; static float Bh2[HIDDEN_DIMS2] = { 1.249589323997497559e+00,2.501939237117767334e-01,3.707601428031921387e-01,1.205096021294593811e-01,6.529558449983596802e-02,-2.186506539583206177e-01,-1.120083108544349670e-01,-1.578094959259033203e+00 }; -static float zeta2 = 9.999979734420776367e-01; -static float nu2 = 1.968388687600963749e-06; +static float sigmoid_zeta2 = 9.999979734420776367e-01; +static float sigmoid_nu2 = 1.968388687600963749e-06;