Calculate pid_docid_map.values()
only once in add_to_index
#267
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I was building an index of 200k documents (from the UKPLab/DAPR's Genomics dataset) and noted that when using
add_to_index
(to build the index in batches) it was hanging on a list comprehension in line 162 of colbert.py:Profiling this showed that the entire index building process took 1240 seconds and this list comprehension took 352 seconds.
The issue was that each iteration of the list comprehension was calculating
self.pid_docid_map.values()
. Pulling this out of the list comprehension to calculate it once (and only referencing it in the list comprehension) brought its execution time from 352 seconds down to <0.6 seconds.This PR implements that code.
This is my first PR in RAGatouille so please let me know if additional information is needed. Thank you for maintaining such an awesome library!
For reference, here's the code I used to profile this issue in a Google Colab Pro notebook (T4 w/High-RAM instance):