Repository navigation
Separate benchmark input conversion policy from backend preparation #8888
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
Changes from 1 commit
4d721a9
10af371
2149074
fa414ec
123a6cf
f936549
f60055f
524ae0b
c3211d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,9 +11,10 @@ | |
| from typing import TYPE_CHECKING, Any | ||
|
|
||
| if TYPE_CHECKING: | ||
| from ..suite import ResolvedCase, Suite | ||
| from ..suite import Suite | ||
|
|
||
| from .cuml import CumlBackend | ||
| from .base import InputRepresentation | ||
| from .cuml import CumlBackend, NativeCumlBackend | ||
|
|
||
|
|
||
| def _wait_for_futures(distributed: Any, value: Any) -> None: | ||
|
|
@@ -31,48 +32,32 @@ class DaskBackend(CumlBackend): | |
| """Provide distributed inputs, estimators, and a multi-GPU runtime.""" | ||
|
|
||
| def convert_data( | ||
| self, case: ResolvedCase, X: Any, y: Any | ||
| ) -> tuple[Any, Any]: | ||
| """Convert generated inputs to partitioned Dask collections. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| case : ResolvedCase | ||
| Case defining the dataset shape and representation. | ||
| X : Any | ||
| Complete generated feature data. | ||
| y : Any | ||
| Complete generated target data. | ||
| """ | ||
| # Distributed DBSCAN broadcasts a complete local array itself; it | ||
| # does not accept partitioned Dask collections. | ||
| if case.estimator == "DBSCAN": | ||
| return X, y | ||
| da = importlib.import_module("dask.array") | ||
| cp = importlib.import_module("cupy") | ||
| # TODO: Split training and inference data before backend conversion, | ||
| # then partition and distribute each using the runtime worker count. | ||
| # Fixed two-way chunking leaves every built-in inference input in one | ||
| # partition, so partition-parallel predictions use only one worker. | ||
| # Training also underutilizes clusters with more than two workers. | ||
| chunks = (max(1, case.generated_rows // 2), case.features) | ||
| if case.dataset == "categorical": | ||
| cudf = importlib.import_module("cudf") | ||
| dask_cudf = importlib.import_module("dask_cudf") | ||
| X = dask_cudf.from_cudf(cudf.from_pandas(X), npartitions=2) | ||
| else: | ||
| X = da.from_array(X, chunks=chunks).map_blocks( | ||
| cp.asarray, meta=cp.empty((0, 0), dtype=X.dtype) | ||
| self, | ||
| value: Any, | ||
| *, | ||
| representation: InputRepresentation, | ||
| ) -> Any: | ||
| """Convert one structural representation to distributed device storage.""" | ||
| if representation == "csr": | ||
| raise ValueError("Dask CSR inputs are not supported yet") | ||
|
Comment on lines
+41
to
+42
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| if representation in {"dataframe", "series"}: | ||
| local = NativeCumlBackend.convert_data( | ||
| self, value, representation=representation | ||
| ) | ||
|
Comment on lines
+43
to
+46
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think of having both backends get the host conversion from # backends/cuml.py: NativeCumlBackend.convert_data
if representation == "array":
return importlib.import_module("cupy").asarray(value)
host = super().convert_data(value, representation=representation)
if representation == "csr":
return importlib.import_module("cupyx.scipy.sparse").csr_matrix(
host
)
return importlib.import_module("cudf").from_pandas(host)# backends/dask.py: DaskBackend.convert_data
if representation == "csr":
raise ValueError("Dask CSR inputs are not supported yet")
if representation != "array":
host = super().convert_data(value, representation=representation)
local = importlib.import_module("cudf").from_pandas(host)
return importlib.import_module("dask_cudf").from_cudf(
local, npartitions=2
)
# ... array path unchanged |
||
| return importlib.import_module("dask_cudf").from_cudf( | ||
| local, npartitions=2 | ||
| ) | ||
| if case.estimator == "LabelEncoder": | ||
| cudf = importlib.import_module("cudf") | ||
| dask_cudf = importlib.import_module("dask_cudf") | ||
| y = dask_cudf.from_cudf(cudf.Series(y), npartitions=2) | ||
| else: | ||
| y = da.from_array(y, chunks=(chunks[0],)).map_blocks( | ||
| cp.asarray, meta=cp.empty((0,), dtype=y.dtype) | ||
| if representation != "array": | ||
| raise ValueError( | ||
| f"Unsupported input representation {representation!r}" | ||
| ) | ||
| return X, y | ||
| da = importlib.import_module("dask.array") | ||
| cp = importlib.import_module("cupy") | ||
| # TODO: Use the runtime worker count instead of fixed two-way chunking. | ||
| chunks = (max(1, value.shape[0] // 2), *value.shape[1:]) | ||
| return da.from_array(value, chunks=chunks).map_blocks( | ||
| cp.asarray, meta=cp.empty((0,) * value.ndim, dtype=value.dtype) | ||
| ) | ||
|
|
||
| def prepare_inputs( | ||
| self, inputs: tuple[Any, ...], runtime: Any = 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.
Can this ever trigger?
representationis anInputRepresentationliteral and the only producer is_prepare_case(plus the"series"override inDaskProvider), so no caller should pass anything else. The same branch is repeated inNativeCumlBackend.convert_dataandDaskBackend.convert_data, andtest_conversion_rejects_unknown_requirementsonly exercises this probably unreachable path. I'd drop the raises and the test. If you want to keep one, a one-line comment explaining when it can fire would help. I guess it depends on what we assume about harness authors :-/