Skip to content

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

NPUW: Hotfix - delay the original weight memory deallocation (#27886)

Dmitry Matveev1d36bab8ed35
diff --git a/src/plugins/intel_npu/src/plugin/npuw/weights_bank.cpp b/src/plugins/intel_npu/src/plugin/npuw/weights_bank.cpp
index 2b4be1a759c..5ff064e7629 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/weights_bank.cpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/weights_bank.cpp
@@ -110,9 +110,6 @@ ov::Tensor Bank::eval_and_alloc(const LazyTensor& tensor,
return transformed_tensor;
}
- // Non-CPU case: detach the evaluated LazyTensor from its memory
- const_cast<LazyTensor&>(tensor).detach();
-
ov::SoPtr<ov::ITensor> remote_tensor;
ov::Tensor allocated_tensor;
@@ -124,6 +121,12 @@ ov::Tensor Bank::eval_and_alloc(const LazyTensor& tensor,
guard.unlock(); // Unlock the guard, map update is done - copy can continue in parallel
transformed_tensor.copy_to(allocated_tensor);
+
+ // Detach the evaluated LazyTensor from its memory here - when it is 100%
+ // not needed anymore (transformations, if any, and copies are done)
+ // Note: this is the non-CPU path!
+ const_cast<LazyTensor&>(tensor).detach();
+
return allocated_tensor;
}