Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
3 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
 
#include "gtest/gtest.h"
 
#include <memory>
#include <vector>
 
#include "core/providers/coreml/coreml_execution_provider.h"
#include "core/providers/coreml/coreml_provider_factory_creator.h"
#include "core/providers/coreml/coreml_provider_factory.h"  // for COREMLFlags
#include "test/common/random_generator.h"
#include "test/util/include/current_test_name.h"
#include "test/unittest_util/model_tester.h"
#include "test/util/include/test_utils.h"
 
namespace onnxruntime::test {
 
TEST(CoreMLExecutionProviderDynamicInputShapeTest, MatMul) {
  constexpr auto model_path = ORT_TSTR("testdata/matmul_with_dynamic_input_shape.onnx");
 
  auto test = [&](const size_t M) {
    SCOPED_TRACE(MakeString("M=", M));
    std::unordered_map<std::string, std::string> options;
    auto coreml_ep = CoreMLProviderFactoryCreator::Create(options)->CreateProvider();
 
    const auto ep_verification_params = EPVerificationParams{
        ExpectedEPNodeAssignment::All,
        2e-3f,
    };
 
#if defined(__APPLE__)
    RandomValueGenerator gen{1234};
    const auto A_shape = std::vector<int64_t>{static_cast<int64_t>(M), 2};
    const auto A_data = gen.Uniform<float>(A_shape, 0.0f, 1.0f);
 
    OrtValue A = CreateInputOrtValueOnCPU<float>(A_shape, A_data);
 
    RunAndVerifyOutputsWithEP(model_path, CurrentTestName(),
                              std::move(coreml_ep),
                              {{"A", A}},
                              ep_verification_params);
#else
    TestModelLoad(model_path, std::move(coreml_ep), ep_verification_params.ep_node_assignment);
#endif
  };
 
  for (size_t i = 1; i <= 5; ++i) {
    test(i);
  }
}
 
TEST(CoreMLExecutionProviderDynamicInputShapeTest, MobileNetExcerpt) {
  constexpr auto model_path = ORT_TSTR("testdata/mobilenet_v3_small_excerpt.onnx");
 
  auto test = [&](const size_t batch_size) {
    SCOPED_TRACE(MakeString("batch_size=", batch_size));
    std::unordered_map<std::string, std::string> options;
    auto coreml_ep = CoreMLProviderFactoryCreator::Create(options)->CreateProvider();
 
    const auto ep_verification_params = EPVerificationParams{
        ExpectedEPNodeAssignment::All,
        5e-2f,
    };
 
#if defined(__APPLE__)
    RandomValueGenerator gen{1234};
    const auto input_shape = std::vector<int64_t>{static_cast<int64_t>(batch_size), 3, 224, 224};
    const auto input_data = gen.Uniform<float>(input_shape, 0.0f, 1.0f);
 
    OrtValue input = CreateInputOrtValueOnCPU<float>(input_shape, input_data);
 
    RunAndVerifyOutputsWithEP(model_path, CurrentTestName(),
                              std::move(coreml_ep),
                              {{"input", input}},
                              ep_verification_params);
#else
    TestModelLoad(model_path, std::move(coreml_ep), ep_verification_params.ep_node_assignment);
#endif
  };
 
  for (size_t i = 1; i <= 5; ++i) {
    test(i);
  }
}
 
TEST(CoreMLExecutionProviderDynamicInputShapeTest, EmptyInputFails) {
  constexpr auto model_path = ORT_TSTR("testdata/matmul_with_dynamic_input_shape.onnx");
 
  ModelTester tester(CurrentTestName(), model_path);
  std::unordered_map<std::string, std::string> options;
 
  tester.AddInput<float>("A", {0, 2}, {});
  tester.AddOutput<float>("Y", {0, 4}, {});
 
  tester
      .Config(ModelTester::ExpectResult::kExpectFailure,
              "the runtime shape ({0,2}) has zero elements. This is not supported by the CoreML EP.")
      .ConfigEp(CoreMLProviderFactoryCreator::Create(options)->CreateProvider())
      .RunWithConfig();
}
 
TEST(CoreMLExecutionProviderDynamicInputShapeTest, OnlyAllowStaticInputShapes) {
  constexpr auto model_path = ORT_TSTR("testdata/matmul_with_dynamic_input_shape.onnx");
  std::unordered_map<std::string, std::string> options = {{kCoremlProviderOption_RequireStaticInputShapes, "1"}};
  auto coreml_ep = CoreMLProviderFactoryCreator::Create(options)->CreateProvider();
  ;
 
  TestModelLoad(model_path, std::move(coreml_ep),
                // expect no supported nodes because we disable dynamic input shape support
                ExpectedEPNodeAssignment::None);
}
 
}  // namespace onnxruntime::test