-
Notifications
You must be signed in to change notification settings - Fork 137
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 Range Validation for SQFP16 #1493
Add Range Validation for SQFP16 #1493
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## feature/faiss_sqfp16 #1493 +/- ##
==========================================================
- Coverage 85.14% 84.99% -0.16%
- Complexity 1281 1295 +14
==========================================================
Files 168 168
Lines 5232 5286 +54
Branches 495 510 +15
==========================================================
+ Hits 4455 4493 +38
- Misses 570 580 +10
- Partials 207 213 +6 ☔ View full report in Codecov by Sentry. |
The failing Rolling Upgrade Tests and CI on Windows is not related to these changes, created an issue to track it #1494 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of clip_to_range, what about truncate? Is clip used anywhere else?
src/main/java/org/opensearch/knn/index/mapper/KNNVectorFieldMapper.java
Outdated
Show resolved
Hide resolved
src/main/java/org/opensearch/knn/index/mapper/KNNVectorFieldMapperUtil.java
Show resolved
Hide resolved
I took numpy as a reference, where they call it as clip. As discussed offline will rename it from |
abf7436
to
c20750e
Compare
Signed-off-by: Naveen Tatikonda <[email protected]>
Signed-off-by: Naveen Tatikonda <[email protected]>
Signed-off-by: Naveen Tatikonda <[email protected]>
Signed-off-by: Naveen Tatikonda <[email protected]>
c20750e
to
62c8e29
Compare
Can we add bwc tests here? |
src/main/java/org/opensearch/knn/index/mapper/KNNVectorFieldMapper.java
Outdated
Show resolved
Hide resolved
src/main/java/org/opensearch/knn/index/mapper/KNNVectorFieldMapper.java
Outdated
Show resolved
Hide resolved
src/main/java/org/opensearch/knn/index/mapper/KNNVectorFieldMapper.java
Outdated
Show resolved
Hide resolved
MethodComponentContext methodComponentContext = (MethodComponentContext) methodComponentParams.get( | ||
METHOD_ENCODER_PARAMETER | ||
); | ||
if (ENCODER_SQ.equals(methodComponentContext.getName()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this case can be combined with a previous one if (methodComponentParams.containsKey(METHOD_ENCODER_PARAMETER)) {
, maybe put it to it's own method if it became hard to read
src/main/java/org/opensearch/knn/index/mapper/KNNVectorFieldMapper.java
Outdated
Show resolved
Hide resolved
@SneakyThrows | ||
public void testHNSWSQFP16_whenIndexedWithOutOfFP16Range_thenThrowException() { | ||
String indexName = "test-index-sqfp16"; | ||
String fieldName = "test-field-sqfp16"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think those two fields should be declared at the class level
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that class, all the test variables are initialized at test level. So, tried to maintain consistency.
src/main/java/org/opensearch/knn/index/mapper/KNNVectorFieldMapper.java
Outdated
Show resolved
Hide resolved
@naveentatikonda what is clip parameter going to do? |
Signed-off-by: Naveen Tatikonda <[email protected]>
62c8e29
to
06dc3b1
Compare
50adf0d
to
e90fa0d
Compare
If the Like if the vector value is > 65504.0, then it is indexed as 65504.0 |
So anything outside the range of fp16 is actually getting mapping to 1 single value. Can we do something better here? I am pretty unsure about this. What experiments we have done to understand the impact of this clipping? cc: @jmazanec15 , @vamshin |
Clipping out of range values to MIN or MAX values is also one of the standard quantization technique and we implemented this after discussing with Science team. Do you have any suggestions to implement it even better ? As of now we didn't run any experiments with clipping as we don't have any standard datasets with data outside of Fp16 range. But, the impact depends on the distribution of vectors and if most of them lies outside of the range then the impact on recall will be high. In such scenarios we won't recommend customers to enable this field or use this feature. |
@navneet1v I think there are a few alternatives, but they probably should be iterated on. In the initial phase, we should not recommend using this version of sqfp16 if the majority of the data lies outside -Float16.Max or Float16.Max. Adding the clip functionality just ensures that if a user does get an occasional value outside of the range, the system will not break or reject the document. Alternative 1 I can think of is instead of clipping to 1 value, we could clip to 1,000 values and assign based on range outside of float max. Thus, we get a little bit better granularity in our values outside of the Float16 range. However, the benefit of this is probably minuscule and very data set dependent. Alternative 2 I can think of is to take approach that can be taken with uint8 and Lucene. Where you more or less look at the distribution of the data and come up with a mapping scheme based on this from fp32 to 16-bit. This may offer a better tradeoff, but would require a good amount of work on our side as well as user side and benefit is unknown. So, I think this approach is fine for an initial release. I like clip-to-max better than clip-to-inf because inf values will result in vector never being returned and I also think that more tricky bugs can be introduced when inf is considered a valid value (think divide by 0 sorts of things and other segfault behavior). |
@jmazanec15 Do you mean normalizing the complete data and bucket them into the FP16 range ? |
@naveentatikonda yes, but I dont think this is in scope for now |
I think its good to merge to feature branch. Lets add IVF support once #1527 is merged. |
qa/restart-upgrade/src/test/java/org/opensearch/knn/bwc/FaissSQIT.java
Outdated
Show resolved
Hide resolved
|
||
private void validateGraphEviction() throws Exception { | ||
// Search every 5 seconds 14 times to confirm graph gets evicted | ||
int intervals = 14; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why 14? and 5 seconds?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH, I'm not sure. I replicated this from FaissIT. May be for some tests with less number of docs the graphs gets evicted quickly. For some tests with more docs it might take more time. So, checking it multiple times in short duration.
Signed-off-by: Naveen Tatikonda <[email protected]>
e90fa0d
to
e84d598
Compare
8cad13b
into
opensearch-project:feature/faiss_sqfp16
The backport to
To backport manually, run these commands in your terminal: # Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-2.x 2.x
# Navigate to the new working tree
cd .worktrees/backport-2.x
# Create a new branch
git switch --create backport/backport-1493-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 8cad13b9a961048a90c632d8ba71b4ca46490a09
# Push it to GitHub
git push --set-upstream origin backport/backport-1493-to-2.x
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-2.x Then, create a pull request where the |
* Add Range Validation for SQFP16 Vector Data Signed-off-by: Naveen Tatikonda <[email protected]> * Add index setting to clip vector data to FP16 range Signed-off-by: Naveen Tatikonda <[email protected]> * Add CHANGELOG Signed-off-by: Naveen Tatikonda <[email protected]> * Add an encoder parameter to clip fp16 range Signed-off-by: Naveen Tatikonda <[email protected]> * Address Review Comments Signed-off-by: Naveen Tatikonda <[email protected]> * Add BWC Tests Signed-off-by: Naveen Tatikonda <[email protected]> --------- Signed-off-by: Naveen Tatikonda <[email protected]>
* Add Range Validation for SQFP16 Vector Data Signed-off-by: Naveen Tatikonda <[email protected]> * Add index setting to clip vector data to FP16 range Signed-off-by: Naveen Tatikonda <[email protected]> * Add CHANGELOG Signed-off-by: Naveen Tatikonda <[email protected]> * Add an encoder parameter to clip fp16 range Signed-off-by: Naveen Tatikonda <[email protected]> * Address Review Comments Signed-off-by: Naveen Tatikonda <[email protected]> * Add BWC Tests Signed-off-by: Naveen Tatikonda <[email protected]> --------- Signed-off-by: Naveen Tatikonda <[email protected]>
* Add Range Validation for SQFP16 Vector Data Signed-off-by: Naveen Tatikonda <[email protected]> * Add index setting to clip vector data to FP16 range Signed-off-by: Naveen Tatikonda <[email protected]> * Add CHANGELOG Signed-off-by: Naveen Tatikonda <[email protected]> * Add an encoder parameter to clip fp16 range Signed-off-by: Naveen Tatikonda <[email protected]> * Address Review Comments Signed-off-by: Naveen Tatikonda <[email protected]> * Add BWC Tests Signed-off-by: Naveen Tatikonda <[email protected]> --------- Signed-off-by: Naveen Tatikonda <[email protected]>
* Add Range Validation for SQFP16 Vector Data Signed-off-by: Naveen Tatikonda <[email protected]> * Add index setting to clip vector data to FP16 range Signed-off-by: Naveen Tatikonda <[email protected]> * Add CHANGELOG Signed-off-by: Naveen Tatikonda <[email protected]> * Add an encoder parameter to clip fp16 range Signed-off-by: Naveen Tatikonda <[email protected]> * Address Review Comments Signed-off-by: Naveen Tatikonda <[email protected]> * Add BWC Tests Signed-off-by: Naveen Tatikonda <[email protected]> --------- Signed-off-by: Naveen Tatikonda <[email protected]>
* Add Range Validation for SQFP16 (#1493) * Add Range Validation for SQFP16 Vector Data Signed-off-by: Naveen Tatikonda <[email protected]> * Add index setting to clip vector data to FP16 range Signed-off-by: Naveen Tatikonda <[email protected]> * Add CHANGELOG Signed-off-by: Naveen Tatikonda <[email protected]> * Add an encoder parameter to clip fp16 range Signed-off-by: Naveen Tatikonda <[email protected]> * Address Review Comments Signed-off-by: Naveen Tatikonda <[email protected]> * Add BWC Tests Signed-off-by: Naveen Tatikonda <[email protected]> --------- Signed-off-by: Naveen Tatikonda <[email protected]> * SQFP16 Range Validation for Faiss IVF Models (#1557) * SQFP16 Range Validation for Faiss IVF Models Signed-off-by: Naveen Tatikonda <[email protected]> * Address Review Comments Signed-off-by: Naveen Tatikonda <[email protected]> --------- Signed-off-by: Naveen Tatikonda <[email protected]> * Rebase Changes Signed-off-by: Naveen Tatikonda <[email protected]> --------- Signed-off-by: Naveen Tatikonda <[email protected]>
* Add Range Validation for SQFP16 (#1493) * Add Range Validation for SQFP16 Vector Data Signed-off-by: Naveen Tatikonda <[email protected]> * Add index setting to clip vector data to FP16 range Signed-off-by: Naveen Tatikonda <[email protected]> * Add CHANGELOG Signed-off-by: Naveen Tatikonda <[email protected]> * Add an encoder parameter to clip fp16 range Signed-off-by: Naveen Tatikonda <[email protected]> * Address Review Comments Signed-off-by: Naveen Tatikonda <[email protected]> * Add BWC Tests Signed-off-by: Naveen Tatikonda <[email protected]> --------- Signed-off-by: Naveen Tatikonda <[email protected]> * SQFP16 Range Validation for Faiss IVF Models (#1557) * SQFP16 Range Validation for Faiss IVF Models Signed-off-by: Naveen Tatikonda <[email protected]> * Address Review Comments Signed-off-by: Naveen Tatikonda <[email protected]> --------- Signed-off-by: Naveen Tatikonda <[email protected]> * Rebase Changes Signed-off-by: Naveen Tatikonda <[email protected]> --------- Signed-off-by: Naveen Tatikonda <[email protected]> (cherry picked from commit d63ce27)
* Faiss SQFP16 Range Validation and Clipping (#1562) * Add Range Validation for SQFP16 (#1493) * Add Range Validation for SQFP16 Vector Data Signed-off-by: Naveen Tatikonda <[email protected]> * Add index setting to clip vector data to FP16 range Signed-off-by: Naveen Tatikonda <[email protected]> * Add CHANGELOG Signed-off-by: Naveen Tatikonda <[email protected]> * Add an encoder parameter to clip fp16 range Signed-off-by: Naveen Tatikonda <[email protected]> * Address Review Comments Signed-off-by: Naveen Tatikonda <[email protected]> * Add BWC Tests Signed-off-by: Naveen Tatikonda <[email protected]> --------- Signed-off-by: Naveen Tatikonda <[email protected]> * SQFP16 Range Validation for Faiss IVF Models (#1557) * SQFP16 Range Validation for Faiss IVF Models Signed-off-by: Naveen Tatikonda <[email protected]> * Address Review Comments Signed-off-by: Naveen Tatikonda <[email protected]> --------- Signed-off-by: Naveen Tatikonda <[email protected]> * Rebase Changes Signed-off-by: Naveen Tatikonda <[email protected]> --------- Signed-off-by: Naveen Tatikonda <[email protected]> (cherry picked from commit d63ce27) * Fix EntityUtils package Signed-off-by: Naveen Tatikonda <[email protected]> --------- Signed-off-by: Naveen Tatikonda <[email protected]> Co-authored-by: Naveen Tatikonda <[email protected]>
Description
This PR adds range validation for Faiss SQFP16 where by default it validates the user input if it is in the FP16 range
[-65504.0, 65504.0]
and if it is out of range throws an exception. Users can still provide data that is out of fp16 range which will be clipped to fp16 range(without throwing any exception) when they set this encoder parameter,clip
astrue
.Issues Resolved
#1138
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.