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 all commits
4d721a9
10af371
2149074
fa414ec
123a6cf
f936549
f60055f
524ae0b
c3211d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
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 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -86,33 +86,6 @@ def _run_record(suite: Suite, argv: list[str]) -> dict[str, Any]: | |
| } | ||
|
|
||
|
|
||
| def _generate_data(case: ResolvedCase, backend: Backend) -> tuple[Any, Any]: | ||
| """Generate case inputs and convert them for the backend.""" | ||
| X, y = generate_data(case) | ||
| return backend.convert_data(case, X, y) | ||
|
|
||
|
|
||
| def _partition_data( | ||
| case: ResolvedCase, backend: Backend | ||
| ) -> tuple[Any, Any, Any, Any]: | ||
| """Partition generated inputs into training and measurement data.""" | ||
| # TODO: Split host inputs before backend conversion, or provide a backend | ||
| # row-slicing hook. Dask-cuDF does not support these positional slices, | ||
| # so categorical inference fails even when only y is selected. | ||
| X, y = _generate_data(case, backend) | ||
| if case.lifecycle == "fit": | ||
| return None, None, X, y | ||
| split = case.training_rows | ||
| return X[:split], y[:split], X[split:], y[split:] | ||
|
|
||
|
|
||
| def _inputs( | ||
| selection: tuple[str, ...], inputs: dict[str, Any] | ||
| ) -> tuple[Any, ...]: | ||
| """Select ordered estimator arguments from named inputs.""" | ||
| return tuple(inputs[name] for name in selection) | ||
|
|
||
|
|
||
| def _base_result( | ||
| suite: Suite, | ||
| case: ResolvedCase, | ||
|
|
@@ -160,23 +133,50 @@ def _prepare_case( | |
| spec: EstimatorSpec, | ||
| client: Any = None, | ||
| ) -> _PreparedCase: | ||
| """Load the estimator class and prepare partitioned case inputs.""" | ||
| """Partition host data, then convert and materialize only required inputs.""" | ||
| estimator_class = backend.load_estimator(spec) | ||
| X_train, y_train, X, y = _partition_data(case, backend) | ||
| operation_args = _inputs(case.input_selection, {"X": X, "y": y}) | ||
| fit_args = ( | ||
| () | ||
| if case.lifecycle == "fit" | ||
| else _inputs(case.fit_input_selection, {"X": X_train, "y": y_train}) | ||
| provider = suite.provider_spec | ||
|
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. This makes two sources for the backend in The new tests have to patch the provider's backend and swap the entry in |
||
|
|
||
| # Generate and partition host data. | ||
| X, y = generate_data(case) | ||
| is_fit = case.lifecycle == "fit" | ||
| if is_fit: | ||
| measured = {"X": X, "y": y} | ||
| else: | ||
| split = case.training_rows | ||
| train = {"X": X[:split], "y": y[:split]} | ||
| measured = {"X": X[split:], "y": y[split:]} | ||
|
|
||
| # Convert only selected inputs, applying provider-specific requirements. | ||
| x_representation = ( | ||
| "csr" | ||
| if case.input_format == "csr" | ||
| else "dataframe" | ||
| if case.dataset == "categorical" | ||
| else "array" | ||
| ) | ||
| # Keep materialized inputs alive in the prepared case across every warmup | ||
| # and measurement, rather than rerunning a lazy conversion graph. | ||
| prepared_inputs = backend.prepare_inputs(operation_args + fit_args, client) | ||
| split = len(operation_args) | ||
|
|
||
| def convert(inputs, selection): | ||
| return tuple( | ||
| provider.convert_data( | ||
| inputs[name], | ||
| estimator=case.estimator, | ||
| role=name, | ||
| representation=x_representation if name == "X" else "array", | ||
| ) | ||
| for name in selection | ||
| ) | ||
|
|
||
| operation_args = convert(measured, case.input_selection) | ||
| fit_args = () if is_fit else convert(train, case.fit_input_selection) | ||
|
|
||
| # Materialize both groups together, then restore their boundary. | ||
| prepared = backend.prepare_inputs(operation_args + fit_args, client) | ||
| boundary = len(operation_args) | ||
| return _PreparedCase( | ||
| estimator_class=estimator_class, | ||
| operation_args=prepared_inputs[:split], | ||
| fit_args=None if case.lifecycle == "fit" else prepared_inputs[split:], | ||
| operation_args=prepared[:boundary], | ||
| fit_args=None if is_fit else prepared[boundary:], | ||
| ) | ||
|
|
||
|
|
||
|
|
||
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 :-/