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

[Data] optimize dataset.unique() #49296

Merged
merged 3 commits into from
Jan 3, 2025

Conversation

wingkitlee0
Copy link
Contributor

@wingkitlee0 wingkitlee0 commented Dec 17, 2024

Why are these changes needed?

The current implementation uses groupby(column).count() that causes a full sort. The new implementation uses AggregateFn which uses groupby(None) and set() to aggregate unique values.

The time complexity should be O(N / parallelism) according to ds.aggregate().

It's about 10x faster in my local test.

Some part of test_unique is removed because it was designed for the original implementation.

Related issue number

Closes #49298

Checks

  • I've signed off every commit(by using the -s flag, i.e., git commit -s) in this PR.
  • I've run scripts/format.sh to lint the changes in this PR.
  • I've included any doc changes needed for https://docs.ray.io/en/master/.
    • I've added any new APIs to the API Reference. For example, if I added a
      method in Tune, I've added it in doc/source/tune/api/ under the
      corresponding .rst file.
  • I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures at https://flakey-tests.ray.io/
  • Testing Strategy
    • Unit tests
    • Release tests
    • This PR is not tested :(

@wingkitlee0 wingkitlee0 force-pushed the optimize-dataset-unique branch 2 times, most recently from f21dbeb to a2270a7 Compare December 17, 2024 03:42
@wingkitlee0 wingkitlee0 force-pushed the optimize-dataset-unique branch 4 times, most recently from 91c0e5a to 3802155 Compare December 19, 2024 03:09
@wingkitlee0 wingkitlee0 marked this pull request as ready for review December 19, 2024 03:10
@wingkitlee0 wingkitlee0 requested a review from a team as a code owner December 19, 2024 03:10
@wingkitlee0 wingkitlee0 force-pushed the optimize-dataset-unique branch from 2882ed5 to 5c5cc7f Compare December 19, 2024 03:47
@wingkitlee0
Copy link
Contributor Author

@raulchen this should be ready for review. thanks

Copy link
Contributor

@raulchen raulchen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for submitting this PR.
LGTM overall. Just a few small comments.

@raulchen raulchen added the go add ONLY when ready to merge, run all tests label Dec 30, 2024
@wingkitlee0 wingkitlee0 force-pushed the optimize-dataset-unique branch 2 times, most recently from 706c2ae to 80f6cb2 Compare December 31, 2024 00:26
- small clean up to private functions in ds.aggregate

Signed-off-by: Kit Lee <[email protected]>
@wingkitlee0 wingkitlee0 force-pushed the optimize-dataset-unique branch from 80f6cb2 to 4001a64 Compare December 31, 2024 00:47
@raulchen raulchen enabled auto-merge (squash) December 31, 2024 18:14
@github-actions github-actions bot disabled auto-merge January 1, 2025 15:41
@wingkitlee0
Copy link
Contributor Author

@raulchen Happy new year! it looks like something failed in the premerge (after the docstring commit), but I don't have access to see what's going on.

@raulchen
Copy link
Contributor

raulchen commented Jan 2, 2025

Looks unrelated. Retrying failed jobs.

@raulchen raulchen merged commit acec4fe into ray-project:master Jan 3, 2025
5 checks passed
roshankathawate pushed a commit to roshankathawate/ray that referenced this pull request Jan 7, 2025
## Why are these changes needed?

The current implementation uses `groupby(column).count()` that causes a
full sort. The new implementation uses `AggregateFn` which uses
`groupby(None)` and `set()` to aggregate unique values.

The time complexity should be O(N / parallelism) according to
`ds.aggregate()`.

It's about 10x faster in my local test.

Some part of `test_unique` is removed because it was designed for the
original implementation.


## Related issue number

Closes ray-project#49298
---------

Signed-off-by: Kit Lee <[email protected]>
Signed-off-by: Hao Chen <[email protected]>
Co-authored-by: Hao Chen <[email protected]>
roshankathawate pushed a commit to roshankathawate/ray that referenced this pull request Jan 9, 2025
## Why are these changes needed?

The current implementation uses `groupby(column).count()` that causes a
full sort. The new implementation uses `AggregateFn` which uses
`groupby(None)` and `set()` to aggregate unique values.

The time complexity should be O(N / parallelism) according to
`ds.aggregate()`.

It's about 10x faster in my local test.

Some part of `test_unique` is removed because it was designed for the
original implementation.

## Related issue number

Closes ray-project#49298
---------

Signed-off-by: Kit Lee <[email protected]>
Signed-off-by: Hao Chen <[email protected]>
Co-authored-by: Hao Chen <[email protected]>
Signed-off-by: Roshan Kathawate <[email protected]>
anyadontfly pushed a commit to anyadontfly/ray that referenced this pull request Feb 13, 2025
## Why are these changes needed?

The current implementation uses `groupby(column).count()` that causes a
full sort. The new implementation uses `AggregateFn` which uses
`groupby(None)` and `set()` to aggregate unique values.

The time complexity should be O(N / parallelism) according to
`ds.aggregate()`.

It's about 10x faster in my local test.

Some part of `test_unique` is removed because it was designed for the
original implementation.

## Related issue number

Closes ray-project#49298
---------

Signed-off-by: Kit Lee <[email protected]>
Signed-off-by: Hao Chen <[email protected]>
Co-authored-by: Hao Chen <[email protected]>
Signed-off-by: Puyuan Yao <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
go add ONLY when ready to merge, run all tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Data] Use AggregateFn instead of groupby.count for unique()
2 participants