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

Prevent humongous allocations when calculating scalar quantiles #13090

Merged

Conversation

benwtrent
Copy link
Member

The initial release of scalar quantization would periodically create a humongous allocation, which can put unwarranted pressure on the GC & on the heap usage as a whole.

This commit adjusts this by only allocating a float array of 20*dimensions and averaging the discovered quantiles from there.

Why does this work?

  • Quantiles based on confidence intervals are (generally) unbiased and doing an average gives statistically good results
  • The selector algorithm scales linearly, so the cost is just about the same
  • We need to do more than 1 vector at a time to prevent extreme confidence intervals interacting strangely with edge cases

I benchmarked this over 500k vectors.

candidate

Force merge done in: 691533 ms
0.817	 0.04	500000	0	16	250	2343	596410	1.00	post-filter

baseline

Force merge done in: 685618 ms
0.818	 0.04	500000	0	16	250	2346	582242	1.00	post-filter

100k vectors
candidate

0.855	 0.03	100000	0	16	250	2207	144173	1.00	post-filter

baseline

0.858	 0.03	100000	0	16	250	2205	141578	1.00	post-filter

There does seem to be a slight increase in merge time (these are single threaded numbers) and a slight change in recall.

But to me, these seem acceptable given we are no longer allocating a ginormous array.

Copy link
Contributor

@mayya-sharipova mayya-sharipova left a comment

Choose a reason for hiding this comment

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

@benwtrent Thanks, the Lucene implementation LGTM as long as we are ok with the math and decreased recall that it brings.

Copy link

@tveasey tveasey left a comment

Choose a reason for hiding this comment

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

LGTM

@benwtrent benwtrent merged commit 7da509b into apache:main Feb 8, 2024
4 checks passed
@benwtrent benwtrent deleted the feature/scalar-quantization-optimization branch February 8, 2024 20:56
benwtrent added a commit that referenced this pull request Feb 8, 2024
The initial release of scalar quantization would periodically create a humongous allocation, which can put unwarranted pressure on the GC & on the heap usage as a whole.

This commit adjusts this by only allocating a float array of 20*dimensions and averaging the discovered quantiles from there. 

Why does this work?

 - Quantiles based on confidence intervals are (generally) unbiased and doing an average gives statistically good results
 - The selector algorithm scales linearly, so the cost is just about the same
 - We need to do more than `1` vector at a time to prevent extreme confidence intervals interacting strangely with edge cases
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants