Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions common_settings.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ WINDOWS_COMMON_STATIC_LIBS_COPTS = [
"/wd4702",
"/wd4267",
"/wd4996",
"/wd6385",
"/wd6001",
"/wd6386",
"/wd4099",
]

COMMON_STATIC_LIBS_COPTS = select({
Expand Down
52 changes: 37 additions & 15 deletions src/image_gen/http_image_gen_calculator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,37 @@ using ImageGenerationPipelinesMap = std::unordered_map<std::string, std::shared_

const std::string IMAGE_GEN_SESSION_SIDE_PACKET_TAG = "IMAGE_GEN_NODE_RESOURCES";

static bool progress_bar(size_t step, size_t num_steps, ov::Tensor& /* latent */) {
static bool progress_bar(size_t step, size_t num_steps, ov::Tensor&) {
SPDLOG_LOGGER_DEBUG(llm_calculator_logger, "Image Generation Step: {}/{}", step, num_steps);
return false;
}
// written out separately to avoid msvc crashing when using try-catch in process method ...
static absl::Status generateTensor(ov::genai::Text2ImagePipeline& request,
const std::string& prompt, ov::AnyMap& requestOptions,
std::unique_ptr<ov::Tensor>& images) {
try {
requestOptions.insert(ov::genai::callback(progress_bar));
images = std::make_unique<ov::Tensor>(request.generate(prompt, requestOptions));
} catch (const std::exception& e) {
SPDLOG_LOGGER_ERROR(llm_calculator_logger, "ImageGenCalculator Error: {}", e.what());
return absl::InternalError("Error during images generation");
} catch (...) {
return absl::InternalError("Unknown error during image generation");
}
return absl::OkStatus();
}
// written out separately to avoid msvc crashing when using try-catch in process method ...
static absl::Status convert2String(const std::unique_ptr<ov::Tensor>& images, std::unique_ptr<std::string>& imageAsString) {
try {
*imageAsString = saveImageStbi(*images);
} catch (std::exception& e) {
SPDLOG_LOGGER_ERROR(llm_calculator_logger, "ImageGenCalculator Error: {}", e.what());
return absl::InternalError("Error during image conversion");
} catch (...) {
return absl::InternalError("Unknown error during image conversion");
}
return absl::OkStatus();
}

class ImageGenCalculator : public CalculatorBase {
static const std::string INPUT_TAG_NAME;
Expand Down Expand Up @@ -105,32 +132,27 @@ class ImageGenCalculator : public CalculatorBase {
if (numImages != 1) {
return absl::InvalidArgumentError(absl::StrCat("Only 1 image in response can be requested. n value:", numImages, " is not supported."));
}
}
}

std::unique_ptr<ov::Tensor> images;
try {
requestOptions.insert(ov::genai::callback(progress_bar));
images = std::make_unique<ov::Tensor>(request.generate(prompt, requestOptions));
} catch (const std::exception& e) {
SPDLOG_LOGGER_ERROR(llm_calculator_logger, "ImageGenCalculator [Node: {}] Error: {}", cc->NodeName(), e.what());
return absl::InternalError(absl::StrCat("Error during images generation: ", e.what()));
auto status = generateTensor(request, prompt, requestOptions, images);
if (!status.ok()) {
return status;
}
// temp try-catch to rework to statuses later TODO
auto imageAsString = std::make_unique<std::string>();
try {
*imageAsString = saveImageStbi(*images);
} catch (const std::exception& e) {
SPDLOG_LOGGER_ERROR(llm_calculator_logger, "ImageGenCalculator [Node: {}] Error: {}", cc->NodeName(), e.what());
return absl::InternalError(absl::StrCat("Error during image conversion: ", e.what()));
status = convert2String(images, imageAsString);
if (!status.ok()) {
return status;
}

// Convert the images to a base64 strings
std::string base64image;
absl::Base64Escape(*imageAsString, &base64image);
// Create the JSON response
auto output = generateJSONResponseFromB64Image(base64image);
cc->Outputs().Tag(OUTPUT_TAG_NAME).Add(output.release(), cc->InputTimestamp());

SPDLOG_LOGGER_DEBUG(llm_calculator_logger, "ImageGenCalculator [Node: {}] Process end", cc->NodeName());

return absl::OkStatus();
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/llm/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ cc_library(
"@stb//:image",
":response_parsers",
] + select({
"//conditions:default": ["//third_party:genai", ":llm_engine"],
"//conditions:default": ["//third_party:genai", "@llm_engine//:llm_engine"],
"//:not_genai_bin" : [":llm_engine"],
}),
visibility = ["//visibility:public"],
Expand Down
2 changes: 1 addition & 1 deletion third_party/genai/genai_windows.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ cc_library(
visibility = ["//visibility:public"],
deps = [
# ":genai_lib",
":genai_headers",
# ":genai_headers",
],
)

2 changes: 2 additions & 0 deletions third_party/llm_engine/llm_engine.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ cc_library(
"@ovms//third_party:openvino",
":llm_engine_cmake",
],
hdrs = glob(["include/openvino/**/*.*"]),
strip_include_prefix = "include",
visibility = ["//visibility:public"],
)
"""
Expand Down
9 changes: 9 additions & 0 deletions third_party/openvino/openvino_windows.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ cc_library(
name = "openvino_new_headers",
hdrs = glob([
"include/openvino/**/*.*"
], exclude = ["**/genai/**/*.*"]),
strip_include_prefix = "include",
visibility = ["//visibility:public"],
)

cc_library(
name = "openvino_genai_headers",
hdrs = glob([
"include/openvino/genai/*.*"
]),
strip_include_prefix = "include",
visibility = ["//visibility:public"],
Expand Down