Skip to content

Commit ffeb3a4

Browse files
committed
simplify interface export. only keep pipeline export.
Signed-off-by: xiping.yan <xiping.yan@intel.com>
1 parent 6770251 commit ffeb3a4

File tree

7 files changed

+126
-32
lines changed

7 files changed

+126
-32
lines changed

src/cpp/include/openvino/genai/module_genai/pipeline.hpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,13 @@
77

88
#include "openvino/genai/generation_config.hpp"
99
#include "openvino/genai/llm_pipeline.hpp"
10-
#include "openvino/genai/module_genai/module_base.hpp"
1110

1211
namespace ov {
1312
namespace genai {
1413

1514
namespace module {
1615

17-
using PipelineModuleInstance = std::vector<IBaseModule::PTR>;
18-
1916
class OPENVINO_GENAI_EXPORTS ModulePipeline {
20-
private:
21-
PipelineModuleInstance m_modules;
2217

2318
public:
2419
// config_path: yaml file.
@@ -39,7 +34,7 @@ class OPENVINO_GENAI_EXPORTS ModulePipeline {
3934
void finish_chat();
4035

4136
private:
42-
std::map<std::string, ov::Any> outputs;
37+
void* m_pipeline_impl = nullptr;
4338
};
4439

4540
} // namespace module

src/cpp/src/module_genai/module.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
#include <unordered_map>
88
#include <vector>
99

10-
11-
#include "openvino/genai/module_genai/pipeline.hpp"
10+
#include "module_base.hpp"
1211

1312
namespace ov {
1413
namespace genai {
1514

1615
namespace module {
1716

17+
using PipelineModuleInstance = std::vector<IBaseModule::PTR>;
18+
1819
using PipelineModuleDesc = std::unordered_map<std::string, IBaseModuleDesc::PTR>;
1920

2021
void construct_pipeline(const PipelineModuleDesc& pipeline_desc, PipelineModuleInstance& pipeline_instance);

src/cpp/include/openvino/genai/module_genai/module_base.hpp renamed to src/cpp/src/module_genai/module_base.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,17 @@ class OPENVINO_GENAI_EXPORTS IBaseModuleDesc {
5050
}
5151
};
5252

53-
class OPENVINO_GENAI_EXPORTS IBaseModule {
53+
class IBaseModule {
5454
public:
5555
~IBaseModule() = default;
5656
using PTR = std::shared_ptr<IBaseModule>;
57-
struct OPENVINO_GENAI_EXPORTS InputModule {
57+
struct InputModule {
5858
IBaseModule::PTR module_ptr;
5959
// std::string out_port_name;
6060
DataType dt_type;
6161
ov::Any data;
6262
};
63-
struct OPENVINO_GENAI_EXPORTS OutputModule {
63+
struct OutputModule {
6464
IBaseModule::PTR module_ptr;
6565
// std::string in_port_name;
6666
DataType dt_type;

src/cpp/src/module_genai/pipeline.cpp

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
#include <optional>
77

88
#include "module.hpp"
9-
#include "utils/yaml_utils.hpp"
109
#include "modules/md_io.hpp"
10+
#include "pipeline_impl.hpp"
11+
#include "utils/yaml_utils.hpp"
1112

1213
namespace ov {
1314
namespace genai {
@@ -16,40 +17,40 @@ namespace module {
1617

1718
// config_path: yaml file.
1819
ModulePipeline::ModulePipeline(const std::filesystem::path& config_path) {
19-
auto pipeline_desc = utils::load_config(config_path);
20-
21-
// Construct pipeline
22-
construct_pipeline(pipeline_desc, m_modules);
23-
24-
// Sort pipeline
25-
m_modules = sort_pipeline(m_modules);
20+
ModulePipelineImpl* pImpl = new ModulePipelineImpl(config_path);
21+
OPENVINO_ASSERT(pImpl != NULL, "Create ModulePipelineImpl return null.");
22+
m_pipeline_impl = (ModulePipelineImpl*)pImpl;
2623
}
2724

28-
ModulePipeline::~ModulePipeline() {}
25+
ModulePipeline::~ModulePipeline() {
26+
auto* pImpl = (ModulePipelineImpl*)m_pipeline_impl;
27+
delete pImpl;
28+
m_pipeline_impl = nullptr;
29+
}
2930

3031
// input all parameters in config.yaml
3132
// "prompt": string
3233
// "image": image ov::Tensor or std::vector<ov::Tensor>
3334
// "video": video ov::Tensor
3435
void ModulePipeline::generate(ov::AnyMap& inputs, StreamerVariant streamer) {
35-
for (auto& module : m_modules) {
36-
if (module->is_input_module) {
37-
std::dynamic_pointer_cast<ParameterModule>(module)->run(inputs);
38-
} else if (module->is_output_module) {
39-
std::dynamic_pointer_cast<ResultModule>(module)->run(this->outputs);
40-
} else {
41-
module->run();
42-
}
43-
}
36+
auto* pImpl = (ModulePipelineImpl*)m_pipeline_impl;
37+
pImpl->generate(inputs, streamer);
4438
}
4539

4640
ov::Any ModulePipeline::get_output(const std::string& output_name) {
47-
return outputs[output_name];
41+
auto* pImpl = (ModulePipelineImpl*)m_pipeline_impl;
42+
return pImpl->get_output(output_name);
4843
}
4944

50-
void ModulePipeline::start_chat(const std::string& system_message) {}
45+
void ModulePipeline::start_chat(const std::string& system_message) {
46+
auto* pImpl = (ModulePipelineImpl*)m_pipeline_impl;
47+
return pImpl->start_chat(system_message);
48+
}
5149

52-
void ModulePipeline::finish_chat() {}
50+
void ModulePipeline::finish_chat() {
51+
auto* pImpl = (ModulePipelineImpl*)m_pipeline_impl;
52+
return pImpl->finish_chat();
53+
}
5354

5455
} // namespace module
5556
} // namespace genai
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright (C) 2023-2025 Intel Corporation
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
#include "pipeline_impl.hpp"
5+
6+
#include "module.hpp"
7+
#include "utils/yaml_utils.hpp"
8+
#include "modules/md_io.hpp"
9+
10+
namespace ov {
11+
namespace genai {
12+
13+
namespace module {
14+
15+
// config_path: yaml file.
16+
ModulePipelineImpl::ModulePipelineImpl(const std::filesystem::path& config_path) {
17+
auto pipeline_desc = utils::load_config(config_path);
18+
19+
// Construct pipeline
20+
construct_pipeline(pipeline_desc, m_modules);
21+
22+
// Sort pipeline
23+
m_modules = sort_pipeline(m_modules);
24+
}
25+
26+
ModulePipelineImpl::~ModulePipelineImpl() {}
27+
28+
// input all parameters in config.yaml
29+
// "prompt": string
30+
// "image": image ov::Tensor or std::vector<ov::Tensor>
31+
// "video": video ov::Tensor
32+
void ModulePipelineImpl::generate(ov::AnyMap& inputs, StreamerVariant streamer) {
33+
for (auto& module : m_modules) {
34+
if (module->is_input_module) {
35+
std::dynamic_pointer_cast<ParameterModule>(module)->run(inputs);
36+
} else if (module->is_output_module) {
37+
std::dynamic_pointer_cast<ResultModule>(module)->run(this->outputs);
38+
} else {
39+
module->run();
40+
}
41+
}
42+
}
43+
44+
ov::Any ModulePipelineImpl::get_output(const std::string& output_name) {
45+
return outputs[output_name];
46+
}
47+
48+
void ModulePipelineImpl::start_chat(const std::string& system_message) {}
49+
50+
void ModulePipelineImpl::finish_chat() {}
51+
52+
} // namespace module
53+
} // namespace genai
54+
} // namespace ov
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright (C) 2023-2025 Intel Corporation
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
#include <optional>
5+
6+
#include "module.hpp"
7+
#include "modules/md_io.hpp"
8+
#include "utils/yaml_utils.hpp"
9+
10+
namespace ov {
11+
namespace genai {
12+
13+
namespace module {
14+
class ModulePipelineImpl {
15+
private:
16+
PipelineModuleInstance m_modules;
17+
18+
public:
19+
// config_path: yaml file.
20+
ModulePipelineImpl(const std::filesystem::path& config_path);
21+
22+
~ModulePipelineImpl();
23+
24+
// input all parameters in config.yaml
25+
// "prompt": string
26+
// "image": image ov::Tensor or std::vector<ov::Tensor>
27+
// "video": video ov::Tensor
28+
void generate(ov::AnyMap& inputs, StreamerVariant streamer = std::monostate());
29+
30+
ov::Any get_output(const std::string& output_name);
31+
32+
void start_chat(const std::string& system_message = {});
33+
34+
void finish_chat();
35+
36+
private:
37+
std::map<std::string, ov::Any> outputs;
38+
};
39+
40+
} // namespace module
41+
} // namespace genai
42+
} // namespace ov

src/cpp/src/module_genai/utils/data_type_converter.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <vector>
1010

1111
#include "openvino/genai/module_genai/pipeline.hpp"
12+
#include "module_genai/module_base.hpp"
1213

1314
namespace ov {
1415
namespace genai {

0 commit comments

Comments
 (0)