Skip to content
This repository was archived by the owner on Jan 13, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ def test_model_label_encoder_int(self):
model = LabelEncoder()
data = numpy.array([10, 3, 5, -34, 0], dtype=numpy.int64)
model.fit(data)
for op in sorted(set([9, 10, 11, 12, 13, 14, TARGET_OPSET])): # opset=13, 14, ...
# opset=13, 14, ...
for op in sorted(set([9, 10, 11, 12, 13, 14, TARGET_OPSET])):
if op > TARGET_OPSET:
continue
with self.subTest(opset=op):
Expand Down
3 changes: 2 additions & 1 deletion _unittests/ut_onnxrt/test_benchmark_replay.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ def test_benchmark_replay(self):
enumerate_benchmark_replay(temp, runtime='python')),
FileNotFoundError)
res = list(enumerate_validated_operator_opsets(
0, fLOG=None, models={"LogisticRegression"}, opset_min=14, # opset=13, 14, ...
# opset=13, 14, ...
0, fLOG=None, models={"LogisticRegression"}, opset_min=14,
opset_max=14, benchmark=False, store_models=True, dump_all=True,
dump_folder=temp, filter_exp=lambda m, p: (
"64" not in p and "b-cl" in p and "dec" not in p)))
Expand Down
18 changes: 12 additions & 6 deletions _unittests/ut_onnxrt/test_onnxrt_python_runtime_.py
Original file line number Diff line number Diff line change
Expand Up @@ -2874,7 +2874,8 @@ def test_onnxt_runtime_reduce_prod(self):
def test_onnxt_runtime_reduce_sum(self):
X = numpy.array([[2, 1], [0, 1]], dtype=float)

for opset in (10, 11, 12, 13, 14, get_opset_number_from_onnx()): # opset=13, 14, ...
# opset=13, 14, ...
for opset in (10, 11, 12, 13, 14, get_opset_number_from_onnx()):
if onnx_opset_version() < opset:
continue
if opset < 13:
Expand Down Expand Up @@ -2977,7 +2978,8 @@ def test_onnxt_runtime_reduce_sum_square(self):
def test_onnxt_runtime_reduce_sum_noop(self):
X = numpy.array([], dtype=float).reshape((2, 0))

for opset in (13, 14, get_opset_number_from_onnx()): # opset=13, 14, ...
# opset=13, 14, ...
for opset in (13, 14, get_opset_number_from_onnx()):
if onnx_opset_version() < opset:
continue
cl = OnnxReduceSum
Expand Down Expand Up @@ -3191,7 +3193,8 @@ def test_onnxt_runtime_slice(self):

@wraplog()
def test_onnxt_runtime_slice_step_none(self):
for opset in [13, 14, get_opset_number_from_onnx()]: # opset=13, 14, ...
# opset=13, 14, ...
for opset in [13, 14, get_opset_number_from_onnx()]:
if opset > get_opset_number_from_onnx():
continue
with self.subTest(opset=opset):
Expand All @@ -3211,7 +3214,8 @@ def test_onnxt_runtime_slice_step_none(self):

@wraplog()
def test_onnxt_runtime_split(self):
for opset in [10, 11, 12, 13, 14, get_opset_number_from_onnx()]: # opset=13, 14, ...
# opset=13, 14, ...
for opset in [10, 11, 12, 13, 14, get_opset_number_from_onnx()]:
if opset > get_opset_number_from_onnx():
continue
with self.subTest(opset=opset):
Expand Down Expand Up @@ -3259,7 +3263,8 @@ def test_onnxt_runtime_sqrt(self):

@wraplog()
def test_onnxt_runtime_squeeze(self):
for opset in [10, 11, 12, 13, 14, get_opset_number_from_onnx()]: # opset=13, 14, ...
# opset=13, 14, ...
for opset in [10, 11, 12, 13, 14, get_opset_number_from_onnx()]:
if opset > get_opset_number_from_onnx():
continue
with self.subTest(opset=opset):
Expand Down Expand Up @@ -3444,7 +3449,8 @@ def test_onnxt_runtime_transpose(self):

@wraplog()
def test_onnxt_runtime_unsqueeze(self):
for opset in [10, 11, 12, 13, 14, get_opset_number_from_onnx()]: # opset=13, 14, ...
# opset=13, 14, ...
for opset in [10, 11, 12, 13, 14, get_opset_number_from_onnx()]:
if opset > get_opset_number_from_onnx():
continue
with self.subTest(opset=opset):
Expand Down
50 changes: 50 additions & 0 deletions _unittests/ut_testing/test_custom_add.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"""
@brief test log(time=8s)
"""
import unittest
import numpy
from pyquickhelper.pycode import ExtTestCase
from mlprodict.testing.experimental_c import ( # pylint: disable=E0611
BroadcastMatrixAddLeftInplaceDouble,
BroadcastMatrixAddLeftInplaceFloat,
BroadcastMatrixAddLeftInplaceInt64)


class TestCustomAdd(ExtTestCase):

add_dtypes = {
numpy.float64: BroadcastMatrixAddLeftInplaceDouble,
numpy.float32: BroadcastMatrixAddLeftInplaceFloat,
numpy.int64: BroadcastMatrixAddLeftInplaceInt64
}

def _common_broadcast_matrix(self, dt):
with self.subTest(dtype=dt):
fct = TestCustomAdd.add_dtypes[dt]

m1 = numpy.array([1, 2, 3, 4, 5, 6], dtype=dt).reshape((-1, 2))
m2 = numpy.array([1, 2], dtype=dt).reshape((1, 2))
m3 = m1 + m2
fct(m1, m2)
self.assertEqualArray(m3, m1)

m1 = numpy.array([1, 2, 3, 4, 5, 6], dtype=dt).reshape((-1, 3))
m2 = numpy.array([1, 2], dtype=dt).reshape((2, 1))
m3 = m1 + m2
fct(m1, m2)
self.assertEqualArray(m3, m1)

m1 = numpy.array([1, 2, 3, 4, 5, 6], dtype=dt).reshape((-1, 3))
m2 = numpy.array([1, 2], dtype=dt).reshape((2, ))
m3 = m1 + m2.reshape((2, 1))
fct(m1, m2)
self.assertEqualArray(m3, m1)

def test_broadcast_matrix(self):
for dt in [numpy.float64, numpy.float32, numpy.int64]:
self._common_broadcast_matrix(dt)


if __name__ == "__main__":
# TestEinsum().test_np_test_broadcasting_dot_cases1()
unittest.main()
4 changes: 4 additions & 0 deletions bin/debug/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "op_qlinear_conv_.hpp"
#include "op_qlinear_cpp_qgemm_tester_.hpp"
#include "op_qlinear_cpp_tester_.hpp"
#include "experimental_c.h"


void test_qlinear_conv1() {
Expand Down Expand Up @@ -100,6 +101,9 @@ void test_qlinear_conv2(bool random) {
}

int main() {
experimental_ut_add();
experimental_ut_einsum();
experimental_ut_reduce();
TestQGemm0();
TestQGemm1();
test_qlinear_conv2(false);
Expand Down
12 changes: 11 additions & 1 deletion bin/debug/debug.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions);SKIP_PYTHON</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>../../mlprodict/onnxrt/ops_cpu</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>../../mlprodict/onnxrt/ops_cpu;../../mlprodict/testing</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand Down Expand Up @@ -150,6 +150,16 @@
<ClCompile Include="../../mlprodict/onnxrt/ops_cpu/op_conv_matrices_.hpp" />
<ClCompile Include="../../mlprodict/onnxrt/ops_cpu/op_common_.cpp" />
<ClCompile Include="../../mlprodict/onnxrt/ops_cpu/op_common_.hpp" />
<ClCompile Include="../../mlprodict/testing/experimental_c_helper.h" />
<ClCompile Include="../../mlprodict/testing/experimental_c_helper.hpp" />
<ClCompile Include="../../mlprodict/testing/experimental_c_add.h" />
<ClCompile Include="../../mlprodict/testing/experimental_c_add.hpp" />
<ClCompile Include="../../mlprodict/testing/experimental_c_einsum.h" />
<ClCompile Include="../../mlprodict/testing/experimental_c_einsum.hpp" />
<ClCompile Include="../../mlprodict/testing/experimental_c_reduce.h" />
<ClCompile Include="../../mlprodict/testing/experimental_c_reduce.hpp" />
<ClCompile Include="../../mlprodict/testing/experimental_c.cpp" />
<ClCompile Include="../../mlprodict/testing/experimental_c.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
3 changes: 3 additions & 0 deletions mlprodict/onnxrt/ops_cpu/op_conv_matrices_.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Inspired from
// https://github.com/microsoft/onnxruntime/blob/master/onnxruntime/core/providers/cpu/nn/qlinearconv.cc.

#include "op_conv_matrices_.hpp"


Expand Down
2 changes: 1 addition & 1 deletion mlprodict/onnxrt/ops_cpu/op_conv_matrices_.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

// Inspired from
// https://github.com/microsoft/onnxruntime/blob/master/onnxruntime/core/providers/cpu/ml/tree_ensemble_classifier.cc.
// https://github.com/microsoft/onnxruntime/blob/master/onnxruntime/core/providers/cpu/nn/qlinearconv.cc.

#if !defined(_CRT_SECURE_NO_WARNINGS)
#define _CRT_SECURE_NO_WARNINGS
Expand Down
4 changes: 1 addition & 3 deletions mlprodict/onnxrt/ops_cpu/op_qlinear_conv_.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// Inspired from
// https://github.com/microsoft/onnxruntime/blob/master/onnxruntime/core/providers/cpu/ml/tree_ensemble_classifier.cc.
// https://github.com/microsoft/onnxruntime/blob/master/onnxruntime/core/providers/cpu/nn/qlinearconv.cc.

#if !defined(_CRT_SECURE_NO_WARNINGS)
#define _CRT_SECURE_NO_WARNINGS
#endif


#include "op_qlinear_conv_.hpp"
#include "op_qlinear_cpp_tester_.hpp"
#include "op_qlinear_cpp_qgemm_tester_.hpp"
Expand All @@ -20,7 +19,6 @@
#undef max
#endif


class RuntimeTesterQLinearConv : public RuntimeTester {
public:
RuntimeTesterQLinearConv(const char* op_name, int opset = 13) : RuntimeTester(op_name, opset) {}
Expand Down
5 changes: 2 additions & 3 deletions mlprodict/onnxrt/ops_cpu/op_qlinear_conv_.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

// Inspired from
// https://github.com/microsoft/onnxruntime/blob/master/onnxruntime/core/providers/cpu/ml/tree_ensemble_classifier.cc.
// https://github.com/microsoft/onnxruntime/blob/master/onnxruntime/core/providers/cpu/nn/qlinearconv.cc.

#if !defined(_CRT_SECURE_NO_WARNINGS)
#define _CRT_SECURE_NO_WARNINGS
Expand Down Expand Up @@ -49,8 +49,7 @@ inline uint32_t BitsOfFp32(float FloatValue) {
*/
template <typename T>
void RequantizeOutput(
const int32_t* Input, T* Output, const int32_t* Bias,
size_t M, size_t N,
const int32_t* Input, T* Output, const int32_t* Bias, size_t M, size_t N,
const float* Scale, bool PerColumnScale, T ZeroPoint) {
const float PerMatrixScaleValue = PerColumnScale ? 0.0f : *Scale;
const float MinimumValue = float(0 - ZeroPoint);
Expand Down
2 changes: 1 addition & 1 deletion mlprodict/onnxrt/ops_cpu/op_qlinear_cpp_qgemm_tester_.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Inspired from
// https://github.com/microsoft/onnxruntime/blob/master/onnxruntime/core/providers/cpu/ml/tree_ensemble_classifier.cc.
// https://github.com/microsoft/onnxruntime/blob/master/onnxruntime/test/providers/cpu/nn/qlinearconv_op_test.cc.

#if !defined(_CRT_SECURE_NO_WARNINGS)
#define _CRT_SECURE_NO_WARNINGS
Expand Down
2 changes: 1 addition & 1 deletion mlprodict/onnxrt/ops_cpu/op_qlinear_cpp_qgemm_tester_.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

// Inspired from
// https://github.com/microsoft/onnxruntime/blob/master/onnxruntime/core/providers/cpu/ml/tree_ensemble_classifier.cc.
// https://github.com/microsoft/onnxruntime/blob/master/onnxruntime/test/providers/cpu/nn/qlinearconv_op_test.cc.

#if !defined(_CRT_SECURE_NO_WARNINGS)
#define _CRT_SECURE_NO_WARNINGS
Expand Down
2 changes: 1 addition & 1 deletion mlprodict/onnxrt/ops_cpu/op_qlinear_cpp_tester_.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

// Inspired from
// https://github.com/microsoft/onnxruntime/blob/master/onnxruntime/core/providers/cpu/ml/tree_ensemble_classifier.cc.
// https://github.com/microsoft/onnxruntime/blob/master/onnxruntime/test/providers/cpu/nn/qlinearconv_op_test.cc.

#if !defined(_CRT_SECURE_NO_WARNINGS)
#define _CRT_SECURE_NO_WARNINGS
Expand Down
Loading