mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-29 20:14:01 +00:00
Use Eigen::logistic instead of manually computing values. (#3186)
* Use MlasComputeLogistic instead of manually computing values. * Update test script to allow the tolerance to be specified when checking float output from logreg_iris.onnx.
This commit is contained in:
parent
b8575dda7b
commit
890cb78b20
3 changed files with 22 additions and 7 deletions
|
|
@ -5,7 +5,9 @@
|
|||
#include "core/common/common.h"
|
||||
#include "core/common/safeint.h"
|
||||
#include "core/framework/op_kernel.h"
|
||||
#include "core/util/math.h"
|
||||
#include "core/util/math_cpuonly.h"
|
||||
#include "core/mlas/inc/mlas.h"
|
||||
#include "core/platform/threadpool.h"
|
||||
|
||||
namespace onnxruntime {
|
||||
|
|
@ -390,10 +392,7 @@ void batched_update_scores_inplace(gsl::span<T> scores, int64_t num_batches_in,
|
|||
break;
|
||||
}
|
||||
case POST_EVAL_TRANSFORM::LOGISTIC: {
|
||||
while (s < s_end) {
|
||||
*s = ComputeLogistic(*s);
|
||||
++s;
|
||||
}
|
||||
MlasComputeLogistic(s, s, scores.size());
|
||||
break;
|
||||
}
|
||||
case POST_EVAL_TRANSFORM::SOFTMAX: {
|
||||
|
|
|
|||
|
|
@ -87,7 +87,6 @@ auto EigenMap(Tensor& t) -> EigenVectorMap<T> {
|
|||
}
|
||||
template <typename T>
|
||||
auto EigenMap(const Tensor& t) -> ConstEigenVectorMap<T> {
|
||||
|
||||
return ConstEigenVectorMap<T>(t.template Data<T>(), t.Shape().Size());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,21 @@ from onnxruntime.backend.backend import OnnxRuntimeBackend as ort_backend
|
|||
from onnx import load
|
||||
|
||||
|
||||
def check_list_of_map_to_float(testcase, expected_rows, actual_rows):
|
||||
"""Validate two list<map<key, float>> instances match closely enough."""
|
||||
|
||||
num_rows = len(expected_rows)
|
||||
sorted_keys = sorted(expected_rows[0].keys())
|
||||
testcase.assertEqual(num_rows, len(actual_rows))
|
||||
testcase.assertEqual(sorted_keys, sorted(actual_rows[0].keys()))
|
||||
|
||||
for i in range(num_rows):
|
||||
# use np.testing.assert_allclose so we can specify the tolerance
|
||||
np.testing.assert_allclose([expected_rows[i][key] for key in sorted_keys],
|
||||
[actual_rows[i][key] for key in sorted_keys],
|
||||
rtol=1e-05, atol=1e-07)
|
||||
|
||||
|
||||
class TestBackend(unittest.TestCase):
|
||||
|
||||
def get_name(self, name):
|
||||
|
|
@ -56,7 +71,8 @@ class TestBackend(unittest.TestCase):
|
|||
output_expected = [{0: 0.950599730014801, 1: 0.027834169566631317, 2: 0.02156602405011654},
|
||||
{0: 0.9974970817565918, 1: 5.6299926654901356e-05, 2: 0.0024466661270707846},
|
||||
{0: 0.9997311234474182, 1: 1.1918064757310276e-07, 2: 0.00026869276189245284}]
|
||||
self.assertEqual(output_expected, res[1])
|
||||
|
||||
check_list_of_map_to_float(self, output_expected, res[1])
|
||||
|
||||
def testRunModelProtoApi(self):
|
||||
name = datasets.get_example("logreg_iris.onnx")
|
||||
|
|
@ -70,7 +86,8 @@ class TestBackend(unittest.TestCase):
|
|||
output_expected = [{0: 0.950599730014801, 1: 0.027834169566631317, 2: 0.02156602405011654},
|
||||
{0: 0.9974970817565918, 1: 5.6299926654901356e-05, 2: 0.0024466661270707846},
|
||||
{0: 0.9997311234474182, 1: 1.1918064757310276e-07, 2: 0.00026869276189245284}]
|
||||
self.assertEqual(output_expected, outputs[1])
|
||||
|
||||
check_list_of_map_to_float(self, output_expected, outputs[1])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
|||
Loading…
Reference in a new issue