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

Use valid data for sqfp16 test #1474

Merged
merged 1 commit into from
Feb 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/test/java/org/opensearch/knn/jni/JNIServiceTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ public void testQueryIndex_faiss_sqfp16_valid() {
Path tmpFile = createTempFile();
JNIService.createIndex(
testData.indexData.docs,
testData.indexData.vectors,
truncateToFp16Range(testData.indexData.vectors),
tmpFile.toAbsolutePath().toString(),
ImmutableMap.of(INDEX_DESCRIPTION_PARAMETER, sqfp16IndexDescription, KNNConstants.SPACE_TYPE, SpaceType.L2.getValue()),
FAISS_NAME
Expand All @@ -547,6 +547,23 @@ public void testQueryIndex_faiss_sqfp16_valid() {
}
}

// If the value is outside of the fp16 range, then convert it to the fp16 minimum or maximum value
private float[][] truncateToFp16Range(final float[][] data) {
float[][] result = new float[data.length][data[0].length];
for (int i = 0; i < data.length; i++) {
for (int j = 0; j < data[i].length; j++) {
float value = data[i][j];
if (value < Float.MIN_VALUE || value > Float.MAX_VALUE) {
// If value is outside of the range, set it to the maximum or minimum value
result[i][j] = value < 0 ? -Float.MAX_VALUE : Float.MAX_VALUE;
} else {
result[i][j] = value;
}
}
}
return result;
}

@SneakyThrows
public void testTrain_whenConfigurationIsIVFSQFP16_thenSucceed() {
long trainPointer = transferVectors(10);
Expand Down
Loading