mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-29 20:14:01 +00:00
Fix code-base after breaking API changes
This commit is contained in:
parent
759818f2c1
commit
83c3da3fc0
8 changed files with 34 additions and 45 deletions
|
|
@ -89,12 +89,12 @@ class FastGelu : public OpKernel {
|
|||
int64_t elem_count = X->Shape().Size();
|
||||
const auto coefficient = kAlpha * kGamma;
|
||||
if (elem_count > task_count) {
|
||||
tp->ParallelFor(task_count, [ input,
|
||||
tp->SimpleParallelFor(static_cast<std::ptrdiff_t>(task_count), [ input,
|
||||
output,
|
||||
elem_count,
|
||||
task_count,
|
||||
kAlpha = this->kAlpha,
|
||||
coefficient ](int32_t i) {
|
||||
coefficient ](std::ptrdiff_t i) {
|
||||
int64_t elem_inx_start = i * elem_count / task_count;
|
||||
int64_t elem_inx_end = (i + 1) * elem_count / task_count;
|
||||
for (int64_t elem_inx = elem_inx_start; elem_inx < elem_inx_end; elem_inx++) {
|
||||
|
|
|
|||
|
|
@ -214,13 +214,7 @@ class WindowsEnv : public Env {
|
|||
return Status::OK();
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
Status MapFileIntoMemory(
|
||||
const PathChar*, FileOffsetType, size_t,
|
||||
MappedMemoryPtr&) const override {
|
||||
=======
|
||||
Status MapFileIntoMemory(const ORTCHAR_T*, FileOffsetType, size_t, MappedMemoryPtr&) const override {
|
||||
>>>>>>> origin/master
|
||||
return ORT_MAKE_STATUS(ONNXRUNTIME, NOT_IMPLEMENTED, "MapFileIntoMemory is not implemented on Windows.");
|
||||
}
|
||||
|
||||
|
|
@ -356,7 +350,7 @@ class WindowsEnv : public Env {
|
|||
// adapted from MSVC STL std::filesystem::canonical() implementation
|
||||
// https://github.com/microsoft/STL/blob/ed3cbf36416a385828e7a5987ca52cb42882d84b/stl/inc/filesystem#L2986
|
||||
|
||||
ScopedFileHandle file_handle{CreateFileW(
|
||||
wil::unique_hfile file_handle{CreateFileW(
|
||||
path.c_str(),
|
||||
FILE_READ_ATTRIBUTES,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
|
||||
|
|
@ -365,8 +359,10 @@ class WindowsEnv : public Env {
|
|||
FILE_FLAG_BACKUP_SEMANTICS,
|
||||
nullptr)};
|
||||
|
||||
ORT_RETURN_IF_NOT(
|
||||
file_handle.IsValid(), "CreateFile() failed: ", GetLastError());
|
||||
if (file_handle.get() == INVALID_HANDLE_VALUE) {
|
||||
const int err = GetLastError();
|
||||
return ORT_MAKE_STATUS(ONNXRUNTIME, FAIL, "open file ", ToMBString(path), " fail, errcode = ", err);
|
||||
}
|
||||
|
||||
constexpr DWORD initial_buffer_size = MAX_PATH;
|
||||
std::vector<PathChar> result_buffer{};
|
||||
|
|
@ -374,7 +370,7 @@ class WindowsEnv : public Env {
|
|||
|
||||
while (true) {
|
||||
const DWORD result_length = GetFinalPathNameByHandleW(
|
||||
file_handle.Get(),
|
||||
file_handle.get(),
|
||||
result_buffer.data(),
|
||||
static_cast<DWORD>(result_buffer.size()),
|
||||
0);
|
||||
|
|
|
|||
|
|
@ -12,19 +12,6 @@ from helper import get_name
|
|||
|
||||
class TestInferenceSession(unittest.TestCase):
|
||||
|
||||
def get_name(self, name):
|
||||
if os.path.exists(name):
|
||||
return name
|
||||
rel = os.path.join("testdata", name)
|
||||
if os.path.exists(rel):
|
||||
return rel
|
||||
this = os.path.dirname(__file__)
|
||||
data = os.path.join(this, "..", "testdata")
|
||||
res = os.path.join(data, name)
|
||||
if os.path.exists(res):
|
||||
return res
|
||||
raise FileNotFoundError("Unable to find '{0}' or '{1}' or '{2}'".format(name, rel, res))
|
||||
|
||||
def run_model(self, session_object, run_options):
|
||||
x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype=np.float32)
|
||||
input_name = session_object.get_inputs()[0].name
|
||||
|
|
@ -66,7 +53,7 @@ class TestInferenceSession(unittest.TestCase):
|
|||
def testSessionProviders(self):
|
||||
if 'CUDAExecutionProvider' in onnxrt.get_available_providers():
|
||||
# create session from scratch, but constrain it to only use the CPU.
|
||||
sess = onnxrt.InferenceSession(self.get_name("mul_1.onnx"), providers=['CPUExecutionProvider'])
|
||||
sess = onnxrt.InferenceSession(get_name("mul_1.onnx"), providers=['CPUExecutionProvider'])
|
||||
self.assertEqual(['CPUExecutionProvider'], sess.get_providers())
|
||||
|
||||
def testRunModel(self):
|
||||
|
|
@ -117,7 +104,7 @@ class TestInferenceSession(unittest.TestCase):
|
|||
np.testing.assert_allclose(output_expected, res[0], rtol=1e-05, atol=1e-08)
|
||||
|
||||
def testRunModel2Contiguous(self):
|
||||
sess = onnxrt.InferenceSession(self.get_name("matmul_1.onnx"))
|
||||
sess = onnxrt.InferenceSession(get_name("matmul_1.onnx"))
|
||||
x = np.array([[2.0, 1.0], [4.0, 3.0], [6.0, 5.0]], dtype=np.float32)[:, [1, 0]]
|
||||
input_name = sess.get_inputs()[0].name
|
||||
self.assertEqual(input_name, "X")
|
||||
|
|
@ -138,7 +125,7 @@ class TestInferenceSession(unittest.TestCase):
|
|||
so = onnxrt.SessionOptions()
|
||||
so.log_verbosity_level = 1
|
||||
so.logid = "MultiThreadsTest"
|
||||
sess = onnxrt.InferenceSession(self.get_name("mul_1.onnx"), sess_options=so)
|
||||
sess = onnxrt.InferenceSession(get_name("mul_1.onnx"), sess_options=so)
|
||||
ro1 = onnxrt.RunOptions()
|
||||
ro1.logid = "thread1"
|
||||
t1 = threading.Thread(target=self.run_model, args=(sess, ro1))
|
||||
|
|
@ -219,7 +206,7 @@ class TestInferenceSession(unittest.TestCase):
|
|||
np.testing.assert_equal(output_expected, res[0])
|
||||
|
||||
def testStringInput1(self):
|
||||
sess = onnxrt.InferenceSession(self.get_name("identity_string.onnx"))
|
||||
sess = onnxrt.InferenceSession(get_name("identity_string.onnx"))
|
||||
x = np.array(['this', 'is', 'identity', 'test'], dtype=np.str).reshape((2, 2))
|
||||
|
||||
x_name = sess.get_inputs()[0].name
|
||||
|
|
@ -240,7 +227,7 @@ class TestInferenceSession(unittest.TestCase):
|
|||
np.testing.assert_equal(x, res[0])
|
||||
|
||||
def testStringInput2(self):
|
||||
sess = onnxrt.InferenceSession(self.get_name("identity_string.onnx"))
|
||||
sess = onnxrt.InferenceSession(get_name("identity_string.onnx"))
|
||||
x = np.array(['Olá', '你好', '여보세요', 'hello'], dtype=np.unicode).reshape((2, 2))
|
||||
|
||||
x_name = sess.get_inputs()[0].name
|
||||
|
|
@ -282,7 +269,7 @@ class TestInferenceSession(unittest.TestCase):
|
|||
np.testing.assert_equal(x, res[0].astype('|S8'))
|
||||
|
||||
def testInputObject(self):
|
||||
sess = onnxrt.InferenceSession(self.get_name("identity_string.onnx"))
|
||||
sess = onnxrt.InferenceSession(get_name("identity_string.onnx"))
|
||||
x = np.array(['this', 'is', 'identity', 'test'], object).reshape((2, 2))
|
||||
|
||||
x_name = sess.get_inputs()[0].name
|
||||
|
|
@ -303,7 +290,7 @@ class TestInferenceSession(unittest.TestCase):
|
|||
np.testing.assert_equal(x, res[0])
|
||||
|
||||
def testInputVoid(self):
|
||||
sess = onnxrt.InferenceSession(self.get_name("identity_string.onnx"))
|
||||
sess = onnxrt.InferenceSession(get_name("identity_string.onnx"))
|
||||
x = np.array([b'this', b'is', b'identity', b'test'], np.void).reshape((2, 2))
|
||||
|
||||
x_name = sess.get_inputs()[0].name
|
||||
|
|
@ -327,7 +314,7 @@ class TestInferenceSession(unittest.TestCase):
|
|||
np.testing.assert_equal(expr, res[0])
|
||||
|
||||
def testZipMapStringFloat(self):
|
||||
sess = onnxrt.InferenceSession(self.get_name("zipmap_stringfloat.onnx"))
|
||||
sess = onnxrt.InferenceSession(get_name("zipmap_stringfloat.onnx"))
|
||||
x = np.array([1.0, 0.0, 3.0, 44.0, 23.0, 11.0], dtype=np.float32).reshape((2, 3))
|
||||
|
||||
x_name = sess.get_inputs()[0].name
|
||||
|
|
@ -353,7 +340,7 @@ class TestInferenceSession(unittest.TestCase):
|
|||
self.assertEqual(output_expected, res[0])
|
||||
|
||||
def testZipMapInt64Float(self):
|
||||
sess = onnxrt.InferenceSession(self.get_name("zipmap_int64float.onnx"))
|
||||
sess = onnxrt.InferenceSession(get_name("zipmap_int64float.onnx"))
|
||||
x = np.array([1.0, 0.0, 3.0, 44.0, 23.0, 11.0], dtype=np.float32).reshape((2, 3))
|
||||
|
||||
x_name = sess.get_inputs()[0].name
|
||||
|
|
@ -392,7 +379,7 @@ class TestInferenceSession(unittest.TestCase):
|
|||
def testProfilerWithSessionOptions(self):
|
||||
so = onnxrt.SessionOptions()
|
||||
so.enable_profiling = True
|
||||
sess = onnxrt.InferenceSession(self.get_name("mul_1.onnx"), sess_options=so)
|
||||
sess = onnxrt.InferenceSession(get_name("mul_1.onnx"), sess_options=so)
|
||||
x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype=np.float32)
|
||||
sess.run([], {'X': x})
|
||||
profile_file = sess.end_profiling()
|
||||
|
|
@ -407,7 +394,7 @@ class TestInferenceSession(unittest.TestCase):
|
|||
self.assertTrue(']' in lines[8])
|
||||
|
||||
def testDictVectorizer(self):
|
||||
sess = onnxrt.InferenceSession(self.get_name("pipeline_vectorize.onnx"))
|
||||
sess = onnxrt.InferenceSession(get_name("pipeline_vectorize.onnx"))
|
||||
input_name = sess.get_inputs()[0].name
|
||||
self.assertEqual(input_name, "float_input")
|
||||
input_type = str(sess.get_inputs()[0].type)
|
||||
|
|
@ -521,7 +508,7 @@ class TestInferenceSession(unittest.TestCase):
|
|||
res = sess.run([], {'input1:0': a, 'input:0': b})
|
||||
|
||||
def testSequenceLength(self):
|
||||
sess = onnxrt.InferenceSession(self.get_name("sequence_length.onnx"))
|
||||
sess = onnxrt.InferenceSession(get_name("sequence_length.onnx"))
|
||||
x = [
|
||||
np.array([1.0, 0.0, 3.0, 44.0, 23.0, 11.0], dtype=np.float32).reshape((2, 3)),
|
||||
np.array([1.0, 0.0, 3.0, 44.0, 23.0, 11.0], dtype=np.float32).reshape((2, 3))
|
||||
|
|
@ -542,7 +529,7 @@ class TestInferenceSession(unittest.TestCase):
|
|||
self.assertEqual(output_expected, res[0])
|
||||
|
||||
def testSequenceConstruct(self):
|
||||
sess = onnxrt.InferenceSession(self.get_name("sequence_construct.onnx"))
|
||||
sess = onnxrt.InferenceSession(get_name("sequence_construct.onnx"))
|
||||
|
||||
self.assertEqual(sess.get_inputs()[0].type, 'tensor(int64)')
|
||||
self.assertEqual(sess.get_inputs()[1].type, 'tensor(int64)')
|
||||
|
|
|
|||
|
|
@ -96,9 +96,11 @@ int main(int argc, char* argv[]) {
|
|||
0, //session_log_verbosity_level
|
||||
5, //max_num_graph_transformation_steps
|
||||
TransformerLevel::Level1, //graph_optimization_level
|
||||
0, //intra_op_num_threads
|
||||
0, //inter_op_num_threads
|
||||
overrides //free_dimension_overrides
|
||||
{}, //intra_op_param
|
||||
{}, //inter_op_param
|
||||
overrides, //free_dimension_overrides
|
||||
true, //use_per_session_threads
|
||||
true //thread_pool_allow_spinning
|
||||
};
|
||||
|
||||
InferenceSession session_object{so, *env};
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ DataLoader::DataLoader(const MapStringToString& input_name_map,
|
|||
}
|
||||
|
||||
data_loader_thread_pool_ = onnxruntime::make_unique<onnxruntime::concurrency::ThreadPool>(
|
||||
"DataLoaderPool", thread_pool_size_);
|
||||
&onnxruntime::Env::Default(), onnxruntime::ThreadOptions(), ORT_TSTR("DataLoaderPool"), thread_pool_size_, true);
|
||||
}
|
||||
|
||||
Status DataLoader::InitializeDataSetIndex(size_t initial_data_set_index) {
|
||||
|
|
|
|||
|
|
@ -33,9 +33,11 @@ static SessionOptions SESSION_OPTION = {
|
|||
0, //session_log_verbosity_level
|
||||
5, //max_num_graph_transformation_steps
|
||||
TransformerLevel::Level1, //graph_optimization_level
|
||||
0, //intra_op_num_threads
|
||||
0, //inter_op_num_threads
|
||||
overrides //free_dimension_overrides
|
||||
{}, //intra_op_param
|
||||
{}, //inter_op_param
|
||||
overrides, //free_dimension_overrides
|
||||
true, //use_per_session_threads
|
||||
true //thread_pool_allow_spinning
|
||||
};
|
||||
|
||||
TrainingRunner::TrainingRunner(Parameters params, const Environment& env)
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include <bitset>
|
||||
#include <cmath>
|
||||
#include <random>
|
||||
#include <thread>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "core/framework/random_seed.h"
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
#include <thread>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "orttraining/core/optimizer/gist_encode_decode.h"
|
||||
|
|
|
|||
Loading…
Reference in a new issue