Skip to content

Commit 57ff056

Browse files
razvanapetroaieDanLiu2Intel
authored andcommitted
Fallback to weights copies on all unhandled cases
1 parent fe0e2a4 commit 57ff056

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/plugins/intel_npu/src/compiler_adapter/include/xml_serializer.hpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,23 @@ class XmlSerializer : public ov::util::XmlSerializer {
4040
false,
4141
ov::element::dynamic,
4242
false),
43+
m_base_constant_writer(std::ref(constant_write_handler)),
4344
m_weightless_constant_writer(weightless_constant_writer
4445
? weightless_constant_writer
4546
: std::make_shared<WeightlessWriter>(constant_write_handler)) {}
4647

4748
private:
49+
/**
50+
* @brief Toggles between the two writers.
51+
*/
4852
ov::util::ConstantWriter& get_constant_write_handler() override;
4953

54+
/**
55+
* @brief Overriden in order to choose which weights writer will be used based on the occurrence of the
56+
* "WeightsPointerAttribute".
57+
*/
58+
bool append_node_attributes(ov::Node& node) override;
59+
5060
std::unique_ptr<ov::util::XmlSerializer> make_visitor(pugi::xml_node& data,
5161
const std::string& node_type_name,
5262
ov::util::ConstantWriter& constant_write_handler,
@@ -56,7 +66,15 @@ class XmlSerializer : public ov::util::XmlSerializer {
5666
ov::element::Type,
5767
bool) const override;
5868

69+
/**
70+
* @brief The base OV writer, copies the weights in a dedicated buffer.
71+
*
72+
* @note Ideally, we would not require this writer at all. The current algorithm does not handle subgraphs properly,
73+
* so falling back to copying a part of the weights is a temporary fix.
74+
*/
75+
std::reference_wrapper<ov::util::ConstantWriter> m_base_constant_writer;
5976
std::shared_ptr<WeightlessWriter> m_weightless_constant_writer = nullptr;
77+
bool m_use_weightless_writer = false;
6078
};
6179

6280
/**

src/plugins/intel_npu/src/compiler_adapter/src/xml_serializer.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,20 @@
1010
namespace intel_npu {
1111

1212
ov::util::ConstantWriter& XmlSerializer::get_constant_write_handler() {
13-
return *m_weightless_constant_writer;
13+
if (m_use_weightless_writer) {
14+
return *m_weightless_constant_writer;
15+
} else {
16+
return m_base_constant_writer;
17+
}
18+
}
19+
20+
bool XmlSerializer::append_node_attributes(ov::Node& node) {
21+
// If the "WeightsPointerAttribute" is found, then we have the metadata required to avoid copying the weights
22+
// corresponding to this node.
23+
m_use_weightless_writer = node.get_rt_info().count(WeightsPointerAttribute::get_type_info_static()) != 0;
24+
auto result = ov::util::XmlSerializer::append_node_attributes(node);
25+
m_use_weightless_writer = false;
26+
return result;
1427
}
1528

1629
std::unique_ptr<ov::util::XmlSerializer> XmlSerializer::make_visitor(pugi::xml_node& data,

0 commit comments

Comments
 (0)