@@ -47,7 +47,6 @@ void printDebugInfo(const ov::CompiledModel& obj) {
4747 continue ;
4848 OPENVINO_SUPPRESS_DEPRECATED_END
4949 std::cout << " " << item2.first << " : " << item2.second .as <std::string>() << std::endl;
50- }
5150 }
5251 } else {
5352 std::cout << " " << cfg << " : " << prop.as <std::string>() << std::endl;
@@ -101,10 +100,10 @@ OVExeNetwork OVCore::StatefulCompileModel(std::shared_ptr<OVNetwork>& model,
101100 LogBasicModelInfo (model);
102101 }
103102
104- LOGS_DEFAULT (INFO) << log_tag << " Converting from Stateless OV Model to Stateful OV Model" << std::endl;
105103 bool model_status = IsStateful (model);
106104 LOGS_DEFAULT (INFO) << log_tag << " Model IsStateful() Status:\t " << (model_status ? " True" : " False" );
107105 if (!model_status) {
106+ LOGS_DEFAULT (INFO) << log_tag << " Converting from Stateless OV Model to Stateful OV Model" << std::endl;
108107 PatchStatefulDecoder (model);
109108 }
110109
@@ -198,15 +197,69 @@ OVExeNetwork OVCore::ImportModel(std::istream& model_stream,
198197 return OvExceptionBoundary ([&]() {
199198 ov::CompiledModel obj;
200199 obj = core.import_model (model_stream, hw_target, device_config);
200+ OVExeNetwork exe (obj, hw_target);
201201#ifndef NDEBUG
202202 printDebugInfo (exe.Get ());
203203#endif
204- OVExeNetwork exe (obj, hw_target);
205204 return exe;
206205 },
207206 " Exception while Loading Network for graph {}" , name);
208207}
209208
209+ OVExeNetwork OVCore::ImportEPCtxOVIREncapsulation (std::istream& model_stream,
210+ std::string& hw_target,
211+ const ov::AnyMap& device_config,
212+ bool enable_causallm,
213+ std::filesystem::path model_file_path) {
214+ return OvExceptionBoundary ([&]() {
215+ OVExeNetwork exe;
216+
217+ bool isXML = backend_utils::IsModelStreamXML (model_stream);
218+
219+ // Helper function to check if file exists and is readable
220+ const auto check_file_access = [&model_file_path](const std::filesystem::path& path) {
221+ try {
222+ if (!std::filesystem::exists (path) || std::filesystem::is_empty (path)) {
223+ ORT_THROW (log_tag + " Required file missing or empty: " + path.string ());
224+ }
225+ std::ifstream file (path);
226+ if (!file) {
227+ ORT_THROW (log_tag + " Required file not readable: " + path.string ());
228+ }
229+ } catch (const std::exception& e) {
230+ ORT_THROW (log_tag + " Exception while checking file access for: " + path.string () + " - " + e.what ());
231+ }
232+ };
233+
234+ if (isXML) {
235+ // If the model is XML, we need to load it with the XML content in read_model()
236+ // where weights from bin file is directly consumed
237+ auto xml_file_path = model_file_path.parent_path () / (model_file_path.stem ().string () + " .xml" );
238+
239+ check_file_access (xml_file_path);
240+
241+ LOGS_DEFAULT (INFO) << log_tag << " Reading OVIR from XML file path: " << xml_file_path.string ();
242+
243+ // Load the model explicitly with XML contents
244+ std::shared_ptr<ov::Model> model = core.read_model (xml_file_path.string ());
245+
246+ if (enable_causallm) {
247+ exe = OVCore::Get ()->StatefulCompileModel (model, hw_target, device_config);
248+ } else {
249+ auto obj = core.compile_model (model, hw_target, device_config);
250+ exe = OVExeNetwork (obj, hw_target);
251+ }
252+ }
253+
254+ #ifndef NDEBUG
255+ printDebugInfo (exe.Get ());
256+ #endif
257+ return exe;
258+ },
259+ " Exception while Loading Network from OVIR model file: {}" , model_file_path.string ());
260+ }
261+
262+
210263void OVCore::SetCache (const std::string& cache_dir_path) {
211264 core.set_property (ov::cache_dir (cache_dir_path));
212265}
0 commit comments