Skip to content

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

[NPUW] Avoid allocating full-size vocab tensors in alloc_quant_gather_tensors (#38834)

jburcham-intel415223709d55
diff --git a/src/plugins/intel_npu/src/plugin/npuw/base_sync_infer_request.cpp b/src/plugins/intel_npu/src/plugin/npuw/base_sync_infer_request.cpp
index 340331a9003..e2011e9332a 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/base_sync_infer_request.cpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/base_sync_infer_request.cpp
@@ -291,7 +291,7 @@ void ov::npuw::IBaseInferRequest::alloc_quant_gather() {
if (!comp_model_desc.compiled_model && !comp_model_desc.replaced_by) {
continue; // Optimized out
}
- alloc_quant_gather_tensors(i, m_subrequests[i]);
+ alloc_quant_gather_tensors(i);
}
}
@@ -516,41 +516,36 @@ void ov::npuw::IBaseInferRequest::bind_global_params(std::size_t idx, RqPtr requ
LOG_DEBUG("Done");
}
-void ov::npuw::IBaseInferRequest::alloc_quant_gather_tensors(std::size_t idx, RqPtr request) {
+void ov::npuw::IBaseInferRequest::alloc_quant_gather_tensors(std::size_t idx) {
auto& comp_model_desc = m_npuw_model->m_compiled_submodels[idx];
auto& quant_unpack_gather = comp_model_desc.quant_unpack_gather;
if (quant_unpack_gather.dst_idx != -1) {
NPUW_ASSERT(quant_unpack_gather.idx_idx != -1 && quant_unpack_gather.src_w_idx != -1);
+ // Only element types and shapes are needed, so read them from the compiled model's ports: querying the
+ // subrequest's tensors would allocate full-vocab device buffers before unpack_closure() binds the weights.
const auto& lport = comp_model_desc.compiled_model->inputs()[quant_unpack_gather.idx_idx];
- const auto& lookup = request->get_tensor(lport);
-
const auto& wport = comp_model_desc.compiled_model->inputs()[quant_unpack_gather.src_w_idx];
- const auto& vocabw = request->get_tensor(wport);
- auto ids_shape = lookup->get_shape();
+ auto ids_shape = lport.get_shape();
auto get_gathered_shape = [&ids_shape](const ov::Shape& shape) {
return ov::Shape{1, ids_shape[1], shape.size() == 3 ? shape[1] * shape[2] : shape[1]};
};
- m_quant_gather_tensors.w = ov::Tensor(vocabw->get_element_type(), get_gathered_shape(vocabw->get_shape()));
+ m_quant_gather_tensors.w = ov::Tensor(wport.get_element_type(), get_gathered_shape(wport.get_shape()));
if (quant_unpack_gather.src_z_idx != -1 && quant_unpack_gather.src_s_idx != -1) {
const auto& zport = comp_model_desc.compiled_model->inputs()[quant_unpack_gather.src_z_idx];
- const auto& vocabz = request->get_tensor(zport);
-
const auto& sport = comp_model_desc.compiled_model->inputs()[quant_unpack_gather.src_s_idx];
- const auto& vocabs = request->get_tensor(sport);
- m_quant_gather_tensors.z = ov::Tensor(vocabz->get_element_type(), get_gathered_shape(vocabz->get_shape()));
- m_quant_gather_tensors.s = ov::Tensor(vocabs->get_element_type(), get_gathered_shape(vocabs->get_shape()));
+ m_quant_gather_tensors.z = ov::Tensor(zport.get_element_type(), get_gathered_shape(zport.get_shape()));
+ m_quant_gather_tensors.s = ov::Tensor(sport.get_element_type(), get_gathered_shape(sport.get_shape()));
} else if (quant_unpack_gather.src_s_idx != -1) {
const auto& sport = comp_model_desc.compiled_model->inputs()[quant_unpack_gather.src_s_idx];
- const auto& vocabs = request->get_tensor(sport);
- m_quant_gather_tensors.s = ov::Tensor(vocabs->get_element_type(), get_gathered_shape(vocabs->get_shape()));
+ m_quant_gather_tensors.s = ov::Tensor(sport.get_element_type(), get_gathered_shape(sport.get_shape()));
}
}
}
diff --git a/src/plugins/intel_npu/src/plugin/npuw/base_sync_infer_request.hpp b/src/plugins/intel_npu/src/plugin/npuw/base_sync_infer_request.hpp
index 203d652c4f8..2182fe937a8 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/base_sync_infer_request.hpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/base_sync_infer_request.hpp
@@ -197,7 +197,7 @@ protected:
std::size_t input_idx,
const ov::SoPtr<ov::ITensor>& tensor,
RqPtr request);
- void alloc_quant_gather_tensors(std::size_t idx, RqPtr request);
+ void alloc_quant_gather_tensors(std::size_t idx);
void handle_quant_host_gather(std::size_t idx, RqPtr request);
void dump_input_tensors(std::size_t idx);