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

int4 doesn't handle cosine similarity correctly #13614

Closed
benwtrent opened this issue Jul 26, 2024 · 2 comments · Fixed by #13615
Closed

int4 doesn't handle cosine similarity correctly #13614

benwtrent opened this issue Jul 26, 2024 · 2 comments · Fixed by #13615

Comments

@benwtrent
Copy link
Member

benwtrent commented Jul 26, 2024

Description

just with some default settings, glove-200 does poorly with int4 HNSW and when using cosine. The bug occurs on merge. When recalculating the quantiles, the vectors aren't normalized like they should, so the quantiles will get all out of whack. We can actually see this in some of the below experiments. All these values should indicate a normalized vectory, however some of the results are > 1 or < -1.

Some experiments I have done:

Dynamic confidence interval:

  • Floats used to build the graph (e.g. when buffer is large enough): 0.693 (I regrettably didn't get the quantiles here...)
  • When int4 vectors are used 0.189 (minQuantile=-1.2686034, maxQuantile=1.3250866)

0.5 confidence interval (locally patched to allow it):

  • int4 vectors building the graph 0.649 (minQuantile=-0.277436, maxQuantile=0.29298353)

0.75 confidence interval (locally patched to allow it):

  • int4 vectors building the graph 0.535 (minQuantile=-0.48500386, maxQuantile=0.5028781)

0.9 confidence interval:

  • int4 vectors building the graph 0.407 (minQuantile=-0.71112806, maxQuantile=0.73441404)
@benwtrent
Copy link
Member Author

Actually, this might be a bug. Looking at the code, I am not sure we normalize the vectors when building the quantizer & using cosine.

@benwtrent
Copy link
Member Author

Yep, not normalizing during quantile merging is the actual bug. I have a local patch that fixes this. Need to write up some tests & will push up a change soon.

Good find @naveentatikonda!

@benwtrent benwtrent changed the title int4 quantization does poorly on glove-200 int4 doesn't handle cosine similarity correctly Jul 27, 2024
@benwtrent benwtrent self-assigned this Jul 27, 2024
benwtrent added a commit that referenced this issue Aug 5, 2024
When quantizing vectors in a COSINE vector space, we normalize them. However, there is a bug when building the quantizer quantiles and we didn't always use the normalized vectors. Consequently, we would end up with poorly configured quantiles and recall will drop significantly (especially in sensitive cases like int4).

closes: #13614
benwtrent added a commit that referenced this issue Aug 5, 2024
When quantizing vectors in a COSINE vector space, we normalize them. However, there is a bug when building the quantizer quantiles and we didn't always use the normalized vectors. Consequently, we would end up with poorly configured quantiles and recall will drop significantly (especially in sensitive cases like int4).

closes: #13614
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant