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

Optimize to_cupy and values #11648

Open
vyasr opened this issue Sep 2, 2022 · 2 comments
Open

Optimize to_cupy and values #11648

vyasr opened this issue Sep 2, 2022 · 2 comments
Labels
improvement Improvement / enhancement to an existing function Performance Performance related issue Python Affects Python cuDF API.

Comments

@vyasr
Copy link
Contributor

vyasr commented Sep 2, 2022

Currently series.values and especially series.to_cupy() are substantially slower than cupy.asarray(series).

In [2]: s = cudf.Series(range(10000))

In [3]: %timeit s.values
81.4 µs ± 1.68 µs per loop (mean ± std. dev. of 7 runs, 10,000 loops each)

In [4]: %timeit cp.asarray(s)
19.1 µs ± 168 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)

In [5]: %timeit s.to_cupy()
349 µs ± 75.2 µs per loop (mean ± std. dev. of 7 runs, 1 loop each)

There are at least two obvious potential culprits in Frame._to_array (the underlying method for to_cupy):

In [11]: df = cudf.DataFrame({'a': [1], 'b': [3.], 'c': ['a']})

In [12]: %timeit cudf.utils.dtypes.find_common_type([col.dtype for col in df._data.values()])
53.6 µs ± 530 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each)

In [13]: df = cudf.DataFrame({'a': [1], 'b': [3.]})

In [14]: %timeit cudf.utils.dtypes.find_common_type([col.dtype for col in df._data.values()])
39.8 µs ± 1.01 µs per loop (mean ± std. dev. of 7 runs, 10,000 loops each)

The implementation of values drops down to ColumnBase.values and requires some deeper consideration. However, since we use .values frequently internally (and we occasionally use to_cupy) we are likely giving up a lot of performance. We should profile these functions to determine the bottlenecks, and if there are valid reasons for them we should establish some policies on how to select the right function to use when performing these conversions to arrays internally. While this exact analogy does not hold for DataFrame (because that doesn't support the conversion to an array), any optimization that we make for Series will likely also help speed up DataFrame operations.

@vyasr vyasr added Python Affects Python cuDF API. Performance Performance related issue improvement Improvement / enhancement to an existing function labels Sep 2, 2022
@github-actions
Copy link

github-actions bot commented Oct 3, 2022

This issue has been labeled inactive-30d due to no recent activity in the past 30 days. Please close this issue if no further response or action is needed. Otherwise, please respond with a comment indicating any updates or changes to the original issue and/or confirm this issue still needs to be addressed. This issue will be labeled inactive-90d if there is no activity in the next 60 days.

@vyasr
Copy link
Contributor Author

vyasr commented May 17, 2024

CC @mroeschke (might be of interest given some of your recent comments about converting to device and all the internal reworkings you're doing with our columns)

rapids-bot bot pushed a commit that referenced this issue May 21, 2024
xref #11648

Essentially refactors `Frame._to_array` to short circuit some checks for a `Frame` with 1 column or `ndim == 1` 

```python
In [1]: import cudf

In [2]: s = cudf.Series(range(10000))

In [3]: %timeit s.to_cupy()
252 µs ± 3.47 µs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)  # PR

419 µs ± 2.21 µs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)  # branch 24.06
```

I needed to add `Frame.ndim` which will raise a `NotImplementedError` (until Frame actually becomes an ABC)

Authors:
  - Matthew Roeschke (https://github.com/mroeschke)

Approvers:
  - Bradley Dice (https://github.com/bdice)
  - GALI PREM SAGAR (https://github.com/galipremsagar)

URL: #15792
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Improvement / enhancement to an existing function Performance Performance related issue Python Affects Python cuDF API.
Projects
Status: Todo
Status: In Progress
Development

No branches or pull requests

2 participants