Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NPUW] Fix for weights bank UIDs #28297

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/plugins/intel_npu/src/plugin/npuw/weights_bank.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ int64_t Bank::registerLT(const LazyTensor& tensor, const std::string& device) {
std::lock_guard<std::mutex> guard(m_mutex);

auto& device_bank = m_device_banks[device_for_alloc];
std::unique_lock dev_guard(device_bank.mutex);

auto iter_registered = device_bank.registered_tensors.find(tensor);
if (iter_registered == device_bank.registered_tensors.end()) {
auto uid = uid_count++;
Expand Down Expand Up @@ -79,10 +81,14 @@ void Bank::evaluate_and_allocate() {
auto& device_bank = bank.second;

std::vector<LazyTensor> vec;

std::unique_lock storage_guard(device_bank.mutex);
vec.reserve(device_bank.storage.size());
for (const auto& el : device_bank.storage) {
vec.push_back(el.second.lt);
}
storage_guard.unlock();
Comment on lines +85 to +90
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if I understand this code correctly (aside of the lock guards), it seems to me you first iterate over all (say, 400) registered lazy tensors in the bank to make a job list, and then run over it in parallel_for() to evaluate and allocate.

Under the parallel_for(), you check if the tensor is already allocated.

On the first run (prefill compile), this code will work as expected - you will evaluate, allocate, and copy all ~400 tensors.

On the second run you have these 400 tensors in the bank already and you add it to the list regardless, then fire up all the threads to basically do a no-op.

I'd recommend to only add tensors which were not allocated to this list.


ov::parallel_for(vec.size(), [&](std::size_t idx) {
const auto& lt = vec[idx];
std::unique_lock dev_guard(device_bank.mutex);
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/intel_npu/src/plugin/npuw/weights_bank.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Bank {
// Register LazyTensor in a bank if it's not there. Returns LazyTensor's unique id
int64_t registerLT(const LazyTensor& tensor, const std::string& device);

// Allocate and evaluate a registered tensor on a specified device (if needed) and return it from the bank
// Get registered, allocated and evaluated tensor on a specified device
ov::Tensor get(int64_t uid, const std::string& device);

// Evaluate and allocate all LazyTensors in the bank
Expand Down
Loading