-
Notifications
You must be signed in to change notification settings - Fork 200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mkulakow/mediapipe kfs rest test #2377
Changes from 3 commits
8e15ca5
ddefb38
802e99f
3b440fd
ed96629
24361f3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -383,6 +383,9 @@ static Status deserializeTensor(const std::string& requestedName, const KFSReque | |
case TFSDataType::DT_FLOAT: { | ||
COPY_INPUT_VALUE_BY_VALUE(float, fp32); | ||
} | ||
case TFSDataType::DT_DOUBLE: { | ||
COPY_INPUT_VALUE_BY_VALUE(double, fp64); | ||
} | ||
case TFSDataType::DT_INT64: { | ||
COPY_INPUT_VALUE_BY_VALUE(int64_t, int64); | ||
} | ||
|
@@ -410,7 +413,6 @@ static Status deserializeTensor(const std::string& requestedName, const KFSReque | |
case TFSDataType::DT_BOOL: { | ||
COPY_INPUT_VALUE_BY_VALUE(bool, bool); | ||
} | ||
case TFSDataType::DT_DOUBLE: | ||
case TFSDataType::DT_HALF: | ||
default: | ||
return ovms::Status(ovms::StatusCode::NOT_IMPLEMENTED, "There is no support for types different than fp32, int64, int32, uint32, uint64, int8, uint8, bool"); | ||
|
@@ -455,10 +457,10 @@ static Status deserializeTensor(const std::string& requestedName, const KFSReque | |
} | ||
} else { | ||
OVMS_RETURN_ON_FAIL(validateInputContent(*requestInputItr, expectedBytes, requestedName, request)); | ||
outTensor = std::make_unique<ov::Tensor>(precision, shape); | ||
if (expectedBytes == 0) { | ||
return StatusCode::OK; | ||
} | ||
outTensor = std::make_unique<ov::Tensor>(precision, shape); | ||
void* data = outTensor->data(); | ||
switch (precision) { | ||
case ov::element::Type_t::f32: { | ||
|
@@ -491,12 +493,14 @@ static Status deserializeTensor(const std::string& requestedName, const KFSReque | |
case ov::element::Type_t::boolean: { | ||
COPY_INPUT_VALUE_BY_VALUE(bool, bool); | ||
} | ||
case ov::element::Type_t::f64: { | ||
COPY_INPUT_VALUE_BY_VALUE(double, fp64); | ||
} | ||
// the rest not supported by KFS | ||
case ov::element::Type_t::u1: | ||
case ov::element::Type_t::u4: | ||
case ov::element::Type_t::i4: | ||
case ov::element::Type_t::f16: | ||
case ov::element::Type_t::f64: | ||
case ov::element::Type_t::bf16: | ||
case ov::element::Type_t::undefined: | ||
case ov::element::Type_t::dynamic: | ||
|
@@ -689,20 +693,32 @@ static Status deserializeTensor(const std::string& requestedName, const KFSReque | |
SPDLOG_DEBUG("[servable name: {} version: {}] {}", request.model_name(), request.model_version(), details); | ||
return Status(StatusCode::INVALID_PRECISION, details); | ||
} | ||
size_t expectedBytes = 1; | ||
bool expectedBufferSizeValid = computeExpectedBufferSizeReturnFalseIfOverflow<py::ssize_t>(shape, precision.size(), expectedBytes); | ||
if (!expectedBufferSizeValid) { | ||
const std::string details = "Provided shape and datatype declare too large buffer."; | ||
SPDLOG_DEBUG("[servable name: {} version: {}] {}", request.model_name(), request.model_version(), details); | ||
return Status(StatusCode::INVALID_CONTENT_SIZE, details); | ||
size_t expectedBytes; | ||
if (precision == ov::element::Type_t::string) { | ||
expectedBytes = 0; | ||
for (auto contents : request.inputs(inputIndex).contents().bytes_contents()) { | ||
expectedBytes = expectedBytes + contents.size() + sizeof(uint32_t); | ||
} | ||
} else { | ||
expectedBytes = 1; | ||
bool expectedBufferSizeValid = computeExpectedBufferSizeReturnFalseIfOverflow<py::ssize_t>(shape, precision.size(), expectedBytes); | ||
if (!expectedBufferSizeValid) { | ||
const std::string details = "Provided shape and datatype declare too large buffer."; | ||
SPDLOG_DEBUG("[servable name: {} version: {}] {}", request.model_name(), request.model_version(), details); | ||
return Status(StatusCode::INVALID_CONTENT_SIZE, details); | ||
} | ||
OVMS_RETURN_ON_FAIL(validateInputContent(*requestInputItr, expectedBytes, requestedName, request)); | ||
} | ||
OVMS_RETURN_ON_FAIL(validateInputContent(*requestInputItr, expectedBytes, requestedName, request)); | ||
auto ok = pythonBackend->createEmptyOvmsPyTensor( | ||
requestedName, | ||
shape, | ||
requestInputItr->datatype(), | ||
expectedBytes, | ||
outTensor); | ||
if (!ok) { | ||
SPDLOG_DEBUG("Error creating empty Python tensor"); | ||
return StatusCode::UNKNOWN_ERROR; | ||
} | ||
void* data; | ||
if (!pythonBackend->getOvmsPyTensorData(outTensor, &data)) { | ||
return Status(StatusCode::INTERNAL_ERROR); | ||
|
@@ -711,6 +727,9 @@ static Status deserializeTensor(const std::string& requestedName, const KFSReque | |
case ov::element::Type_t::f32: { | ||
COPY_INPUT_VALUE_BY_VALUE(float, fp32); | ||
} | ||
case ov::element::Type_t::f64: { | ||
COPY_INPUT_VALUE_BY_VALUE(double, fp64); | ||
} | ||
case ov::element::Type_t::i64: { | ||
COPY_INPUT_VALUE_BY_VALUE(int64_t, int64); | ||
} | ||
|
@@ -738,13 +757,23 @@ static Status deserializeTensor(const std::string& requestedName, const KFSReque | |
case ov::element::Type_t::boolean: { | ||
COPY_INPUT_VALUE_BY_VALUE(bool, bool); | ||
} | ||
case ov::element::Type_t::string: { | ||
uint32_t offset = 0; | ||
for (auto contents : request.inputs(inputIndex).contents().bytes_contents()) { | ||
uint32_t size = contents.size(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is used only below as a buffer to copy from. Do we need that? If so, can we make it const and replace following There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can it be const? |
||
std::memcpy(reinterpret_cast<char*>(data) + offset, &size, sizeof(uint32_t)); | ||
offset += sizeof(uint32_t); | ||
std::memcpy(reinterpret_cast<char*>(data) + offset, contents.data(), contents.size()); | ||
offset += contents.size(); | ||
} | ||
return StatusCode::OK; | ||
} | ||
|
||
// the rest not supported by KFS | ||
case ov::element::Type_t::u1: | ||
case ov::element::Type_t::u4: | ||
case ov::element::Type_t::i4: | ||
case ov::element::Type_t::f16: | ||
case ov::element::Type_t::f64: | ||
case ov::element::Type_t::bf16: | ||
case ov::element::Type_t::undefined: | ||
case ov::element::Type_t::dynamic: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,7 @@ const std::unordered_map<std::string, std::string> datatypeToBufferFormat{ | |
{"FP16", "e"}, | ||
{"FP32", "f"}, | ||
{"FP64", "d"}, | ||
{"BYTES", "s"}, | ||
// {"BF16", X} to be considered, for now it shall be treated as a custom datatype | ||
}; | ||
|
||
|
@@ -64,6 +65,7 @@ const std::unordered_map<std::string, std::string> bufferFormatToDatatype{ | |
{"e", "FP16"}, | ||
{"f", "FP32"}, | ||
{"d", "FP64"}, | ||
{"s", "BYTES"}, | ||
// {X, "BF16"} to be considered, for now it shall be treated as a custom datatype | ||
}; | ||
|
||
|
@@ -83,6 +85,7 @@ const std::unordered_map<std::string, py::ssize_t> bufferFormatToItemsize{ | |
{"e", 2}, | ||
{"f", 4}, | ||
{"d", 8}, | ||
{"s", 1}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How is it 1? |
||
// {"BF16", X} to be considered, for now it shall be treated as a custom datatype | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't size written in first bytes of the input? If so I suggest keeping the order also here.