OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[CPU] Introduce LoRA macro operation (#27110)
Maksim Kutakov60e348b85c15
diff --git a/src/plugins/intel_cpu/src/cpu_types.cpp b/src/plugins/intel_cpu/src/cpu_types.cppindex 953f94cb3d5..e20369c9cca 100644--- a/src/plugins/intel_cpu/src/cpu_types.cpp+++ b/src/plugins/intel_cpu/src/cpu_types.cpp@@ -256,7 +256,8 @@ static const TypeToNameMap& get_type_to_name_tbl() {{"LLMMLP", Type::LLMMLP},{"QKVProjection", Type::QKVProjection},{"RMS", Type::RMS},- {"SearchSorted", Type::SearchSorted}+ {"SearchSorted", Type::SearchSorted},+ {"LoraSubgraph", Type::LoRA}};return type_to_name_tbl;}@@ -389,6 +390,7 @@ std::string NameFromType(const Type type) {CASE(QKVProjection);CASE(RMS);CASE(SearchSorted);+ CASE(LoRA);CASE(Unknown);}#undef CASEdiff --git a/src/plugins/intel_cpu/src/cpu_types.h b/src/plugins/intel_cpu/src/cpu_types.hindex c0a2acc3329..d6ac9947a8f 100644--- a/src/plugins/intel_cpu/src/cpu_types.h+++ b/src/plugins/intel_cpu/src/cpu_types.h@@ -134,6 +134,7 @@ enum class Type {QKVProjection,RMS,SearchSorted,+ LoRA};enum class Algorithm {diff --git a/src/plugins/intel_cpu/src/nodes/composite.cpp b/src/plugins/intel_cpu/src/nodes/composite.cppindex b38a56649bd..a1ceabd6942 100644--- a/src/plugins/intel_cpu/src/nodes/composite.cpp+++ b/src/plugins/intel_cpu/src/nodes/composite.cpp@@ -15,11 +15,23 @@ namespace intel_cpu {namespace node {bool Composite::isSupportedOperation(const std::shared_ptr<const ov::Node>& op, std::string& errorMessage) noexcept {- return ov::is_type<ov::intel_cpu::SubModel>(op);+ try {+ if (!ov::is_type<ov::intel_cpu::SubModel>(op)) {+ errorMessage = "Unknown SubGraph operation : " + std::string(op->get_type_info().name) + " with name '" ++ op->get_friendly_name() + "'";+ }+ } catch (...) {+ return false;+ }+ return true;}Composite::Composite(const std::shared_ptr<ov::Node>& op, const GraphContext::CPtr& context): Node(op, context, InternalDynShapeInferFactory()) {+ std::string errorMessage;+ if (!isSupportedOperation(op, errorMessage)) {+ OPENVINO_THROW_NOT_IMPLEMENTED(errorMessage);+ }const auto& subModel = ov::as_type_ptr<SubModel>(op);OPENVINO_ASSERT(subModel, "Attempt to create SubGraph node from an invalid op type: ", op);@@ -27,7 +39,7 @@ Composite::Composite(const std::shared_ptr<ov::Node>& op, const GraphContext::CP}void Composite::selectOptimalPrimitiveDescriptor() {- // for the input configution, just always use the parent configuration+ // for the input configuration, just always use the parent configurationstd::vector<PortConfig> inConfs;std::vector<Input::InputConfig> graphInputConfig;@@ -38,14 +50,14 @@ void Composite::selectOptimalPrimitiveDescriptor() {}std::vector<Input::OutputConfig> graphOutputConfig;- for (size_t i = 0; i < getParentEdges().size(); i++) {+ for (size_t i = 0; i < outputShapes.size(); i++) {graphOutputConfig.emplace_back(node::Input::OutputConfig{true, true});}// configure the inner graph to get the information about output memory descriptorsm_graph.Init(m_body, context, graphInputConfig, graphOutputConfig);- // for the output decriptors, use the configuration of the graph's output nodes+ // for the output descriptors, use the configuration of the graph's output nodesauto outputDescriptors = m_graph.getOutputMemoryDescriptors();std::vector<PortConfig> outConfs;@@ -89,9 +101,6 @@ void Composite::execute(dnnl::stream) {void Composite::executeDynamicImpl(dnnl::stream strm) {execute(strm);- if (!inputShapesModified())- return;-// since the shape inference is not performed for the composite node// a memory of the extra child edges, attached to the output ports// has to be updated after an inference of the inner graph finisheddiff --git a/src/plugins/intel_cpu/src/nodes/input.cpp b/src/plugins/intel_cpu/src/nodes/input.cppindex 4ee5707e0a9..1f650bd8c5d 100644--- a/src/plugins/intel_cpu/src/nodes/input.cpp+++ b/src/plugins/intel_cpu/src/nodes/input.cpp@@ -430,6 +430,7 @@ Input::Input(const std::shared_ptr<ov::Node>& op,const GraphContext::CPtr context,OutputConfig config): Input(op, context) {+ extMemDesc = config.desc;m_useParentMemoryDescForOutput = config.useParentMemoryDescForOutput;m_isInPlace = config.inPlace;}diff --git a/src/plugins/intel_cpu/src/nodes/input.h b/src/plugins/intel_cpu/src/nodes/input.hindex a954ce56665..4d7febb17ad 100644--- a/src/plugins/intel_cpu/src/nodes/input.h+++ b/src/plugins/intel_cpu/src/nodes/input.h@@ -19,9 +19,17 @@ public:};struct OutputConfig {+ OutputConfig() = default;+ OutputConfig(bool useParentMemoryDesc_, bool inPlace_)+ : useParentMemoryDescForOutput(useParentMemoryDesc_),+ inPlace(inPlace_) {}++ OutputConfig(MemoryDescPtr desc_, bool inPlace_) : desc(std::move(desc_)), inPlace(inPlace_) {}+// @todo better to use memory desc with any layout and undefined precision- bool useParentMemoryDescForOutput;- bool inPlace;+ MemoryDescPtr desc = nullptr;+ bool useParentMemoryDescForOutput = false;+ bool inPlace = false;};Input(const std::shared_ptr<ov::Node>& op, const GraphContext::CPtr context);diff --git a/src/plugins/intel_cpu/src/nodes/lora.cpp b/src/plugins/intel_cpu/src/nodes/lora.cppnew file mode 100644index 00000000000..2c69bc347b6--- /dev/null+++ b/src/plugins/intel_cpu/src/nodes/lora.cpp@@ -0,0 +1,110 @@+// Copyright (C) 2024 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "lora.h"++#include "nodes/input.h"+#include "cpu_memory.h"+#include "ov_ops/lora_subgraph.hpp"+#include "utils/debug_capabilities.h"+#include "shape_inference/shape_inference_pass_through.hpp"++namespace ov {+namespace intel_cpu {+namespace node {++bool LoRA::isSupportedOperation(const std::shared_ptr<const ov::Node>& op, std::string& errorMessage) noexcept {+ try {+ if (!ov::is_type<ov::op::internal::LoraSubgraph>(op)) {+ errorMessage = "Unknown LoRA operation : " + std::string(op->get_type_info().name) + " with name '" ++ op->get_friendly_name() + "'";+ }+ } catch (...) {+ return false;+ }+ return true;+}++LoRA::LoRA(const std::shared_ptr<ov::Node>& op, const GraphContext::CPtr& context)+ : Node(op, context, PassThroughShapeInferFactory()) {+ std::string errorMessage;+ if (!isSupportedOperation(op, errorMessage)) {+ OPENVINO_THROW_NOT_IMPLEMENTED(errorMessage);+ }+ const auto& loraModel = ov::as_type_ptr<ov::op::internal::LoraSubgraph>(op);+ OPENVINO_ASSERT(loraModel,+ "Attempt to create LoRA node from an invalid op type: ",+ op,+ " with name ",+ op->get_friendly_name());++ m_body = loraModel->get_function();+}++void LoRA::selectOptimalPrimitiveDescriptor() {+ // for the input configuration, just always use the parent configuration+ std::vector<PortConfig> inConfs;+ std::vector<Input::InputConfig> graphInputConfig;++ for (size_t i = 0; i < getParentEdges().size(); i++) {+ auto desc = getParentOutputMemDesc(getParentEdgeAt(i));+ inConfs.emplace_back(desc);+ graphInputConfig.emplace_back(node::Input::InputConfig{desc, true});+ }++ std::vector<Input::OutputConfig> graphOutputConfig;+ // enforce the same memory descriptor on the output as on the input to allow inPlace memory+ graphOutputConfig.emplace_back(node::Input::OutputConfig{inConfs.front().getMemDesc(), true});++ // configure the inner graph to get the information about output memory descriptors+ m_graph.Init(m_body, context, graphInputConfig, graphOutputConfig);++ // for the output descriptors, use the configuration of the graph's output nodes+ auto outputDescriptors = m_graph.getOutputMemoryDescriptors();++ const auto& desc = outputDescriptors.front();++ // just a sanity check+ CPU_NODE_ASSERT(desc->isCompatible(*(inConfs.front().getMemDesc())), "Unexpected input/output descriptor mismatch");++ std::vector<PortConfig> outConfs;++ outConfs.emplace_back(desc, BlockedMemoryDesc::FULL_MASK, 0); // use the memory from the first input inPlace++ const NodeConfig config(inConfs, outConfs);++ supportedPrimitiveDescriptors.clear();+ supportedPrimitiveDescriptors.emplace_back(config, impl_desc_type::undef);++ selectPrimitiveDescriptorByIndex(0);+}++// @todo add ascii diagram for memory mapping / reuse+void LoRA::createPrimitive() {+ CPU_NODE_ASSERT(getOriginalInputsNumber() == m_graph.GetInputNodesMap().size(),+ "Number of node inputs must be equal the number of inner graph's inputs");++ std::vector<MemoryPtr> inputMemory;+ for (size_t i = 0; i < getOriginalInputsNumber(); i++) {+ inputMemory.emplace_back(getSrcMemoryAtPort(i));+ }++ CPU_NODE_ASSERT(getOriginalOutputsNumber() == m_graph.GetOutputNodesMap().size(),+ "Number of node outputs must be equal the number of inner graph's outputs");++ std::vector<MemoryPtr> outputMemory{getDstMemoryAtPort(0)};+ m_graph.Activate(inputMemory, outputMemory);+}++void LoRA::execute(dnnl::stream) {+ m_graph.Infer();+}++void LoRA::executeDynamicImpl(dnnl::stream strm) {+ execute(strm);+}++} // namespace node+} // namespace intel_cpu+} // namespace ovdiff --git a/src/plugins/intel_cpu/src/nodes/lora.h b/src/plugins/intel_cpu/src/nodes/lora.hnew file mode 100644index 00000000000..89a1bc15c2b--- /dev/null+++ b/src/plugins/intel_cpu/src/nodes/lora.h@@ -0,0 +1,41 @@+// Copyright (C) 2024 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#pragma once++#include "graph.h"+#include "node.h"++namespace ov {+namespace intel_cpu {+namespace node {++class LoRA : public Node {+public:+ static bool isSupportedOperation(const std::shared_ptr<const ov::Node>& op, std::string& errorMessage) noexcept;++ LoRA(const std::shared_ptr<ov::Node>& op, const GraphContext::CPtr& context);++ bool created() const override {+ return getType() == Type::LoRA;+ }++ bool needPrepareParams() const override {+ return false;+ }++ void getSupportedDescriptors() override{};+ void selectOptimalPrimitiveDescriptor() override;+ void createPrimitive() override;+ void execute(dnnl::stream) override;+ void executeDynamicImpl(dnnl::stream strm) override;++private:+ std::shared_ptr<const ov::Model> m_body;+ Graph m_graph;+};++} // namespace node+} // namespace intel_cpu+} // namespace ovdiff --git a/src/plugins/intel_cpu/src/nodes/reference.cpp b/src/plugins/intel_cpu/src/nodes/reference.cppindex 43b8f041184..185815acd8c 100644--- a/src/plugins/intel_cpu/src/nodes/reference.cpp+++ b/src/plugins/intel_cpu/src/nodes/reference.cpp@@ -14,7 +14,7 @@ Reference::Reference(const std::shared_ptr<ov::Node>& op, const GraphContext::CPNode(op, context, NgraphShapeInferFactory(op, FULL_PORT_MASK)), ovCoreNode(op), additionalErrorMessage(errorMessage) {if (!op->has_evaluate()) {OPENVINO_THROW_NOT_IMPLEMENTED(- "Cannot fallback on ngraph reference implementation (Ngraph::Node::evaluate() is not implemented");+ "Cannot fallback on ngraph reference implementation (Ngraph::Node::evaluate() is not implemented)");}setType(Type::Reference);diff --git a/src/plugins/intel_cpu/src/nodes_factory.cpp b/src/plugins/intel_cpu/src/nodes_factory.cppindex 16cf1b974d8..4a8e8205510 100644--- a/src/plugins/intel_cpu/src/nodes_factory.cpp+++ b/src/plugins/intel_cpu/src/nodes_factory.cpp@@ -108,6 +108,7 @@#include "nodes/transpose.h"#include "nodes/unique.hpp"#include "nodes/causal_mask_preprocess.h"+#include "nodes/lora.h"namespace ov {namespace intel_cpu {@@ -221,6 +222,7 @@ Node::NodesFactory::NodesFactory() : Factory("NodesFactory") {INTEL_CPU_NODE(Composite, Type::SubModel);INTEL_CPU_NODE(ScaledDotProductAttention, Type::ScaledDotProductAttention);INTEL_CPU_NODE(SearchSorted, Type::SearchSorted);+ INTEL_CPU_NODE(LoRA, Type::LoRA);#if defined(OPENVINO_ARCH_X86_64)INTEL_CPU_NODE(FakeQuantize, Type::FakeQuantize);INTEL_CPU_NODE(GridSample, Type::GridSample);diff --git a/src/plugins/intel_cpu/src/transformations/transformation_pipeline.cpp b/src/plugins/intel_cpu/src/transformations/transformation_pipeline.cppindex fcf38440b8a..9dd1da2d471 100644--- a/src/plugins/intel_cpu/src/transformations/transformation_pipeline.cpp+++ b/src/plugins/intel_cpu/src/transformations/transformation_pipeline.cpp@@ -37,6 +37,7 @@#include "transformations/common_optimizations/move_eltwise_up_data_movement.hpp"#include "transformations/common_optimizations/mark_rope_input_to_keep_in_mixed_precision.hpp"#include "transformations/common_optimizations/rms_fusion.hpp"+#include "transformations/common_optimizations/lora_subgraph_fusion.hpp"#include "transformations/control_flow/unroll_tensor_iterator.hpp"#include "transformations/fp16_compression/mark_decompression_convert_constant_folding.hpp"#include "transformations/fp16_compression/mark_floatpoint_range.hpp"@@ -693,6 +694,7 @@ void Transformations::PreLpt(const std::vector<ov::element::Type>& defaultPrecisCPU_REGISTER_PASS_COMMON(manager, ov::pass::EnableDecompressionConvertConstantFolding);CPU_REGISTER_PASS_COMMON(manager, ov::pass::KeepConstAndDecompression);CPU_REGISTER_PASS_COMMON(manager, ov::pass::ConstantFolding);+ CPU_REGISTER_PASS_COMMON(manager, ov::pass::LoraSubgraphFusion);manager.run_passes(model);}diff --git a/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/common/lora_pattern.cpp b/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/common/lora_pattern.cppnew file mode 100644index 00000000000..4f4b05ef567--- /dev/null+++ b/src/plugins/intel_cpu/tests/functional/custom/subgraph_tests/src/common/lora_pattern.cpp@@ -0,0 +1,266 @@+// Copyright (C) 2018-2024 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "common_test_utils/node_builders/convolution.hpp"+#include "common_test_utils/node_builders/eltwise.hpp"+#include "common_test_utils/ov_tensor_utils.hpp"+#include "shared_test_classes/base/ov_subgraph.hpp"+#include "utils/cpu_test_utils.hpp"++namespace ov {+namespace test {++namespace {+constexpr auto t4_name = "lora/MatMul.B";+constexpr auto t5_name = "lora/MatMul.alpha";+constexpr auto t6_name = "lora/MatMul.A";+constexpr auto netType = ov::element::f32;+} // namespace++class LoraPatternBaseCPUTest : public SubgraphBaseTest {+protected:+ void run_test_empty_tensors() {+ compile_model();+ inferRequest = compiledModel.create_infer_request();+ ASSERT_TRUE(inferRequest);+ generate_inputs(targetStaticShapes.front());+ for (const auto& input : inputs) {+ inferRequest.set_tensor(input.first, input.second);+ }++ inferRequest.infer();+ auto outputs = function->outputs();++ auto tx_result = inferRequest.get_tensor(outputs[0]);+ auto tz_result = inferRequest.get_tensor(outputs[1]);+ ov::test::utils::compare(tx_result, tz_result, 1e-4, 1e-4);+ }++ void run_test_random_tensors() {+ compile_model();+ inferRequest = compiledModel.create_infer_request();+ ASSERT_TRUE(inferRequest);++ // use the Template plugin as a reference++ auto compiledReferenceModel = core->compile_model(function, ov::test::utils::DEVICE_TEMPLATE);+ auto inferRequestRef = compiledReferenceModel.create_infer_request();+ ASSERT_TRUE(inferRequestRef);++ generate_inputs(targetStaticShapes.front());+ for (const auto& input : inputs) {+ inferRequest.set_tensor(input.first, input.second);+ inferRequestRef.set_tensor(input.first, input.second);+ }++ constexpr size_t lora_order = 25lu;+ constexpr int infer_count = 6lu;++ std::unordered_map<std::string, ov::Shape> stateShapes;+ std::unordered_map<std::string, ov::Shape> initStateShapes;++ auto&& states = inferRequest.query_state();+ for (auto&& state : states) {+ auto shape = state.get_state().get_shape();+ initStateShapes.insert({state.get_name(), shape});+ std::for_each(shape.begin(), shape.end(), [=](ov::Shape::value_type& x) {+ if (0 == x) {+ x = lora_order;+ }+ });+ stateShapes.insert({state.get_name(), std::move(shape)});+ }++ for (int i = 0; i < infer_count; ++i) {+ // set states++ if (i == 3) {+ // reset states on the 3rd iteration+ for (auto&& item : states) {+ item.reset();+ }++ for (auto&& item : inferRequestRef.query_state()) {+ // Template plugin doesn't support reset state for dynamic shape states+ item.get_state().set_shape(initStateShapes.at(item.get_name()));+ }+ } else if (!(i & 0x1)) { // every even call+ // generate and set state tensors+ for (auto&& item : states) {+ auto&& refStates = inferRequestRef.query_state();+ using ov::test::utils::InputGenerateData;+ const auto& shape = stateShapes.at(item.get_name());+ auto tensor =+ ov::test::utils::create_and_fill_tensor(netType, shape, InputGenerateData{0, 10, 1, i});+ item.set_state(tensor);+ auto itr = std::find_if(refStates.begin(), refStates.end(), [&](const ov::VariableState& state) {+ return state.get_name() == item.get_name();+ });+ ASSERT_FALSE(itr == refStates.end());+ itr->set_state(tensor);+ }+ }++ inferRequest.infer();+ inferRequestRef.infer();+ auto outputs = function->outputs();++ auto tx_result = inferRequest.get_tensor(outputs[0]);+ auto tz_result = inferRequest.get_tensor(outputs[1]);++ auto tx_result_ref = inferRequestRef.get_tensor(outputs[0]);+ auto tz_result_ref = inferRequestRef.get_tensor(outputs[1]);++ ov::test::utils::compare(tx_result, tx_result_ref, 1e-4, 1e-4);+ ov::test::utils::compare(tz_result, tz_result_ref, 1e-4, 1e-4);+ }+ }+};++class LoraPatternMatmulCPUTest : public LoraPatternBaseCPUTest {+public:+ void SetUp() override {+ targetDevice = ov::test::utils::DEVICE_CPU;++ ov::PartialShape shape_x = {-1, -1, K};+ ov::PartialShape shape_w = {N, K};++ auto param_y = std::make_shared<ov::op::v0::Parameter>(netType, shape_x);+ auto param_w = std::make_shared<ov::op::v0::Parameter>(netType, shape_w);++ // "Main" matrix multiplication from the original transformer model+ auto tx = std::make_shared<ov::op::v0::MatMul>(param_y, param_w, false, true);++ // LoRA parameters from states+ auto variable_t4 = std::make_shared<ov::op::util::Variable>(+ ov::op::util::VariableInfo{ov::PartialShape({N, -1}), netType, t4_name});+ auto t4 = std::make_shared<ov::op::v6::ReadValue>(variable_t4);+ auto t4_assign = std::make_shared<ov::op::v6::Assign>(t4, variable_t4);++ auto variable_t5 = std::make_shared<ov::op::util::Variable>(+ ov::op::util::VariableInfo{ov::PartialShape({1, -1}), netType, t5_name});+ auto t5 = std::make_shared<ov::op::v6::ReadValue>(variable_t5);+ auto t5_assign = std::make_shared<ov::op::v6::Assign>(t5, variable_t5);++ auto variable_t6 = std::make_shared<ov::op::util::Variable>(+ ov::op::util::VariableInfo{ov::PartialShape({-1, K}), netType, t6_name});+ auto t6 = std::make_shared<ov::op::v6::ReadValue>(variable_t6);+ auto t6_assign = std::make_shared<ov::op::v6::Assign>(t6, variable_t6);++ // Apply LoRA parameters to the current activations+ auto t5810 = std::make_shared<ov::op::v0::MatMul>(param_y, t6, false, true);+ auto t5811 = std::make_shared<ov::op::v1::Multiply>(t5810, t5);+ auto t5812 = std::make_shared<ov::op::v0::MatMul>(t5811, t4, false, true);++ // Mix LoRA part into normally computed activations after the "main" MatMul+ auto tz = std::make_shared<ov::op::v1::Add>(tx, t5812);++ auto result_x = std::make_shared<ov::op::v0::Result>(tx);+ auto result_z = std::make_shared<ov::op::v0::Result>(tz);++ function = std::make_shared<ov::Model>(ov::ResultVector({result_x, result_z}),+ ov::SinkVector({t4_assign, t5_assign, t6_assign}),+ ov::ParameterVector({param_y, param_w}));+ }++protected:+ static constexpr size_t K = 563ul; // Weights matrix K dimension+ static constexpr size_t N = 2048ul; // Weights matrix N dimension+};++class LoraPatternConvolutionCPUTest : public LoraPatternBaseCPUTest {+public:+ void SetUp() override {+ targetDevice = ov::test::utils::DEVICE_CPU;+ ov::PartialShape shape_x = {-1, num_channels, -1, -1};++ auto param_y = std::make_shared<ov::op::v0::Parameter>(netType, shape_x);++ // Original Convolution that is modified by LoRA adapter later+ auto tx = ov::test::utils::make_convolution(param_y,+ netType,+ {1, 1},+ {1, 1},+ {0, 0},+ {0, 0},+ {1, 1},+ ov::op::PadType::EXPLICIT,+ num_channels);++ // LoRA parameters from states+ auto variable_t4 = std::make_shared<ov::op::util::Variable>(+ ov::op::util::VariableInfo{ov::PartialShape({num_channels, -1}), netType, t4_name});+ auto t4 = std::make_shared<ov::op::v6::ReadValue>(variable_t4);+ auto t4_assign = std::make_shared<ov::op::v6::Assign>(t4, variable_t4);++ auto variable_t5 = std::make_shared<ov::op::util::Variable>(+ ov::op::util::VariableInfo{ov::PartialShape({1, -1}), netType, t5_name});+ auto t5 = std::make_shared<ov::op::v6::ReadValue>(variable_t5);+ auto t5_assign = std::make_shared<ov::op::v6::Assign>(t5, variable_t5);++ auto variable_t6 = std::make_shared<ov::op::util::Variable>(+ ov::op::util::VariableInfo{ov::PartialShape({-1, num_channels}), netType, t6_name});+ auto t6 = std::make_shared<ov::op::v6::ReadValue>(variable_t6);+ auto t6_assign = std::make_shared<ov::op::v6::Assign>(t6, variable_t6);++ // LoRA pattern with additional Transposes to move channel dimensions into positions where MatMul can be applied+ auto t4940 =+ std::make_shared<ov::op::v0::Constant>(ov::element::i32, ov::Shape{4}, std::vector<size_t>{2, 3, 0, 1});++ auto t4941 = std::make_shared<ov::op::v1::Transpose>(param_y, t4940);+ auto t4942 = std::make_shared<ov::op::v0::MatMul>(t4941, t6, false, true);+ auto t4943 = std::make_shared<ov::op::v1::Multiply>(t4942, t5);+ auto t4944 = std::make_shared<ov::op::v0::MatMul>(t4943, t4, false, true);++ auto t4945 =+ std::make_shared<ov::op::v0::Constant>(ov::element::i32, ov::Shape{4}, std::vector<size_t>{2, 3, 0, 1});+ auto t4946 = std::make_shared<ov::op::v1::Transpose>(t4944, t4945);++ // Mix LoRA part into normally computed activations after the "main" MatMul+ auto tz = std::make_shared<ov::op::v1::Add>(tx, t4946);++ auto result_x = std::make_shared<ov::op::v0::Result>(tx);+ auto result_z = std::make_shared<ov::op::v0::Result>(tz);++ function = std::make_shared<ov::Model>(ov::ResultVector({result_x, result_z}),+ ov::SinkVector({t4_assign, t5_assign, t6_assign}),+ ov::ParameterVector({param_y}));+ }++protected:+ static constexpr size_t num_channels = 64ul;+};++TEST_F(LoraPatternMatmulCPUTest, smoke_LoRA_CPU_MatMul_empty) {+ targetStaticShapes = {{{{1, 20, K}}, {{N, K}}}};+ run_test_empty_tensors();+ CPUTestUtils::CheckNumberOfNodesWithType(compiledModel, "LoRA", 1);+ CPUTestUtils::CheckNumberOfNodesWithType(compiledModel, "MatMul", 1);+}++TEST_F(LoraPatternConvolutionCPUTest, smoke_LoRA_CPU_Conv_empty) {+ targetStaticShapes = {{{1, num_channels, 10, 15}}};+ run_test_empty_tensors();+ CPUTestUtils::CheckNumberOfNodesWithType(compiledModel, "LoRA", 1);+ CPUTestUtils::CheckNumberOfNodesWithType(compiledModel, "MatMul", 0);+}++TEST_F(LoraPatternMatmulCPUTest, smoke_LoRA_CPU_MatMul_random) {+ GTEST_SKIP();+ targetStaticShapes = {{{{1, 20, K}}, {{N, K}}}};+ run_test_random_tensors();+ CPUTestUtils::CheckNumberOfNodesWithType(compiledModel, "LoRA", 1);+ CPUTestUtils::CheckNumberOfNodesWithType(compiledModel, "MatMul", 1);+}++TEST_F(LoraPatternConvolutionCPUTest, smoke_LoRA_CPU_Conv_random) {+ GTEST_SKIP();+ targetStaticShapes = {{{1, num_channels, 10, 15}}};+ run_test_random_tensors();+ CPUTestUtils::CheckNumberOfNodesWithType(compiledModel, "LoRA", 1);+ CPUTestUtils::CheckNumberOfNodesWithType(compiledModel, "MatMul", 0);+}++} // namespace test+} // namespace ov\ No newline at end of file