Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[CPU][TP] Ensure that memory attributes are present before splitting (#29315)

Egor Duplenskiidf324b745cf9
diff --git a/src/plugins/intel_cpu/src/nodes/fullyconnected.cpp b/src/plugins/intel_cpu/src/nodes/fullyconnected.cpp
index 77424aab90e..d643ef1c18e 100644
--- a/src/plugins/intel_cpu/src/nodes/fullyconnected.cpp
+++ b/src/plugins/intel_cpu/src/nodes/fullyconnected.cpp
@@ -601,24 +601,33 @@ void FullyConnected::needSplitMemoryForTensorParallel() {
memory[ARG_DST] = getDstMemoryAtPort(0);
tp_cfg.cached_dst = split_horizontal(context->getEngine(), dst, -1, tp_cfg.w_rank, tp_cfg.w_size, false);
- memory[ARG_DST | ARG_ATTR_SCALES] =
- split_horizontal(context->getEngine(), memory[ARG_DST | ARG_ATTR_SCALES], 0, tp_cfg.w_rank, tp_cfg.w_size);
-
- auto scale_mem = std::const_pointer_cast<IMemory>(memory[ARG_WEI | ARG_ATTR_SCALES]);
- memory[ARG_WEI | ARG_ATTR_SCALES] =
- attrs.weightsNonTransposed
- ? split_vertical(context->getEngine(), scale_mem, 0, tp_cfg.w_rank, tp_cfg.w_size)
- : split_horizontal(context->getEngine(), scale_mem, 0, tp_cfg.w_rank, tp_cfg.w_size);
-
- auto zeropoint_mem = std::const_pointer_cast<IMemory>(memory[ARG_WEI | ARG_ATTR_ZERO_POINTS]);
- auto element_num = zeropoint_mem->getSize() / zeropoint_mem->getPrecision().size();
- if (element_num == 1) {
- tp_cfg.cached_zeropoint = zeropoint_mem;
- } else {
- tp_cfg.cached_zeropoint =
+ if (memory.count(ARG_DST | ARG_ATTR_SCALES)) {
+ memory[ARG_DST | ARG_ATTR_SCALES] = split_horizontal(context->getEngine(),
+ memory[ARG_DST | ARG_ATTR_SCALES],
+ 0,
+ tp_cfg.w_rank,
+ tp_cfg.w_size);
+ }
+
+ if (memory.count(ARG_WEI | ARG_ATTR_SCALES)) {
+ auto scale_mem = std::const_pointer_cast<IMemory>(memory[ARG_WEI | ARG_ATTR_SCALES]);
+ memory[ARG_WEI | ARG_ATTR_SCALES] =
attrs.weightsNonTransposed
- ? split_vertical(context->getEngine(), zeropoint_mem, 0, tp_cfg.w_rank, tp_cfg.w_size)
- : split_horizontal(context->getEngine(), zeropoint_mem, 0, tp_cfg.w_rank, tp_cfg.w_size);
+ ? split_vertical(context->getEngine(), scale_mem, 0, tp_cfg.w_rank, tp_cfg.w_size)
+ : split_horizontal(context->getEngine(), scale_mem, 0, tp_cfg.w_rank, tp_cfg.w_size);
+ }
+
+ if (memory.count(ARG_WEI | ARG_ATTR_ZERO_POINTS)) {
+ auto zeropoint_mem = std::const_pointer_cast<IMemory>(memory[ARG_WEI | ARG_ATTR_ZERO_POINTS]);
+ auto element_num = zeropoint_mem->getSize() / zeropoint_mem->getPrecision().size();
+ if (element_num == 1) {
+ tp_cfg.cached_zeropoint = zeropoint_mem;
+ } else {
+ tp_cfg.cached_zeropoint =
+ attrs.weightsNonTransposed
+ ? split_vertical(context->getEngine(), zeropoint_mem, 0, tp_cfg.w_rank, tp_cfg.w_size)
+ : split_horizontal(context->getEngine(), zeropoint_mem, 0, tp_cfg.w_rank, tp_cfg.w_size);
+ }
}
}
}