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

Add padding while saving ivf.pid.pt and release GIL #336

Merged
merged 1 commit into from
May 28, 2024
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
9 changes: 9 additions & 0 deletions colbert/indexing/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ def optimize_ivf(orig_ivf, orig_ivf_lengths, index_path, verbose:int=3):
offset += length
ivf = torch.cat(unique_pids_per_centroid)
ivf_lengths = torch.tensor(ivf_lengths)

max_stride = ivf_lengths.max().item()
zero = torch.zeros(1, dtype=torch.long, device=ivf_lengths.device)
offsets = torch.cat((zero, torch.cumsum(ivf_lengths, dim=0)))
inner_dims = ivf.size()[1:]

if offsets[-2] + max_stride > ivf.size(0):
padding = torch.zeros(max_stride, *inner_dims, dtype=ivf.dtype, device=ivf.device)
ivf = torch.cat((ivf, padding))

original_ivf_path = os.path.join(index_path, 'ivf.pt')
optimized_ivf_path = os.path.join(index_path, 'ivf.pid.pt')
Expand Down
2 changes: 1 addition & 1 deletion colbert/search/decompress_residuals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,5 @@ torch::Tensor decompress_residuals(

PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
m.def("decompress_residuals_cpp", &decompress_residuals,
"Decompress residuals");
"Decompress residuals", py::call_guard<py::gil_scoped_release>());
}
2 changes: 1 addition & 1 deletion colbert/search/filter_pids.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,5 +170,5 @@ torch::Tensor filter_pids(const torch::Tensor pids,
}

PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
m.def("filter_pids_cpp", &filter_pids, "Filter pids");
m.def("filter_pids_cpp", &filter_pids, "Filter pids", py::call_guard<py::gil_scoped_release>());
}