Skip to content

Commit 2f16435

Browse files
committed
Eliminate weightless attr
1 parent e40ac7f commit 2f16435

File tree

9 files changed

+82
-9
lines changed

9 files changed

+82
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (C) 2018-2025 Intel Corporation
2+
// SPDX-License-Identifier: Apache-2.0
3+
//
4+
5+
#pragma once
6+
7+
#include "openvino/pass/matcher_pass.hpp"
8+
#include "transformations_visibility.hpp"
9+
10+
namespace ov {
11+
namespace pass {
12+
13+
/**
14+
* @ingroup ov_transformation_common_api
15+
* @brief EliminateWeightlessAttributes transformation
16+
*
17+
*/
18+
class TRANSFORMATIONS_API EliminateWeightlessAttributes : public ov::pass::MatcherPass {
19+
public:
20+
OPENVINO_MATCHER_PASS_RTTI("EliminateWeightlessAttributes");
21+
EliminateWeightlessAttributes();
22+
};
23+
24+
} // namespace pass
25+
} // namespace ov
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (C) 2018-2025 Intel Corporation
2+
// SPDX-License-Identifier: Apache-2.0
3+
//
4+
5+
#include "transformations/common_optimizations/eliminate_weightless_attributes.hpp"
6+
7+
#include "itt.hpp"
8+
#include "openvino/core/rt_info/weightless_caching_attributes.hpp"
9+
#include "openvino/pass/pattern/op/wrap_type.hpp"
10+
11+
namespace ov::pass {
12+
13+
EliminateWeightlessAttributes::EliminateWeightlessAttributes() {
14+
MATCHER_SCOPE(EliminateWeightlessAttributes);
15+
16+
auto constant_pattern = pattern::wrap_type<op::v0::Constant>(pattern::has_static_shape());
17+
18+
matcher_pass_callback callback = [=](pattern::Matcher& m) {
19+
auto constant = as_type<op::v0::Constant>(m.get_match_root().get());
20+
if (!constant) {
21+
return false;
22+
}
23+
24+
auto& rt_info = constant->get_rt_info();
25+
rt_info.erase(WeightlessCacheAttribute::get_type_info_static());
26+
27+
return true;
28+
};
29+
30+
auto m = std::make_shared<ov::pass::pattern::Matcher>(constant_pattern, matcher_name);
31+
this->register_matcher(m, callback);
32+
}
33+
} // namespace ov::pass

src/core/src/node.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,9 @@ bool ov::Node::constant_fold(OutputVector& output_values, const OutputVector& in
745745
for (size_t i = 0; i < output_tensors.size(); ++i) {
746746
output_values[i] = make_shared<ov::op::v0::Constant>(output_tensors[i]);
747747
ov::copy_runtime_info(nodes, output_values[i].get_node_shared_ptr());
748-
ov::copy_weightless_cache_attr(nodes[0], output_values[i].get_node_shared_ptr());
748+
if (nodes.size() > 0) {
749+
ov::copy_weightless_cache_attr(nodes[0], output_values[i].get_node_shared_ptr());
750+
}
749751
}
750752
return true;
751753
}

src/frontends/ir/src/frontend.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,12 @@ InputModel::Ptr FrontEnd::load_impl(const std::vector<ov::Any>& variants) const
234234
} else if (variant.is<std::wstring>()) {
235235
weights_path = variant.as<std::wstring>();
236236
#endif
237-
} else if (variant.is<std::shared_ptr<ov::AlignedBuffer>>() && !weights) {
238-
weights = variant.as<std::shared_ptr<ov::AlignedBuffer>>();
239-
} else if (variant.is<std::shared_ptr<ov::AlignedBuffer>>() && !origin_weights) {
240-
origin_weights = variant.as<std::shared_ptr<ov::AlignedBuffer>>();
237+
} else if (variant.is<std::shared_ptr<ov::AlignedBuffer>>()) {
238+
if (variant_id == 1) {
239+
weights = variant.as<std::shared_ptr<ov::AlignedBuffer>>();
240+
} else if (variant_id == 2) {
241+
origin_weights = variant.as<std::shared_ptr<ov::AlignedBuffer>>();
242+
}
241243
}
242244
}
243245
bool enable_mmap = variants[variants.size() - 1].is<bool>() ? variants[variants.size() - 1].as<bool>() : false;

src/frontends/ir/src/ir_deserializer.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <regex>
88
#include <string_view>
99

10+
#include "../../../core/reference/include/openvino/reference/convert.hpp"
1011
#include "openvino/core/descriptor_tensor.hpp"
1112
#include "openvino/core/meta_data.hpp"
1213
#include "openvino/core/rt_info/weightless_caching_attributes.hpp"
@@ -20,7 +21,6 @@
2021
#include "openvino/op/util/op_types.hpp"
2122
#include "openvino/op/util/read_value_base.hpp"
2223
#include "openvino/op/util/variable.hpp"
23-
#include "../../../core/reference/include/openvino/reference/convert.hpp"
2424
#include "openvino/runtime/shared_buffer.hpp"
2525
#include "openvino/runtime/string_aligned_buffer.hpp"
2626
#include "openvino/util/xml_parse_utils.hpp"
@@ -402,7 +402,8 @@ void ov::XmlDeserializer::on_adapter(const std::string& name, ov::ValueAccessor<
402402
value.copy(data, value.size());
403403
a->set(buffer);
404404
} else if (name == "value" && type == "Const") {
405-
OPENVINO_ASSERT(m_weights, "Empty weights data in bin file or bin file cannot be found!");
405+
OPENVINO_ASSERT(m_weights != nullptr || m_origin_weights != nullptr,
406+
"Empty weights data in bin file or bin file cannot be found!");
406407
std::vector<int64_t> shape;
407408
std::string el_type_str;
408409

src/plugins/intel_cpu/src/transformations/transformation_pipeline.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "transformations/common_optimizations/common_optimizations.hpp"
3030
#include "transformations/common_optimizations/convert_pagedattn_inputs.hpp"
3131
#include "transformations/common_optimizations/convert_quantize_dequantize.hpp"
32+
#include "transformations/common_optimizations/eliminate_weightless_attributes.hpp"
3233
#include "transformations/common_optimizations/fq_mul_fusion.hpp"
3334
#include "transformations/common_optimizations/fuse_rotary_positional_embeddings.hpp"
3435
#include "transformations/common_optimizations/lora_subgraph_fusion.hpp"
@@ -402,6 +403,9 @@ void Transformations::PreLpt(const std::vector<ov::element::Type>& defaultPrecis
402403

403404
ov::pass::Manager manager("Plugin:CPU");
404405
manager.set_per_pass_validation(false);
406+
if (config.m_cache_mode != ov::CacheMode::OPTIMIZE_SIZE) {
407+
CPU_REGISTER_PASS_COMMON(manager, ov::pass::EliminateWeightlessAttributes);
408+
}
405409
if (useLpt) {
406410
CPU_REGISTER_PASS_COMMON(manager, ov::pass::MarkDequantization, defaultPrecisions);
407411
}

src/plugins/intel_cpu/tests/functional/shared_tests_instances/behavior/compiled_model/model_cache.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
using namespace ov::test::behavior;
99

10-
INSTANTIATE_TEST_SUITE_P(smoke_WeightlessCacheAccuracy,
10+
INSTANTIATE_TEST_SUITE_P(smoke_,
1111
WeightlessCacheAccuracy,
1212
::testing::Combine(::testing::Bool(),
1313
::testing::Bool(),
@@ -16,7 +16,7 @@ INSTANTIATE_TEST_SUITE_P(smoke_WeightlessCacheAccuracy,
1616
::testing::Values(ov::test::utils::DEVICE_CPU)),
1717
WeightlessCacheAccuracy::get_test_case_name);
1818

19-
INSTANTIATE_TEST_SUITE_P(smoke_WeightlessCacheAccuracyLowPrecision,
19+
INSTANTIATE_TEST_SUITE_P(smoke_LowPrecision,
2020
WeightlessCacheAccuracyLowPrecision,
2121
::testing::Combine(::testing::Bool(),
2222
::testing::Bool(),

src/plugins/intel_cpu/tests/functional/shared_tests_instances/skip_tests_config.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ std::vector<std::string> disabledTestPatterns() {
317317
R"(.*FC_3D_BF16.*MatMulLayerCPUTest.*)",
318318
// Issue: 163242
319319
R"(.*bf16.*RNNSequenceCPUTest.*)",
320+
R"(.*WeightlessCacheAccuracy.TiWithLstmCell.*model_dtype=bf16.*)",
320321
// Issue: 163250
321322
R"(.*OnnxModelWithExtensionFromDSO.*)",
322323
// Issue: 163273

src/tests/functional/plugin/shared/src/behavior/compiled_model/model_cache.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "common_test_utils/subgraph_builders/ti_with_lstm_cell.hpp"
1010
#include "common_test_utils/test_assertions.hpp"
1111
#include "common_test_utils/ov_tensor_utils.hpp"
12+
#include "openvino/op/matmul.hpp"
1213
#include "openvino/util/codec_xor.hpp"
1314
#include "shared_test_classes/subgraph/weights_decompression_builders.hpp"
1415

@@ -140,21 +141,25 @@ void WeightlessCacheAccuracy::run() {
140141
}
141142

142143
TEST_P(WeightlessCacheAccuracy, ReadConcatSplitAssign) {
144+
SKIP_IF_CURRENT_TEST_IS_DISABLED()
143145
OV_ASSERT_NO_THROW(m_model = ov::test::utils::make_read_concat_split_assign({1, 1, 2, 4}, m_model_dtype));
144146
OV_ASSERT_NO_THROW(run());
145147
}
146148

147149
TEST_P(WeightlessCacheAccuracy, SingleConcatWithConstant) {
150+
SKIP_IF_CURRENT_TEST_IS_DISABLED()
148151
OV_ASSERT_NO_THROW(m_model = ov::test::utils::make_single_concat_with_constant({1, 1, 2, 4}, m_model_dtype));
149152
OV_ASSERT_NO_THROW(run());
150153
}
151154

152155
TEST_P(WeightlessCacheAccuracy, TiWithLstmCell) {
156+
SKIP_IF_CURRENT_TEST_IS_DISABLED()
153157
OV_ASSERT_NO_THROW(m_model = ov::test::utils::make_ti_with_lstm_cell(m_model_dtype));
154158
OV_ASSERT_NO_THROW(run());
155159
}
156160

157161
TEST_P(WeightlessCacheAccuracyLowPrecision, MatmulWeightsDecompression) {
162+
SKIP_IF_CURRENT_TEST_IS_DISABLED()
158163
ov::test::MatMulDecompressionShapeParams shape_params{{{}, {{1, 4, 16}}}, {1, 16, 32}};
159164
auto dynShape = shape_params.data_shape.first;
160165
if (dynShape.rank() == 0) {

0 commit comments

Comments
 (0)