Skip to content

Commit b0a0e72

Browse files
authored
Adress & remove TODO's (#61)
Remove TODO from Model API adapter. We should change API there but this is in different repo. Created tickets: CVS-128781 CVS-128782 CVS-128783 CVS-128784 CVS-128785 * Add missing test files * Add calculators tests to CI JIRA:CVS-127914
1 parent 00612f2 commit b0a0e72

11 files changed

+115
-372
lines changed

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ run_hello_ovms:
4040
MEDIAPIPE_UNSTABLE_TESTS_REGEX="MuxInputStreamHandlerTest.RemovesUnusedDataStreamPackets"
4141
run_unit_tests:
4242
docker run -e http_proxy=$(HTTP_PROXY) -e https_proxy=$(HTTPS_PROXY) $(OVMS_MEDIA_DOCKER_IMAGE):$(OVMS_MEDIA_IMAGE_TAG) bazel test --define=MEDIAPIPE_DISABLE_GPU=1 --test_output=streamed --test_filter="-${MEDIAPIPE_UNSTABLE_TESTS_REGEX}" //mediapipe/framework/...
43+
docker run -e http_proxy=$(HTTP_PROXY) -e https_proxy=$(HTTPS_PROXY) $(OVMS_MEDIA_DOCKER_IMAGE):$(OVMS_MEDIA_IMAGE_TAG) bazel test --define=MEDIAPIPE_DISABLE_GPU=1 --test_output=streamed //mediapipe/calculators/ovms:all
4344

4445
run_hello_world:
4546
docker run $(OVMS_MEDIA_DOCKER_IMAGE):$(OVMS_MEDIA_IMAGE_TAG) bazel-bin/mediapipe/examples/desktop/hello_world/hello_world

mediapipe/calculators/ovms/BUILD

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ cc_library(
4747
"modelapiovmsadapter.hpp"
4848
],
4949
deps = [
50-
"//mediapipe/framework/port:logging", # TODO remove logs but need better error handling/reporting in Model API
50+
"//mediapipe/framework/port:logging",
5151
"@ovms//src:ovms_header",
5252
"@model_api//:model_api",
5353
"@linux_openvino//:openvino",
@@ -145,8 +145,8 @@ cc_test(
145145
"test_data/config.json",
146146
"test_data/dummy/1/dummy.bin",
147147
"test_data/dummy/1/dummy.xml",
148-
"test_data/add_two_inputs_model/1/dummy.bin",
149-
"test_data/add_two_inputs_model/1/dummy.xml",
148+
"test_data/add_two_inputs_model/1/add.bin",
149+
"test_data/add_two_inputs_model/1/add.xml",
150150
],
151151
copts = ["-Iexternal/ovms/src","-Isrc"],
152152
)

mediapipe/calculators/ovms/modelapiovmsadapter.cc

+13-29
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,11 @@ using std::endl;
6767
#pragma GCC diagnostic ignored "-Wunused-function"
6868
using InferenceOutput = std::map<std::string, ov::Tensor>;
6969
using InferenceInput = std::map<std::string, ov::Tensor>;
70-
// TODO
71-
// * why std::map
72-
// * no ret code from infer()
73-
// * no ret code from load()
70+
7471
namespace ovms {
7572
static OVMS_DataType OVPrecision2CAPI(ov::element::Type_t datatype);
7673
static ov::element::Type_t CAPI2OVPrecision(OVMS_DataType datatype);
77-
static ov::Tensor makeOvTensorO(OVMS_DataType datatype, const int64_t* shape, size_t dimCount, const void* voutputData, size_t bytesize);
74+
static ov::Tensor makeOvTensor(OVMS_DataType datatype, const int64_t* shape, size_t dimCount, const void* voutputData, size_t bytesize);
7875

7976
OVMSInferenceAdapter::OVMSInferenceAdapter(const std::string& servableName, uint32_t servableVersion, OVMS_Server* cserver) :
8077
servableName(servableName),
@@ -103,31 +100,22 @@ InferenceOutput OVMSInferenceAdapter::infer(const InferenceInput& input) {
103100
// PREPARE EACH INPUT
104101
// extract single tensor
105102
for (const auto& [name, input_tensor] : input) {
106-
// TODO validate existence of tag key in map
107-
// or handle inference when there is no need for mapping
108103
const char* realInputName = name.c_str();
109-
#if 0
110-
const float* input_tensor_access = reinterpret_cast<float*>(input_tensor.data());
111-
std::stringstream ss;
112-
ss << " Adapter received tensor: [ ";
113-
for (int x = 0; x < 10; ++x) {
114-
ss << input_tensor_access[x] << " ";
115-
}
116-
ss << " ]";
117-
LOG(INFO) << ss.str();
118-
#endif
119104
const auto& ovinputShape = input_tensor.get_shape();
120-
std::vector<int64_t> inputShape{ovinputShape.begin(), ovinputShape.end()}; // TODO error handling shape conversion
105+
if (std::any_of(ovinputShape.begin(), ovinputShape.end(), [](size_t dim) {
106+
return dim > std::numeric_limits<int64_t>::max();})) {
107+
throw std::runtime_error("Cannot use C-API with dimension size greater than int64_t max value");
108+
}
109+
std::vector<int64_t> inputShape{ovinputShape.begin(), ovinputShape.end()};
121110
OVMS_DataType inputDataType = OVPrecision2CAPI(input_tensor.get_element_type());
122-
ASSERT_CAPI_STATUS_NULL(OVMS_InferenceRequestAddInput(request, realInputName, inputDataType, inputShape.data(), inputShape.size())); // TODO retcode
111+
ASSERT_CAPI_STATUS_NULL(OVMS_InferenceRequestAddInput(request, realInputName, inputDataType, inputShape.data(), inputShape.size()));
123112
const uint32_t NOT_USED_NUM = 0;
124-
// TODO handle hardcoded buffertype, notUsedNum additional options? side packets?
125113
ASSERT_CAPI_STATUS_NULL(OVMS_InferenceRequestInputSetData(request,
126114
realInputName,
127115
reinterpret_cast<void*>(input_tensor.data()),
128116
input_tensor.get_byte_size(),
129117
OVMS_BUFFERTYPE_CPU,
130-
NOT_USED_NUM)); // TODO retcode
118+
NOT_USED_NUM));
131119
}
132120
//////////////////
133121
// INFERENCE
@@ -147,13 +135,10 @@ InferenceOutput OVMSInferenceAdapter::infer(const InferenceInput& input) {
147135
return output;
148136
}
149137
CREATE_GUARD(responseGuard, OVMS_InferenceResponse, response);
150-
// verify GetOutputCount
151138
uint32_t outputCount = 42;
152139
ASSERT_CAPI_STATUS_NULL(OVMS_InferenceResponseOutputCount(response, &outputCount));
153140
uint32_t parameterCount = 42;
154141
ASSERT_CAPI_STATUS_NULL(OVMS_InferenceResponseParameterCount(response, &parameterCount));
155-
// TODO handle output filtering. Graph definition could suggest
156-
// that we are not interested in all outputs from OVMS Inference
157142
const void* voutputData;
158143
size_t bytesize = 42;
159144
OVMS_DataType datatype = (OVMS_DataType)199;
@@ -164,18 +149,19 @@ InferenceOutput OVMSInferenceAdapter::infer(const InferenceInput& input) {
164149
const char* outputName{nullptr};
165150
for (size_t i = 0; i < outputCount; ++i) {
166151
ASSERT_CAPI_STATUS_NULL(OVMS_InferenceResponseOutput(response, i, &outputName, &datatype, &shape, &dimCount, &voutputData, &bytesize, &bufferType, &deviceId));
167-
output[outputName] = makeOvTensorO(datatype, shape, dimCount, voutputData, bytesize); // TODO optimize FIXME
152+
output[outputName] = makeOvTensor(datatype, shape, dimCount, voutputData, bytesize);
168153
}
169154
return output;
170155
}
156+
171157
void OVMSInferenceAdapter::loadModel(const std::shared_ptr<const ov::Model>& model, ov::Core& core,
172158
const std::string& device, const ov::AnyMap& compilationConfig) {
173159
// no need to load but we need to extract metadata
174160
OVMS_ServableMetadata* servableMetadata = nullptr;
175161
ASSERT_CAPI_STATUS_NULL(OVMS_GetServableMetadata(cserver, servableName.c_str(), servableVersion, &servableMetadata));
162+
CREATE_GUARD(metadataGuard, OVMS_ServableMetadata, servableMetadata);
176163
uint32_t inputCount = 0;
177164
uint32_t outputCount = 0;
178-
// TODO ensure Metadata object removal in all paths
179165
ASSERT_CAPI_STATUS_NULL(OVMS_ServableMetadataInputCount(servableMetadata, &inputCount));
180166
ASSERT_CAPI_STATUS_NULL(OVMS_ServableMetadataOutputCount(servableMetadata, &outputCount));
181167

@@ -190,7 +176,6 @@ void OVMSInferenceAdapter::loadModel(const std::shared_ptr<const ov::Model>& mod
190176
inputNames.emplace_back(tensorName);
191177
shape_min_max_t inputMinMax;
192178
for (size_t i = 0; i < dimCount; ++i) {
193-
// TODO test adapter dynamic shapes
194179
inputMinMax.first.emplace_back(shapeMin[i]);
195180
inputMinMax.second.emplace_back(shapeMax[i]);
196181
}
@@ -203,7 +188,6 @@ void OVMSInferenceAdapter::loadModel(const std::shared_ptr<const ov::Model>& mod
203188
const ov::AnyMap* servableMetadataRtInfo;
204189
ASSERT_CAPI_STATUS_NULL(OVMS_ServableMetadataInfo(servableMetadata, reinterpret_cast<const void**>(&servableMetadataRtInfo)));
205190
this->modelConfig = *servableMetadataRtInfo;
206-
OVMS_ServableMetadataDelete(servableMetadata);
207191
}
208192

209193
ov::PartialShape OVMSInferenceAdapter::getInputShape(const std::string& inputName) const {
@@ -294,7 +278,7 @@ static ov::element::Type_t CAPI2OVPrecision(OVMS_DataType datatype) {
294278
return it->second;
295279
}
296280

297-
static ov::Tensor makeOvTensorO(OVMS_DataType datatype, const int64_t* shape, size_t dimCount, const void* voutputData, size_t bytesize) {
281+
static ov::Tensor makeOvTensor(OVMS_DataType datatype, const int64_t* shape, size_t dimCount, const void* voutputData, size_t bytesize) {
298282
ov::Shape ovShape;
299283
for (size_t i = 0; i < dimCount; ++i) {
300284
ovShape.push_back(shape[i]);

mediapipe/calculators/ovms/modelapiovmsadapter.hpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include <utility>
2424
#include <vector>
2525

26-
#include <adapters/inference_adapter.h> // TODO fix path model_api/model_api/cpp/adapters/include/adapters/inference_adapter.h
26+
#include <adapters/inference_adapter.h> // model_api/model_api/cpp/adapters/include/adapters/inference_adapter.h
2727
#include <openvino/openvino.hpp>
2828

2929
// here we need to decide if we have several calculators (1 for OVMS repository, 1-N inside mediapipe)
@@ -37,8 +37,6 @@ namespace ovms {
3737
using InferenceOutput = std::map<std::string, ov::Tensor>;
3838
using InferenceInput = std::map<std::string, ov::Tensor>;
3939

40-
// TODO
41-
// * why std::map
4240
using shape_border_t = std::vector<int64_t>;
4341
using shape_min_max_t = std::pair<shape_border_t, shape_border_t>;
4442
using shapes_min_max_t = std::unordered_map<std::string, shape_min_max_t>;

mediapipe/calculators/ovms/openvinoinferencecalculator.cc

+3-6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include <sstream>
2121
#include <unordered_map>
2222

23-
#include <adapters/inference_adapter.h> // TODO fix path model_api/model_api/cpp/adapters/include/adapters/inference_adapter.h
23+
#include <adapters/inference_adapter.h> // model_api/model_api/cpp/adapters/include/adapters/inference_adapter.h
2424
#include <openvino/core/shape.hpp>
2525
#include <openvino/openvino.hpp>
2626

@@ -317,7 +317,7 @@ static ov::Tensor convertTFLiteTensor2OVTensor(const TfLiteTensor& t) {
317317
ov::Shape shape;
318318
// for some reason TfLite tensor does not have bs dim
319319
shape.emplace_back(1);
320-
// TODO: Support scalars and no data tensors with 0-dim
320+
// No support for scalars and no data tensors with 0-dim
321321
for (int i = 0; i < t.dims->size; ++i) {
322322
shape.emplace_back(t.dims->data[i]);
323323
}
@@ -570,7 +570,6 @@ class OpenVINOInferenceCalculator : public CalculatorBase {
570570
cc->Outputs().Tag(tag).Add(
571571
tensors.release(),
572572
cc->InputTimestamp());
573-
//break; // TODO FIXME order of outputs
574573
// no need to break since we only have one tag
575574
// create concatenator calc
576575
} else if (startsWith(tag, MPTENSORS_TAG)) {
@@ -599,11 +598,9 @@ class OpenVINOInferenceCalculator : public CalculatorBase {
599598
cc->Outputs().Tag(tag).Add(
600599
tensors.release(),
601600
cc->InputTimestamp());
602-
//break; // TODO FIXME order of outputs
603601
// no need to break since we only have one tag
604602
// create concatenator calc
605603
} else if (startsWith(tag, TFLITE_TENSORS_TAG)) {
606-
// TODO FIXME use output_order_list
607604
LOG(INFO) << "OVMS calculator will process vector<TfLiteTensor>";
608605
auto outputStreamTensors = std::vector<TfLiteTensor>();
609606
if (!this->initialized) {
@@ -619,7 +616,7 @@ class OpenVINOInferenceCalculator : public CalculatorBase {
619616
}
620617
interpreter_->SetTensorParametersReadWrite(
621618
tensorId,
622-
kTfLiteFloat32, // TODO datatype
619+
kTfLiteFloat32,
623620
name.c_str(),
624621
tfliteshape,
625622
TfLiteQuantization());

mediapipe/calculators/ovms/openvinomodelserversessioncalculator.proto

+2
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,7 @@ message OpenVINOModelServerSessionCalculatorOptions {
2929
optional string servable_version = 2;
3030
// service_url: "13.21.212.171:9718"
3131
optional string service_url = 3;
32+
// config_path: "/models/config.json"
33+
// when this field is used ensure that each calculator is using the same file
3234
optional string server_config = 4;
3335
}

mediapipe/calculators/ovms/openvinomodelserversessioncalculator_test.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
#include "mediapipe/framework/port/gtest.h"
2525

26-
#include <adapters/inference_adapter.h> // TODO fix path model_api/model_api/cpp/adapters/include/adapters/inference_adapter.h
26+
#include <adapters/inference_adapter.h> // model_api/model_api/cpp/adapters/include/adapters/inference_adapter.h
2727
#include <openvino/core/shape.hpp>
2828
#include <openvino/openvino.hpp>
2929

0 commit comments

Comments
 (0)