Исходный код СУБД 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
115
116
117
118
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
 
#include "gtest/gtest.h"
#include "test/providers/provider_test_utils.h"
#include "core/graph/contrib_ops/quantization_defs.h"
#include "core/graph/contrib_ops/contrib_defs.h"
#include "core/graph/contrib_ops/ms_opset.h"
 
namespace onnxruntime {
namespace test {
 
TEST(QuantizeBFPTest, CreateQuantizeGraph) {
  std::unordered_map<std::string, int> domain_to_version;
  domain_to_version[onnxruntime::kMSDomain] = 1;
  // Generate the input & output def lists
  std::vector<ONNX_NAMESPACE::FunctionProto> model_specific_functions;
  auto p_model = std::make_unique<Model>(
      "test", true, ModelMetaData(), PathString(), IOnnxRuntimeOpSchemaRegistryList(), domain_to_version,
      model_specific_functions, DefaultLoggingManager().DefaultLogger(), ModelOptions(true, true));
  onnxruntime::Graph& graph = p_model->MainGraph();
 
  ONNX_NAMESPACE::TypeProto x_float;
  x_float.mutable_tensor_type()->set_elem_type(ONNX_NAMESPACE::TensorProto_DataType_FLOAT);
  x_float.mutable_tensor_type()->mutable_shape()->add_dim()->set_dim_value(128);
  x_float.mutable_tensor_type()->mutable_shape()->add_dim()->set_dim_value(16);
  std::vector<onnxruntime::NodeArg*> input_defs;
  auto& input_arg_x = graph.GetOrCreateNodeArg("x", &x_float);
  input_defs.push_back(&input_arg_x);
 
  NodeAttributes attributes;
  ONNX_NAMESPACE::AttributeProto bfp_type;
  bfp_type.set_name("bfp_type");
  bfp_type.set_i(static_cast<int64_t>(onnxruntime::contrib::BFPType::BFP_1_8_8_16));
  bfp_type.set_type(ONNX_NAMESPACE::AttributeProto_AttributeType::AttributeProto_AttributeType_INT);
  attributes["bfp_type"] = bfp_type;
  ONNX_NAMESPACE::AttributeProto block_dim;
  block_dim.set_name("block_dim");
  block_dim.set_i(1);  // bounding box is over dimension 1
  block_dim.set_type(ONNX_NAMESPACE::AttributeProto_AttributeType::AttributeProto_AttributeType_INT);
  attributes["block_dim"] = block_dim;
 
  std::vector<onnxruntime::NodeArg*> output_defs;
  ONNX_NAMESPACE::TypeProto y_byte;
  y_byte.mutable_tensor_type()->set_elem_type(ONNX_NAMESPACE::TensorProto_DataType_UINT8);
  auto& output_arg_y = graph.GetOrCreateNodeArg("y", &y_byte);
  output_defs.push_back(&output_arg_y);
 
  ONNX_NAMESPACE::TypeProto tensor_int;
  tensor_int.mutable_tensor_type()->set_elem_type(ONNX_NAMESPACE::TensorProto_DataType_INT64);
  auto& output_arg_shape = graph.GetOrCreateNodeArg("shape", &tensor_int);
  auto& output_arg_strides = graph.GetOrCreateNodeArg("strides", &tensor_int);
  output_defs.push_back(&output_arg_shape);
  output_defs.push_back(&output_arg_strides);
 
  // Create a simple model
  graph.AddNode("node1", "QuantizeBFP", "quantizes float tensor to BFP", input_defs, output_defs, &attributes,
                onnxruntime::kMSDomain);
  Status status = graph.Resolve();
  ASSERT_TRUE(status.IsOK()) << status.ErrorMessage();
}
 
TEST(DequantizeBFPTest, CreateDequantizeGraph) {
  std::unordered_map<std::string, int> domain_to_version;
  domain_to_version[onnxruntime::kMSDomain] = 1;
  // Generate the input & output def lists
  std::vector<ONNX_NAMESPACE::FunctionProto> model_specific_functions;
  auto p_model = std::make_unique<Model>(
      "test", true, ModelMetaData(), PathString(), IOnnxRuntimeOpSchemaRegistryList(), domain_to_version,
      model_specific_functions, DefaultLoggingManager().DefaultLogger(), ModelOptions(true, true));
  onnxruntime::Graph& graph = p_model->MainGraph();
 
  ONNX_NAMESPACE::TypeProto x_byte;
  x_byte.mutable_tensor_type()->set_elem_type(ONNX_NAMESPACE::TensorProto_DataType_UINT8);
  x_byte.mutable_tensor_type()->mutable_shape()->add_dim()->set_dim_value(128);  // an arbitrary byte size
  std::vector<onnxruntime::NodeArg*> input_defs;
  auto& input_arg_x = graph.GetOrCreateNodeArg("x", &x_byte);
  input_defs.push_back(&input_arg_x);
 
  ONNX_NAMESPACE::TypeProto tensor_int;
  tensor_int.mutable_tensor_type()->set_elem_type(ONNX_NAMESPACE::TensorProto_DataType_INT64);
  tensor_int.mutable_tensor_type()->mutable_shape()->add_dim()->set_dim_value(2);
  auto& input_arg_shape = graph.GetOrCreateNodeArg("shape", &tensor_int);
  auto& input_arg_strides = graph.GetOrCreateNodeArg("strides", &tensor_int);
  input_defs.push_back(&input_arg_shape);
  input_defs.push_back(&input_arg_strides);
 
  NodeAttributes attributes;
  ONNX_NAMESPACE::AttributeProto bfp_type;
  bfp_type.set_name("bfp_type");
  bfp_type.set_i(static_cast<int64_t>(onnxruntime::contrib::BFPType::BFP_1_8_8_16));
  bfp_type.set_type(ONNX_NAMESPACE::AttributeProto_AttributeType::AttributeProto_AttributeType_INT);
  attributes["bfp_type"] = bfp_type;
  ONNX_NAMESPACE::AttributeProto block_dim;
  block_dim.set_name("block_dim");
  block_dim.set_i(1);  // bounding box is over dimension 1
  block_dim.set_type(ONNX_NAMESPACE::AttributeProto_AttributeType::AttributeProto_AttributeType_INT);
  attributes["block_dim"] = block_dim;
  ONNX_NAMESPACE::AttributeProto dtype;
  dtype.set_name("dtype");
  dtype.set_i(static_cast<int64_t>(ONNX_NAMESPACE::TensorProto_DataType_FLOAT));
  dtype.set_type(ONNX_NAMESPACE::AttributeProto_AttributeType::AttributeProto_AttributeType_INT);
  attributes["dtype"] = dtype;
 
  std::vector<onnxruntime::NodeArg*> output_defs;
  ONNX_NAMESPACE::TypeProto y_float;
  y_float.mutable_tensor_type()->set_elem_type(ONNX_NAMESPACE::TensorProto_DataType_FLOAT);
  auto& output_arg_y = graph.GetOrCreateNodeArg("y", &y_float);
  output_defs.push_back(&output_arg_y);
 
  // Create a simple model
  graph.AddNode("node1", "DequantizeBFP", "dequantizes BFP tensor to float", input_defs, output_defs, &attributes,
                onnxruntime::kMSDomain);
  Status status = graph.Resolve();
  ASSERT_TRUE(status.IsOK()) << status.ErrorMessage();
}
}  // namespace test
}  // namespace onnxruntime