-
Notifications
You must be signed in to change notification settings - Fork 33
feat: Add scalar quantization dataset #97
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
075f55f
to
0b8f7e8
Compare
This reverts commit be95013.
Co-authored-by: ibhati <[email protected]>
We need to make For reference, see the SimpleData compact and resize implementation. |
I have created PR to dev branch: #117 |
Thank you @razdoburdin for the PR against this branch. I've checked my usage of @ibhati @dian-lun-lin as discussed I reverted the re-compression changes (and the check for trivial data). My last action for this PR would be clean up the RNG generator in |
// Thread-local accumulators | ||
std::vector<MinMaxAccumulator> tls(threadpool.size()); | ||
|
||
// Compute mean and squared sum |
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.
// Compute mean and squared sum | |
// Compute min and max values in dataset |
} | ||
}; | ||
|
||
// operator to find global min and max in dataset |
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.
// operator to find global min and max in dataset | |
// Operator to find global min and max in dataset |
} | ||
}; | ||
|
||
// operator to compress a dataset using a threadpool |
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.
// operator to compress a dataset using a threadpool | |
// Operator to compress a dataset using a threadpool |
// Compute mean and squared sum | ||
threads::parallel_for( | ||
threadpool, | ||
threads::DynamicPartition(data.size(), batch_size), |
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.
Where did we get this batch_size value from? If there is no strong reason for using DynamicParition, we can simply use StaticPartition as used in most of the code. See an example here for instance: https://github.com/intel/ScalableVectorSearch/blob/main/include/svs/index/vamana/index.h#L553
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.
Can we use StaticPartion here as well?
std::move(compressed), scale, bias}; | ||
} | ||
|
||
/// @brief Compact the dataset |
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.
Just to keep in mind we need to dd the Doxygen docstrings for the other functions and some more documentation for SQDataset in next PR
CATCH_REQUIRE(svs_test::prepare_temp_directory()); | ||
size_t num_threads = 2; | ||
|
||
// use uncompressed reference results which should be identical |
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.
// use uncompressed reference results which should be identical | |
// Use uncompressed reference results which should be identical |
// Scale is calculated from (max_data - min_data) / (max_quant - min_quant) | ||
// The dataset features values [-127, 127], the quantization range is given by the MIN | ||
// and MAX elements of the provided type. | ||
constexpr float MIN = std::numeric_limits<T>::min(); |
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 not the minimium value for int8 -128 instead of -127?
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.
Yes, but the dataset is symmetric, not sure why, but it doesn't cause issues.
// and MAX elements of the provided type. | ||
constexpr float MIN = std::numeric_limits<T>::min(); | ||
constexpr float MAX = std::numeric_limits<T>::max(); | ||
constexpr float exp_scale = 254.0F / float(MAX - MIN); |
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.
constexpr float exp_scale = 254.0F / float(MAX - MIN); | |
constexpr float exp_scale = 255.0F / float(MAX - MIN); |
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.
No the dataset min max max values are -127 and 127, respectively. I could have used min()
and max()
, but figured I would use this knowledge about our test data in the test case.
// Calculations are performed in float everywhere and should therefore produce the exact | ||
// same results | ||
CATCH_REQUIRE(sq_dataset.get_scale() == exp_scale); | ||
CATCH_REQUIRE(sq_dataset.get_bias() == exp_bias); |
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 are these checks not failing if the int8 minimum is -128? Not sure
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.
Yeah as explained, these are the values that are not determined from the compression range but rather from data. So all good!
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.
Looks good, just see if we can use StaticParition for the other instance as well
// Compute mean and squared sum | ||
threads::parallel_for( | ||
threadpool, | ||
threads::DynamicPartition(data.size(), batch_size), |
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.
Can we use StaticPartion here as well?
@ibhati everything should be there now. Please update your "change requested" if you think we're ready to merge. |
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.
Thanks @ahuber21 for enabling this capability in SVS.
/intelci |
This PR adds a new class
SQDataset
which implements global scalar quantization.