-
Notifications
You must be signed in to change notification settings - Fork 6.9k
[Data] Add approximate quantile to aggregator #57598
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
base: master
Are you sure you want to change the base?
[Data] Add approximate quantile to aggregator #57598
Conversation
e0584b6
to
45381b1
Compare
Signed-off-by: You-Cheng Lin (Owen) <mses010108@gmail.com>
45381b1
to
024f199
Compare
Signed-off-by: You-Cheng Lin (Owen) <mses010108@gmail.com>
Signed-off-by: You-Cheng Lin (Owen) <mses010108@gmail.com>
Signed-off-by: You-Cheng Lin (Owen) <mses010108@gmail.com>
Signed-off-by: You-Cheng Lin (Owen) <mses010108@gmail.com>
Signed-off-by: You-Cheng Lin <106612301+owenowenisme@users.noreply.github.com>
Signed-off-by: You-Cheng Lin <106612301+owenowenisme@users.noreply.github.com>
""" | ||
self._require_datasketches() | ||
self._quantiles = quantiles | ||
self._k = k |
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 k
, let's use capacity_per_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.
capacity_per_level
does not feel accurate to me, I think maybe we don't need to hide the detail of k, since user will need to see the doc from datasketches
anyway.
I added link to k params description to guide users to the doc for more info.
sketch = self.zero(self._k) | ||
for value in column: | ||
# we ignore nulls here | ||
if value.as_py() is not None: |
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.
do we need an as_py()
conversion here? What type is this value?
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.
This is because we will get this error when the value is none.
def test_approximate_quantile_ignores_nulls(self, ray_start_regular_shared_2_cpus):
data = [
{"id": 1, "value": 5.0},
{"id": 2, "value": None},
{"id": 3, "value": 15.0},
{"id": 4, "value": None},
{"id": 5, "value": 25.0},
]
ds = ray.data.from_items(data)
result = ds.aggregate(ApproximateQuantile(on="value", quantiles=[0.5]))
assert result["approx_quantile(value)"] == [15.0]
TypeError: float() argument must be a string or a number, not 'pyarrow.lib.NullScalar'
Signed-off-by: You-Cheng Lin (Owen) <mses010108@gmail.com>
Signed-off-by: You-Cheng Lin (Owen) <mses010108@gmail.com>
Why are these changes needed?
Add ApproximateQuantile aggregator to Ray Data using DataSketches KLL.
Reason:
• Enables efficient support for the summary API.
• More scalable than exact Quantile on large datasets.
Note:
• DataSketches is not added as a Ray dependency; if missing, users are prompted to install it.
Here's a simple test to show the efficiency difference between
ApproximateQuantile
andQuantile
In this run with 1e8 rows, the approximate median returned 49,979,428.0 in ~12.46s, while the exact Quantile returned 49,999,999.5 in ~163.33s. The difference reflects the sketch’s accuracy trade-off for significant speed and scalability gains.
When k=800 (the default), we are guaranteed to have the error rate < 0.45% , in this test our error rate is
(49,999,999.5-49,979,428.0)/49,999,999.5
= 0.00041143 = 0.041143% which is < 0.45% , but we get the approximate median 13.11x faster.Related issue number
Checks
git commit -s
) in this PR.method in Tune, I've added it in
doc/source/tune/api/
under thecorresponding
.rst
file.