-
Notifications
You must be signed in to change notification settings - Fork 20
[MOD-6775] introduce fp16 type! #462
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
Conversation
change bfloat and fp16 to struct typedef to avoid ambiguty between them
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## meiravg_feature_bfloat16 #462 +/- ##
============================================================
+ Coverage 97.10% 97.18% +0.07%
============================================================
Files 85 85
Lines 4633 4684 +51
============================================================
+ Hits 4499 4552 +53
+ Misses 134 132 -2 ☔ View full report in Codecov by Sentry. |
add fp16 files to bm files decrease testSizeEstimation dim size to make it run fasetr in debug
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.
Code review (without tests/benchmarks)
switch (metric) { | ||
case VecSimMetric_Cosine: | ||
case VecSimMetric_IP: | ||
return IP_FP16_GetDistFunc(dim, nullptr, alignment); |
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 does this function get a void pointer that is always null? can we just not pass it?
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.
It was part of the optimization bit map refactor
It was left mainly for testing purposes
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.
consider cleaning it now? I don't think it is needed for the test either (unless we suspect the hardware will change between calls)
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.
we pass a specific optimization in the tests to enforce lower optimization
see test_spaces.cpp
add default ctor
tests/benchmark/data/serializer.py
Outdated
@@ -128,7 +141,8 @@ | |||
TYPES_ATTR = { | |||
VecSimType_FLOAT32: {"size_in_bytes": 4, "vector_type": np.float32}, | |||
VecSimType_FLOAT64: {"size_in_bytes": 8, "vector_type": np.float64}, | |||
VecSimType_BFLOAT16: {"size_in_bytes": 2, "vector_type": bfloat16} | |||
VecSimType_BFLOAT16: {"size_in_bytes": 2, "vector_type": bfloat16}, | |||
VecSimType_FLOAT16: {"size_in_bytes": 2, "vector_type": np.float16} |
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.
VecSimType_FLOAT16: {"size_in_bytes": 2, "vector_type": np.float16} | |
VecSimType_FLOAT16: {"size_in_bytes": 2, "vector_type": np.float16}, |
@@ -52,4 +54,5 @@ gtest_discover_tests(test_bruteforce) | |||
gtest_discover_tests(test_allocator) | |||
gtest_discover_tests(test_spaces) | |||
gtest_discover_tests(test_common) | |||
gtest_discover_tests(test_bf16) | |||
gtest_discover_tests(test_bf16 TEST_PREFIX BF16UNIT_) |
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.
What's this prefix?
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.
it adds a prefix to all the tests' names in this file making it easier to run a specific set with ctest. for example:
make unit_test CTEST_ARGS="-R BF16UNIT_"
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.
Should we add it to other types as well? (Not in this PR)
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.
we can
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.
LGTM
Let's try to better use the PR template... in this particular case we do introduce (small) API change |
.github/workflows/flow-temp
Outdated
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.
👀
declaring a default ctor as constexpr is allowed as of c++20, and this feature in particular is supported as of gcc10 I don't see any benefit using this feature...
@@ -13,7 +13,7 @@ | |||
namespace vecsim_types { | |||
struct bfloat16 { | |||
uint16_t val; | |||
constexpr bfloat16() = default; | |||
bfloat16() = default; |
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.
Is this a compiler version issue? How come it works with fp16? Can we try this option?
bfloat16() = default; | |
constexpr bfloat16() noexcept {} |
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.
declaring a default ctor as constexpr is allowed as of c++20, and this feature in particular is supported as of gcc10
fp16 worked because it didn't have constexpr at first place.
Anyway, since we have another ctor that is constexpr, it doesn't matter.
.github/workflows/flow-temp.yml
Outdated
@@ -9,13 +9,14 @@ name: temporary testing | |||
|
|||
on: | |||
push: | |||
branches-ignore: ['**'] # ignore all branches. Comment this line to run your workflow below on every push. | |||
# branches-ignore: ['**'] # ignore all branches. Comment this line to run your workflow below on every push. |
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.
Uncomment
704282b
* upgrade codcov instance to c7i * [MOD-6763] bfloat16 - distance calculation functions (#445) * update arch_opt macros in bf16 BM * fix macro check * Remove arch_opt enum and use cpu features flags instead (#459) * FP16 distance functions (#453) * [MOD-6764] Introduce bfloat16 datatype (#454) * Introduce bfloat16 datatype add Datatype to `VecSimIndexAbstract` template args. add template to SetDistFunc and have specialized implemntation for each <dataType, distType> combintation now the dist function pointer argument is not neseccesary, we can simple return the function. move using dist_func_t to spaces_aux.h (should be in a file included by both L2_spaces.h/IP.spaces.h and spaces.h) * move getdistance imp to spaces.cpp * move normalize function from vec_utils to spaces: spaces.h: get normalize function. spaces.cpp: specialized templates according to the datatype for the normalization functions spaces/normalize/normalize_naive.h: templated naive implementations of normalization functions VecSimIndexAbstract must have both DataType and DistType add VecSimType_BFLOAT16 update vec_utile accordingly bfloat16.h: add bfloat16_to_float32 for little and big TieredFactory::NewIndex calls TieredHNSWFactory::TieredFactory::NewIndex instead of implmentation duplication add bfloat to index factory for NewIndex and EstimateInitialSize * add no_opt functions tests for bfloat16 also add normalization function test for bf16 * fixed nohrmalized value * add bf16 benchmarks: add serialized hnsw bf16 files hnswfactory: add ctor from file for bf16 add fitMemory and run it at the begining of each benchmark to tighten memory. * update bm_files script * add flow tests to bf16 bruteforce: L2 batch iterator range query multivalue hnsw: serialization L2 batch iterator range multi tiered: create search and insert * add bfloat16 module to toml * upgrade scipy nupy * also use python 3.10 * upgrade PR python to 3.10 * update serializer * bm: fix casts unit tests: add test_bf16 * more unit tests * tiered tests * add index_type assertion ti hnsw serialization test add desgnated classes for bf and flat in bf16 unit test * unit test final * repalce cast to dynamic casts * add get neighors test to tiered add normalize test for bfloat16 in testcommon * use bit_cast * upgrade codecov machine * Revert "upgrade codecov machine" This reverts commit 7619b05. * Revert "use bit_cast" This reverts commit 59b8fab. * fix alignment intialization by changing the order * make bfloat16_to_float32 templated accroding to system's endianess * eliminate default in GetDistFunc add test for invalid metric * add test fot fit memory * split fit memory tests * run merge queue flow * add override to fit memory * upload valgrind artifacts on failure * _mm256_loadu_epi16 is supported as of gcc1, use _mm256_lddqu_si256 instead * fix fit memory test (#461) * fix fit memory test * remove xenial checks * remove irrelevant comment * free index in seralization test * Remove avx512_BW_VL (#460) * remove bw_vl arch (not needed, avx512 is enough) * remove xenial from merge queue flow * fix fit memory test (#461) * fix fit memory test * remove xenial checks * remove irrelevant comment * free index in seralization test * install gcc10 bionic * install newer vg ubuntu18 * exit valgrind directory * [MOD-6775] introduce fp16 type! (#462) * remove bw_vl arch (not needed, avx512 is enough) * remove xenial from merge queue flow * introduce fp16 type! change bfloat and fp16 to struct typedef to avoid ambiguty between them * added flow tests * fp16 benchmarks * fix hnsw flow test * add float616 to serializing script add fp16 files to bm files decrease testSizeEstimation dim size to make it run fasetr in debug * set log call back to null in benchmarks * remove struct typedef add default ctor * add comma seriaizer file * disable temp flow * disabe for real * remove constexpr from bfloat default ctor declaring a default ctor as constexpr is allowed as of c++20, and this feature in particular is supported as of gcc10 I don't see any benefit using this feature... * test focal * disable temp flow --------- Co-authored-by: alonre24 <alonreshef24@gmail.com>
* remove bw_vl arch (not needed, avx512 is enough) * remove xenial from merge queue flow * introduce fp16 type! change bfloat and fp16 to struct typedef to avoid ambiguty between them * added flow tests * fp16 benchmarks * fix hnsw flow test * add float616 to serializing script add fp16 files to bm files decrease testSizeEstimation dim size to make it run fasetr in debug * set log call back to null in benchmarks * remove struct typedef add default ctor * add comma seriaizer file * disable temp flow * disabe for real * remove constexpr from bfloat default ctor declaring a default ctor as constexpr is allowed as of c++20, and this feature in particular is supported as of gcc10 I don't see any benefit using this feature... * test focal * disable temp flow (cherry picked from commit 704282b)
* upgrade codcov instance to c7i (cherry picked from commit b5cc93b) * [MOD-6763] bfloat16 - distance calculation functions (#445) (cherry picked from commit 850d6a8) * update arch_opt macros in bf16 BM (cherry picked from commit 253dcd3) * fix macro check (cherry picked from commit 26b047d) * Remove arch_opt enum and use cpu features flags instead (#459) (cherry picked from commit f98793a) * FP16 distance functions (#453) (cherry picked from commit 9420e77) * [MOD-6764] Introduce bfloat16 datatype (#454) * Introduce bfloat16 datatype add Datatype to `VecSimIndexAbstract` template args. add template to SetDistFunc and have specialized implemntation for each <dataType, distType> combintation now the dist function pointer argument is not neseccesary, we can simple return the function. move using dist_func_t to spaces_aux.h (should be in a file included by both L2_spaces.h/IP.spaces.h and spaces.h) * move getdistance imp to spaces.cpp * move normalize function from vec_utils to spaces: spaces.h: get normalize function. spaces.cpp: specialized templates according to the datatype for the normalization functions spaces/normalize/normalize_naive.h: templated naive implementations of normalization functions VecSimIndexAbstract must have both DataType and DistType add VecSimType_BFLOAT16 update vec_utile accordingly bfloat16.h: add bfloat16_to_float32 for little and big TieredFactory::NewIndex calls TieredHNSWFactory::TieredFactory::NewIndex instead of implmentation duplication add bfloat to index factory for NewIndex and EstimateInitialSize * add no_opt functions tests for bfloat16 also add normalization function test for bf16 * fixed nohrmalized value * add bf16 benchmarks: add serialized hnsw bf16 files hnswfactory: add ctor from file for bf16 add fitMemory and run it at the begining of each benchmark to tighten memory. * update bm_files script * add flow tests to bf16 bruteforce: L2 batch iterator range query multivalue hnsw: serialization L2 batch iterator range multi tiered: create search and insert * add bfloat16 module to toml * upgrade scipy nupy * also use python 3.10 * upgrade PR python to 3.10 * update serializer * bm: fix casts unit tests: add test_bf16 * more unit tests * tiered tests * add index_type assertion ti hnsw serialization test add desgnated classes for bf and flat in bf16 unit test * unit test final * repalce cast to dynamic casts * add get neighors test to tiered add normalize test for bfloat16 in testcommon * use bit_cast * upgrade codecov machine * Revert "upgrade codecov machine" This reverts commit 7619b05. * Revert "use bit_cast" This reverts commit 59b8fab. * fix alignment intialization by changing the order * make bfloat16_to_float32 templated accroding to system's endianess * eliminate default in GetDistFunc add test for invalid metric * add test fot fit memory * split fit memory tests (cherry picked from commit e018d91) * run merge queue flow (cherry picked from commit 4670c59) * add override to fit memory (cherry picked from commit f994c79) * upload valgrind artifacts on failure (cherry picked from commit 7ece68d) * _mm256_loadu_epi16 is supported as of gcc1, use _mm256_lddqu_si256 instead (cherry picked from commit c521d82) * fix fit memory test (#461) * fix fit memory test * remove xenial checks * remove irrelevant comment * free index in seralization test (cherry picked from commit a0b70c8) * Remove avx512_BW_VL (#460) * remove bw_vl arch (not needed, avx512 is enough) * remove xenial from merge queue flow * fix fit memory test (#461) * fix fit memory test * remove xenial checks * remove irrelevant comment * free index in seralization test * install gcc10 bionic * install newer vg ubuntu18 * exit valgrind directory (cherry picked from commit d2e1d4f) * [MOD-6775] introduce fp16 type! (#462) * remove bw_vl arch (not needed, avx512 is enough) * remove xenial from merge queue flow * introduce fp16 type! change bfloat and fp16 to struct typedef to avoid ambiguty between them * added flow tests * fp16 benchmarks * fix hnsw flow test * add float616 to serializing script add fp16 files to bm files decrease testSizeEstimation dim size to make it run fasetr in debug * set log call back to null in benchmarks * remove struct typedef add default ctor * add comma seriaizer file * disable temp flow * disabe for real * remove constexpr from bfloat default ctor declaring a default ctor as constexpr is allowed as of c++20, and this feature in particular is supported as of gcc10 I don't see any benefit using this feature... * test focal * disable temp flow (cherry picked from commit 704282b) --------- Co-authored-by: meiravgri <meirav.grimberg@redis.com> Co-authored-by: meiravgri <109056284+meiravgri@users.noreply.github.com> Co-authored-by: alonre24 <alonreshef24@gmail.com>
This PR introduces a new data type, FLOAT16, to the VecSim API.
New
FLOAT16_STRING
etc.).Changes
uint16_t
to a struct to avoid ambiguity between themMark if applicable