Fix Training Packaging pipeline (#9885)

* Fix Training Packaging pipeline
This commit is contained in:
Sherlock 2021-11-30 15:26:10 -08:00 committed by GitHub
parent 740679d329
commit 6de79d82c8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 18 additions and 18 deletions

View file

@ -21,7 +21,7 @@ import numpy
from onnxruntime.datasets import get_example
example2 = get_example("logreg_iris.onnx")
sess = rt.InferenceSession(example2)
sess = rt.InferenceSession(example2, providers=rt.get_available_providers())
input_name = sess.get_inputs()[0].name
output_name = sess.get_outputs()[0].name

View file

@ -72,7 +72,7 @@ with open("pipeline_vectorize.onnx", "wb") as f:
import onnxruntime as rt
from onnxruntime.capi.onnxruntime_pybind11_state import InvalidArgument
sess = rt.InferenceSession("pipeline_vectorize.onnx")
sess = rt.InferenceSession("pipeline_vectorize.onnx", providers=rt.get_available_providers())
import numpy
inp, out = sess.get_inputs()[0], sess.get_outputs()[0]

View file

@ -21,7 +21,7 @@ from onnxruntime.datasets import get_example
# The model is available on github `onnx...test_sigmoid <https://github.com/onnx/onnx/tree/master/onnx/backend/test/data/node/test_sigmoid>`_.
example1 = get_example("sigmoid.onnx")
sess = rt.InferenceSession(example1)
sess = rt.InferenceSession(example1, providers=rt.get_available_providers())
#########################
# Let's see the input name and shape.

View file

@ -31,8 +31,8 @@ print("producer_version={}".format(model.producer_version))
#############################
# With *ONNX Runtime*:
from onnxruntime import InferenceSession
sess = InferenceSession(example)
import onnxruntime as rt
sess = rt.InferenceSession(example, providers=rt.get_available_providers())
meta = sess.get_modelmeta()
print("custom_metadata_map={}".format(meta.custom_metadata_map))

View file

@ -35,7 +35,7 @@ def change_ir_version(filename, ir_version=6):
example1 = get_example("mul_1.onnx")
onnx_model = change_ir_version(example1)
onnx_model_str = onnx_model.SerializeToString()
sess = rt.InferenceSession(onnx_model_str)
sess = rt.InferenceSession(onnx_model_str, providers=rt.get_available_providers())
input_name = sess.get_inputs()[0].name
x = numpy.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype=numpy.float32)
@ -48,7 +48,7 @@ print(res)
options = rt.SessionOptions()
options.enable_profiling = True
sess_profile = rt.InferenceSession(onnx_model_str, options)
sess_profile = rt.InferenceSession(onnx_model_str, options, providers=rt.get_available_providers())
input_name = sess.get_inputs()[0].name
x = numpy.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype=numpy.float32)

View file

@ -64,7 +64,7 @@ with open("logreg_iris.onnx", "wb") as f:
# its input and output.
import onnxruntime as rt
sess = rt.InferenceSession("logreg_iris.onnx")
sess = rt.InferenceSession("logreg_iris.onnx", providers=rt.get_available_providers())
print("input name='{}' and shape={}".format(
sess.get_inputs()[0].name, sess.get_inputs()[0].shape))
@ -180,7 +180,7 @@ with open("rf_iris.onnx", "wb") as f:
###################################
# We compare.
sess = rt.InferenceSession("rf_iris.onnx")
sess = rt.InferenceSession("rf_iris.onnx", providers=rt.get_available_providers())
def sess_predict_proba_rf(x):
return sess.run([prob_name], {input_name: x.astype(numpy.float32)})[0]
@ -204,7 +204,7 @@ for n_trees in range(5, 51, 5):
onx = convert_sklearn(rf, initial_types=initial_type)
with open("rf_iris_%d.onnx" % n_trees, "wb") as f:
f.write(onx.SerializeToString())
sess = rt.InferenceSession("rf_iris_%d.onnx" % n_trees)
sess = rt.InferenceSession("rf_iris_%d.onnx" % n_trees, providers=rt.get_available_providers())
def sess_predict_proba_loop(x):
return sess.run([prob_name], {input_name: x.astype(numpy.float32)})[0]
tsk = speed("loop(X_test, rf.predict_proba, 100)", number=5, repeat=5)

View file

@ -82,7 +82,7 @@ for this machine learning model.
import numpy
import onnxruntime as rt
sess = rt.InferenceSession("logreg_iris.onnx")
sess = rt.InferenceSession("logreg_iris.onnx", providers=rt.get_available_providers())
input_name = sess.get_inputs()[0].name
pred_onx = sess.run(None, {input_name: X_test.astype(numpy.float32)})[0]
print(pred_onx)
@ -97,7 +97,7 @@ by specifying its name into a list.
import numpy
import onnxruntime as rt
sess = rt.InferenceSession("logreg_iris.onnx")
sess = rt.InferenceSession("logreg_iris.onnx", providers=rt.get_available_providers())
input_name = sess.get_inputs()[0].name
label_name = sess.get_outputs()[0].name
pred_onx = sess.run([label_name], {input_name: X_test.astype(numpy.float32)})[0]

View file

@ -68,7 +68,7 @@ class TestInferenceSessionKeras(unittest.TestCase):
# runtime
content = converted_model.SerializeToString()
rt = onnxrt.InferenceSession(content)
rt = onnxrt.InferenceSession(content, providers=onnxrt.get_available_providers())
input = {rt.get_inputs()[0].name: x}
actual_rt = rt.run(None, input)
self.assertEqual(len(actual_rt), 1)

View file

@ -163,11 +163,11 @@ def main():
input_mask = np.ones((batch, sq_length), dtype=np.int64)
# Do forward using the original model.
sess = ort.InferenceSession(model_file_path)
sess = ort.InferenceSession(model_file_path, providers=ort.get_available_providers())
result = sess.run(None, {'input1': input_ids, 'input2': segment_ids, 'input3': input_mask})
# Do forward using the new model.
new_sess = ort.InferenceSession(new_model_file_path)
new_sess = ort.InferenceSession(new_model_file_path, providers=ort.get_available_providers())
new_result = new_sess.run(None, {'input1': input_ids, 'input2': segment_ids, 'input3': input_mask})
# Compare the outcomes from the two models.

View file

@ -298,11 +298,11 @@ segment_ids = np.random.randint(low=0, high=2, size=(batch, sq_length), dtype=np
input_mask = np.ones((batch, sq_length), dtype=np.int64)
# Do forward using the original model.
sess = ort.InferenceSession(input_model_name)
sess = ort.InferenceSession(input_model_name, providers=ort.get_available_providers())
result = sess.run(None, {'input1': input_ids, 'input2': segment_ids, 'input3': input_mask})
# Do forward using the new model.
new_sess = ort.InferenceSession(output_model_name)
new_sess = ort.InferenceSession(output_model_name, providers=ort.get_available_providers())
new_result = new_sess.run(None, {'input1': input_ids, 'input2': segment_ids, 'input3': input_mask})
# Compare the outcomes from the two models.

View file

@ -528,7 +528,7 @@ def main():
is_model_exported = False
import onnxruntime as ort
sess = ort.InferenceSession(onnx_path)
sess = ort.InferenceSession(onnx_path, providers=ort.get_available_providers())
result = sess.run(None, {'input1': input_ids.cpu().numpy(), 'input2': segment_ids.cpu().numpy(), 'input3': input_mask.cpu().numpy()})
print('---ORT result---')