Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2ab3a19

Browse files
author
Changming Sun
authored
Enlarge the read buffer size in C#/Java test code (microsoft#4150)
1. Enlarge the read buffer size further, so that our code can run even faster. TODO: need apply the similar changes to python some other language bindings. 2. Add coreml_VGG16_ImageNet to the test exclusion set of x86_32. It is not a new model but previously we didn't run the test against x86_32.
1 parent 8eb6a53 commit 2ab3a19

6 files changed

Lines changed: 16 additions & 25 deletions

File tree

csharp/test/Microsoft.ML.OnnxRuntime.Tests/InferenceTest.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,7 @@ private static Dictionary<string, string> GetSkippedModels()
576576
skipModels["tf_nasnet_large"] = "Get preallocated buffer for initializer ConvBnFusion_BN_B_cell_11/beginning_bn/beta:0_331 failed";
577577
skipModels["test_zfnet512"] = "System out of memory";
578578
skipModels["test_bvlc_reference_caffenet"] = "System out of memory";
579+
skipModels["coreml_VGG16_ImageNet"] = "System out of memory";
579580
}
580581

581582
return skipModels;
@@ -1745,9 +1746,13 @@ private static void GetTypeAndWidth(TensorElementType elemType, out Type type, o
17451746
}
17461747
static NamedOnnxValue LoadTensorFromFilePb(string filename, IReadOnlyDictionary<string, NodeMetadata> nodeMetaDict)
17471748
{
1748-
var file = File.OpenRead(filename);
1749-
var tensor = Onnx.TensorProto.Parser.ParseFrom(file);
1750-
file.Close();
1749+
//Set buffer size to 4MB
1750+
int readBufferSize = 4194304;
1751+
Onnx.TensorProto tensor = null;
1752+
using (var file = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read, readBufferSize))
1753+
{
1754+
tensor = Onnx.TensorProto.Parser.ParseFrom(file);
1755+
}
17511756

17521757
Type tensorElemType = null;
17531758
int width = 0;

java/src/test/java/ai/onnxruntime/InferenceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1425,7 +1425,7 @@ private static TypeWidth getTypeAndWidth(TensorProto.DataType elemType) {
14251425
private static StringTensorPair loadTensorFromFilePb(
14261426
OrtEnvironment env, File filename, Map<String, NodeInfo> nodeMetaDict)
14271427
throws IOException, OrtException {
1428-
InputStream is = new BufferedInputStream(new FileInputStream(filename));
1428+
InputStream is = new BufferedInputStream(new FileInputStream(filename), 1024 * 1024 * 4);
14291429
OnnxMl.TensorProto tensor = OnnxMl.TensorProto.parseFrom(is);
14301430
is.close();
14311431

onnxruntime/core/graph/model.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424

2525
using namespace ONNX_NAMESPACE;
2626
using namespace onnxruntime;
27-
using namespace ::onnxruntime::common;
27+
using namespace onnxruntime::common;
28+
29+
static constexpr int protobuf_block_size_in_bytes = 4 * 1024 * 1024;
2830

2931
namespace onnxruntime {
3032
Model::Model(const std::string& graph_name,
@@ -237,7 +239,7 @@ Status Model::Load(std::istream& model_istream, ModelProto* p_model_proto) {
237239
if (!p_model_proto) {
238240
return Status(ONNXRUNTIME, INVALID_ARGUMENT, "Null model_proto ptr.");
239241
}
240-
google::protobuf::io::IstreamInputStream zero_copy_input(&model_istream, 1 << 20);
242+
google::protobuf::io::IstreamInputStream zero_copy_input(&model_istream, protobuf_block_size_in_bytes);
241243
const bool result = p_model_proto->ParseFromZeroCopyStream(&zero_copy_input) && model_istream.eof();
242244
if (!result) {
243245
return Status(ONNXRUNTIME, INVALID_PROTOBUF, "Failed to load model because protobuf parsing failed.");
@@ -447,7 +449,7 @@ Status Model::Load(int fd, ONNX_NAMESPACE::ModelProto& model_proto) {
447449
}
448450

449451
#if GOOGLE_PROTOBUF_VERSION >= 3002000
450-
FileInputStream input(fd, 1 << 20);
452+
FileInputStream input(fd, protobuf_block_size_in_bytes);
451453
const bool result = model_proto.ParseFromZeroCopyStream(&input) && input.GetErrno() == 0;
452454
if (!result) {
453455
return Status(ONNXRUNTIME, INVALID_PROTOBUF, "Protobuf parsing failed.");

onnxruntime/test/onnx/TestCase.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ using namespace onnxruntime;
2727
using namespace onnxruntime::common;
2828
using google::protobuf::RepeatedPtrField;
2929

30-
static constexpr int protobuf_block_size_in_bytes = 1 << 20;
30+
static constexpr int protobuf_block_size_in_bytes = 4 * 1024 * 1024;
3131

3232
using ORT_VALUE_HOLDER = std::unique_ptr<OrtValue, decltype(Ort::GetApi().ReleaseValue)>;
3333

onnxruntime/test/onnx/main.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ int real_main(int argc, char* argv[], Ort::Env& env) {
451451
}
452452
#if !defined(__amd64__) && !defined(_M_AMD64)
453453
//out of memory
454-
static const ORTCHAR_T* x86_disabled_tests[] = {ORT_TSTR("mlperf_ssd_resnet34_1200"), ORT_TSTR("mask_rcnn_keras"), ORT_TSTR("mask_rcnn"), ORT_TSTR("faster_rcnn"), ORT_TSTR("vgg19")};
454+
static const ORTCHAR_T* x86_disabled_tests[] = {ORT_TSTR("mlperf_ssd_resnet34_1200"), ORT_TSTR("mask_rcnn_keras"), ORT_TSTR("mask_rcnn"), ORT_TSTR("faster_rcnn"), ORT_TSTR("vgg19"), ORT_TSTR("coreml_VGG16_ImageNet")};
455455
all_disabled_tests.insert(std::begin(x86_disabled_tests), std::end(x86_disabled_tests));
456456
#endif
457457

tools/ci_build/github/azure-pipelines/linux-ort-srv-ci-pipeline.yml

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,6 @@ jobs:
2020
script: sudo docker build --pull -t onnxruntime-server-ubuntu16.04 --build-arg BUILD_USER=onnxruntimedev --build-arg BUILD_UID=$(id -u) --build-arg OS_VERSION=16.04 --build-arg PYTHON_VERSION=3.5 -f Dockerfile.ubuntu_server .
2121
workingDirectory: $(Build.SourcesDirectory)/tools/ci_build/github/linux/docker
2222

23-
- task: CmdLine@2
24-
displayName: 'Download azcopy'
25-
inputs:
26-
script: |
27-
curl -so azcopy.tar.gz -L 'https://aka.ms/downloadazcopy-v10-linux'
28-
tar -zxvf azcopy.tar.gz --strip 1
29-
workingDirectory: $(Build.BinariesDirectory)
30-
31-
- task: PythonScript@0
32-
displayName: 'Download test data'
33-
inputs:
34-
scriptPath: '$(Build.SourcesDirectory)/tools/ci_build/github/download_test_data.py'
35-
arguments: --test_data_url $(TestDataUrl) --build_dir $(Build.BinariesDirectory)
36-
pythonInterpreter: '/usr/bin/python3'
37-
workingDirectory: $(Build.BinariesDirectory)
38-
3923
- task: CmdLine@2
4024
displayName: 'Run docker image'
4125
inputs:

0 commit comments

Comments
 (0)