зеркало из https://github.com/microsoft/EdgeML.git
Minor Improvements to Testing (#189)
* Minor Improvements to Testing * Fix Some Benign -Wconversion Warnings
This commit is contained in:
Родитель
b11531b6a2
Коммит
db7ead2866
|
@ -49,5 +49,5 @@ void v_q_scalar_mul(INT_T scalar, const INT_T* const vec, ITER_T len,
|
||||||
// Function for multiplying a matrix with a vector.
|
// Function for multiplying a matrix with a vector.
|
||||||
void m_q_mulvec(const INT_T* const mat, const INT_T* const vec, ITER_T nrows,
|
void m_q_mulvec(const INT_T* const mat, const INT_T* const vec, ITER_T nrows,
|
||||||
ITER_T ncols, INT_T* const ret, SCALE_T scmat, SCALE_T scvec,
|
ITER_T ncols, INT_T* const ret, SCALE_T scmat, SCALE_T scvec,
|
||||||
ITER_T H1, ITER_T H2);
|
SCALE_T H1, SCALE_T H2);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -102,7 +102,7 @@ void v_q_scalar_mul(INT_T scalar, const INT_T* const vec, ITER_T len,
|
||||||
|
|
||||||
void m_q_mulvec(const INT_T* const mat, const INT_T* const vec, ITER_T nrows,
|
void m_q_mulvec(const INT_T* const mat, const INT_T* const vec, ITER_T nrows,
|
||||||
ITER_T ncols, INT_T* const ret, SCALE_T scmat, SCALE_T scvec,
|
ITER_T ncols, INT_T* const ret, SCALE_T scmat, SCALE_T scvec,
|
||||||
ITER_T H1, ITER_T H2) {
|
SCALE_T H1, SCALE_T H2) {
|
||||||
INTM_T tmp[ncols];
|
INTM_T tmp[ncols];
|
||||||
for (ITER_T row = 0; row < nrows; row++) {
|
for (ITER_T row = 0; row < nrows; row++) {
|
||||||
INT_T* mat_offset = (INT_T*)mat + row * ncols;
|
INT_T* mat_offset = (INT_T*)mat + row * ncols;
|
||||||
|
|
|
@ -3,12 +3,12 @@
|
||||||
|
|
||||||
#define HIDDEN_DIM2 8
|
#define HIDDEN_DIM2 8
|
||||||
|
|
||||||
INT_T W2[HIDDEN_DIM2 * HIDDEN_DIM1] = {-849, -1535, 10036, -3592, -286, -6119, -5622, -3760, 359, -6106, -339, -1294, -220, -4337, -2852, -841, -9841, -1977, 745, -996, -1397, -1678, -861, -712, 5701, -5419, -3624, 0, 439, -9575, -3738, 396, 7390, -1214, 1684, 1441, -1650, 13070, 2595, 1405, -4589, -5064, -1926, 2806, 3409, -12783, -284, 3339, -3958, 77, 2312, -1717, -19971, -55, -672, -1476, 2759, -4657, 2028, -3686, -192, -5647, -5103, -3669};
|
static INT_T W2[HIDDEN_DIM2 * HIDDEN_DIM1] = {-849, -1535, 10036, -3592, -286, -6119, -5622, -3760, 359, -6106, -339, -1294, -220, -4337, -2852, -841, -9841, -1977, 745, -996, -1397, -1678, -861, -712, 5701, -5419, -3624, 0, 439, -9575, -3738, 396, 7390, -1214, 1684, 1441, -1650, 13070, 2595, 1405, -4589, -5064, -1926, 2806, 3409, -12783, -284, 3339, -3958, 77, 2312, -1717, -19971, -55, -672, -1476, 2759, -4657, 2028, -3686, -192, -5647, -5103, -3669};
|
||||||
INT_T U2[HIDDEN_DIM2 * HIDDEN_DIM2] = {8755, -905, -2432, -2758, -3162, -4223, 181, 312, 2010, 9661, 1688, 2240, 5634, 5383, -1084, 996, -3641, -1874, 1328, 1795, 15468, -15323, 863, -3599, -912, -327, -1492, 6117, -1188, -2615, 1111, -866, 5998, 4034, 4122, 6542, 704, 19957, -4613, 2397, -2311, -3909, 769, -6010, -1738, 2042, 4177, -1213, -388, -354, -176, 710, 483, -578, 3342, -916, -1570, -5116, 9988, 283, 3409, -318, 4059, 8633};
|
static INT_T U2[HIDDEN_DIM2 * HIDDEN_DIM2] = {8755, -905, -2432, -2758, -3162, -4223, 181, 312, 2010, 9661, 1688, 2240, 5634, 5383, -1084, 996, -3641, -1874, 1328, 1795, 15468, -15323, 863, -3599, -912, -327, -1492, 6117, -1188, -2615, 1111, -866, 5998, 4034, 4122, 6542, 704, 19957, -4613, 2397, -2311, -3909, 769, -6010, -1738, 2042, 4177, -1213, -388, -354, -176, 710, 483, -578, 3342, -916, -1570, -5116, 9988, 283, 3409, -318, 4059, 8633};
|
||||||
INT_T Bg2[HIDDEN_DIM2] = {-5410, -15414, -13002, -12121, -18930, -17922, -8692, -12150};
|
static INT_T Bg2[HIDDEN_DIM2] = {-5410, -15414, -13002, -12121, -18930, -17922, -8692, -12150};
|
||||||
INT_T Bh2[HIDDEN_DIM2] = {21417, 6457, 6421, 8970, 6601, 836, 3060, 8468};
|
static INT_T Bh2[HIDDEN_DIM2] = {21417, 6457, 6421, 8970, 6601, 836, 3060, 8468};
|
||||||
INT_T sigmoid_zeta2 = 32520;
|
static INT_T sigmoid_zeta2 = 32520;
|
||||||
INT_T sigmoid_nu2 = 16387;
|
static INT_T sigmoid_nu2 = 16387;
|
||||||
|
|
||||||
static SCALE_T input2 = 0;
|
static SCALE_T input2 = 0;
|
||||||
static SCALE_T meanScale2 = 0;
|
static SCALE_T meanScale2 = 0;
|
||||||
|
|
|
@ -40,7 +40,7 @@ float compute_error(INT_T pred[4 * HIDDEN_DIM2], float label[4 * HIDDEN_DIM2],
|
||||||
// Function for computing the 95th percentile deviation among all the outputs.
|
// Function for computing the 95th percentile deviation among all the outputs.
|
||||||
float aggregate_error(float* errors, unsigned len) {
|
float aggregate_error(float* errors, unsigned len) {
|
||||||
qsort(errors, len, sizeof(float), compare_floats);
|
qsort(errors, len, sizeof(float), compare_floats);
|
||||||
unsigned index = round(fmax((0.95 * len - 1), 0));
|
unsigned index = (unsigned) round(fmax((0.95 * len - 1), 0));
|
||||||
return errors[index];
|
return errors[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ float aggregate_error(float* errors, unsigned len) {
|
||||||
*/
|
*/
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
unsigned patches;
|
unsigned patches;
|
||||||
int XScale = 12, YScale = 14;
|
SCALE_T XScale = 12, YScale = 14;
|
||||||
|
|
||||||
FILE *xFile, *yFile, *floatResFile, *outputLog;
|
FILE *xFile, *yFile, *floatResFile, *outputLog;
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
int16_t floatHeaderSize;
|
int16_t floatHeaderSize;
|
||||||
fread(&floatHeaderSize, sizeof(int16_t), 1, floatResFile);
|
fread(&floatHeaderSize, sizeof(int16_t), 1, floatResFile);
|
||||||
char* floatHeaderLine = malloc((floatHeaderSize + 1)* sizeof(*floatHeaderLine));
|
char* floatHeaderLine = malloc((floatHeaderSize + 1) * sizeof(*floatHeaderLine));
|
||||||
fgets(floatHeaderLine, floatHeaderSize + 1, floatResFile);
|
fgets(floatHeaderLine, floatHeaderSize + 1, floatResFile);
|
||||||
free(floatHeaderLine);
|
free(floatHeaderLine);
|
||||||
free(headerLine);
|
free(headerLine);
|
||||||
|
@ -105,10 +105,10 @@ int main(int argc, char **argv) {
|
||||||
snprintf(numpyHeader2, len + 1, "%d", patches);
|
snprintf(numpyHeader2, len + 1, "%d", patches);
|
||||||
char numpyHeader3[] = ", 1, 32), }";
|
char numpyHeader3[] = ", 1, 32), }";
|
||||||
|
|
||||||
unsigned headerLength = strlen(numpyHeader1) + strlen(numpyHeader2) +
|
size_t headerLength = strlen(numpyHeader1) + strlen(numpyHeader2) +
|
||||||
strlen(numpyHeader3);
|
strlen(numpyHeader3);
|
||||||
unsigned count = 1;
|
int count = 1;
|
||||||
for (unsigned i = headerLength + 10; i % 64 != 63; i++) {
|
for (size_t i = headerLength + 10; i % 64 != 63; i++) {
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -290,6 +290,7 @@ int main(int argc, char **argv) {
|
||||||
float yLine[4 * HIDDEN_DIM2];
|
float yLine[4 * HIDDEN_DIM2];
|
||||||
float* allErrors = malloc(patches * 4 * HIDDEN_DIM2 * (sizeof(float)));
|
float* allErrors = malloc(patches * 4 * HIDDEN_DIM2 * (sizeof(float)));
|
||||||
|
|
||||||
|
double time_spent = 0.0;
|
||||||
for (unsigned i = 0; i < patches; i++) {
|
for (unsigned i = 0; i < patches; i++) {
|
||||||
fread(&xLine[0], sizeof(float), INPUT_CHANNELS * PATCH_DIM * PATCH_DIM, xFile);
|
fread(&xLine[0], sizeof(float), INPUT_CHANNELS * PATCH_DIM * PATCH_DIM, xFile);
|
||||||
fread(&yLine[0], sizeof(float), 4 * HIDDEN_DIM2, floatResFile);
|
fread(&yLine[0], sizeof(float), 4 * HIDDEN_DIM2, floatResFile);
|
||||||
|
@ -304,7 +305,6 @@ int main(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
double time_spent = 0.0;
|
|
||||||
fprintf(outputLog, "Running Quantized RNNPool on Patch %d\n", i + 1);
|
fprintf(outputLog, "Running Quantized RNNPool on Patch %d\n", i + 1);
|
||||||
clock_t begin = clock();
|
clock_t begin = clock();
|
||||||
q_rnnpool_block(reshapedXLine, INPUT_CHANNELS, PATCH_DIM, PATCH_DIM,
|
q_rnnpool_block(reshapedXLine, INPUT_CHANNELS, PATCH_DIM, PATCH_DIM,
|
||||||
|
@ -315,7 +315,7 @@ int main(int argc, char **argv) {
|
||||||
output_test, buffer);
|
output_test, buffer);
|
||||||
clock_t end = clock();
|
clock_t end = clock();
|
||||||
time_spent += (double)(end - begin) / CLOCKS_PER_SEC;
|
time_spent += (double)(end - begin) / CLOCKS_PER_SEC;
|
||||||
fprintf(outputLog, "Time elpased is %f seconds\n", time_spent);
|
fprintf(outputLog, "Time elapsed is %f seconds\n", time_spent);
|
||||||
|
|
||||||
float max_diff = compute_error(output_test, yLine,
|
float max_diff = compute_error(output_test, yLine,
|
||||||
allErrors + i * 4 * HIDDEN_DIM2, YScale);
|
allErrors + i * 4 * HIDDEN_DIM2, YScale);
|
||||||
|
@ -332,13 +332,13 @@ int main(int argc, char **argv) {
|
||||||
fclose(floatResFile);
|
fclose(floatResFile);
|
||||||
|
|
||||||
float aggregate = aggregate_error(allErrors, patches * 4 * HIDDEN_DIM2);
|
float aggregate = aggregate_error(allErrors, patches * 4 * HIDDEN_DIM2);
|
||||||
|
fprintf(outputLog, "Aggregated 95th Percentile Error: %f\n", aggregate);
|
||||||
if (aggregate < 1.61) {
|
if (aggregate < 1.61) {
|
||||||
fprintf(outputLog, "Quantized RNNPool Numerical Test Passed!\n");
|
fprintf(outputLog, "Quantized RNNPool Numerical Test Passed!\n");
|
||||||
} else {
|
} else {
|
||||||
fprintf(outputLog, "Quantized RNNPool Numerical Test Failed!\n");
|
fprintf(outputLog, "Quantized RNNPool Numerical Test Failed!\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
fprintf(outputLog, "Aggregated 95th Percentile Error: %f\n", aggregate);
|
|
||||||
|
|
||||||
free(allErrors);
|
free(allErrors);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче