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

Float16 integration and API #4234

Merged
merged 2 commits into from
May 15, 2024
Merged

Float16 integration and API #4234

merged 2 commits into from
May 15, 2024

Conversation

IvanPleshkov
Copy link
Contributor

@IvanPleshkov IvanPleshkov commented May 14, 2024

Float16 REST and Grpc, storages, scorers, and constructors

All Submissions:

  • Contributions should target the dev branch. Did you create your branch from dev?
  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

New Feature Submissions:

  1. Does your submission pass tests?
  2. Have you formatted your code locally using cargo +nightly fmt --all command prior to submission?
  3. Have you checked your code using cargo clippy --all --all-features command?

Changes to Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

@IvanPleshkov IvanPleshkov marked this pull request as draft May 14, 2024 10:12
@IvanPleshkov IvanPleshkov changed the title f16 integration Float16 integration and API May 14, 2024
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cosine metric was missed, added

Copy link
Contributor

Choose a reason for hiding this comment

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

Does preprocess work for non float32? I can add tests / SIMD implementations for cosine metric if helpful.

Distance::Manhattan => <ManhattanMetric as Metric<VectorElementType>>::preprocess(v),
};
Cow::from(preprocessed_vector)
Cow::Owned(vector.iter().map(|&x| f16::to_f32(x)).collect_vec())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was an incorrect implementation. quantization_preprocess is a trick for byte type, where we need to apply -127 for binary quantization. Here we need conversion into f32 only

Copy link
Member

Choose a reason for hiding this comment

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

👍

VectorStorageDatatype::Float16,
64,
20
)]
fn test_byte_storage_hnsw(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I extended existing test for byte vector to test HNSW

@@ -166,6 +194,7 @@ fn sames_count(a: &[Vec<ScoredPointOffset>], b: &[Vec<ScoredPointOffset>]) -> us
)]
fn test_byte_storage_binary_quantization_hnsw(
#[case] query_variant: QueryVariant,
#[case] storage_data_type: VectorStorageDatatype,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I extended existing test for byte vector to test quantization

@@ -46,40 +48,68 @@ enum QuantizationVariant {
Binary,
}

fn random_discovery_query<R: Rng + ?Sized>(rnd: &mut R, dim: usize) -> QueryVector {
fn random_vector<R>(rnd_gen: &mut R, dim: usize, data_type: VectorStorageDatatype) -> DenseVector
Copy link
Contributor Author

Choose a reason for hiding this comment

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

because we test binary quantization, we need to specify vector to utilize binary condition. for u8 we generate vectors in range [0; 255], for f16 we generate vectors in range [-0.5; 0.5]

@IvanPleshkov IvanPleshkov marked this pull request as ready for review May 14, 2024 14:56
tests

api

fix test

are you happy clippy
@IvanPleshkov IvanPleshkov merged commit e808449 into dev May 15, 2024
17 checks passed
@IvanPleshkov IvanPleshkov deleted the f16-integration branch May 15, 2024 08:36
generall pushed a commit that referenced this pull request May 26, 2024
* f16 integration

tests

api

fix test

are you happy clippy

* fix build
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