Minimize Dask resource acquisition in cudf_polars tests - #22646
Conversation
📝 WalkthroughSummary by CodeRabbit
WalkthroughAdds a session-scoped configured ChangesDask Engine Fixture Refactoring
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsStopped waiting for pipeline failures after 30000ms. One of your pipelines takes longer than our 30000ms fetch window to run, so review may not consider pipeline-failure results for inline comments if any failures occurred after the fetch window. Increase the timeout if you want to wait longer or run a Comment |
| @pytest.fixture(scope="module") | ||
| def reset_engine() -> Iterator[DaskEngine]: | ||
| """Module-scoped engine for reset tests — independent of ``engine``. | ||
| def reset_engine(dask_client: distributed.Client) -> Iterator[DaskEngine]: # type: ignore[name-defined] |
There was a problem hiding this comment.
Just import distributed in the TYPE_CHECKING block, no?
There was a problem hiding this comment.
I ended up using a try/except for import distributed instead of distributed = pytest.importorskip in 01688c0 since the latter was probably preventing mypy from using that alias as a module
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
python/cudf_polars/tests/streaming/test_dask.py (1)
171-184:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winGuarantee engine cleanup when assertions fail
test_reset_after_shutdown_raisesdoes manual teardown, but if an assertion fails before the lastshutdown(), the engine may not be cleaned up. Wrap the assertions intry/finallyso cleanup is unconditional.Proposed fix
def test_reset_after_shutdown_raises(dask_client: distributed.Client) -> None: """``shutdown`` is idempotent; ``_reset`` after shutdown raises every time.""" engine = DaskEngine( dask_client=dask_client, executor_options={"max_rows_per_partition": 10}, ) - engine.shutdown() - engine.shutdown() # idempotent - with pytest.raises(RuntimeError, match="shut-down"): - engine._reset() - with pytest.raises(RuntimeError, match="shut-down"): - engine._reset() # still raises on a second attempt - engine.shutdown() # still safe after a failed _reset + try: + engine.shutdown() + engine.shutdown() # idempotent + with pytest.raises(RuntimeError, match="shut-down"): + engine._reset() + with pytest.raises(RuntimeError, match="shut-down"): + engine._reset() # still raises on a second attempt + finally: + engine.shutdown() # always clean up even on assertion failureAs per coding guidelines, "Ensure proper cleanup in del and context managers to prevent GPU memory leaks."
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@python/cudf_polars/tests/streaming/test_dask.py` around lines 171 - 184, The test test_reset_after_shutdown_raises creates a DaskEngine and calls shutdown multiple times but doesn't guarantee engine.shutdown() runs if an assertion fails; wrap the assertions that call engine._reset() in a try/finally so engine.shutdown() is always invoked for cleanup. Concretely, after constructing engine (DaskEngine(...)) and the initial shutdown calls, put the two with pytest.raises(...) blocks inside a try block and call engine.shutdown() in the finally block to ensure cleanup even on failure.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@python/cudf_polars/tests/streaming/test_dask.py`:
- Around line 171-184: The test test_reset_after_shutdown_raises creates a
DaskEngine and calls shutdown multiple times but doesn't guarantee
engine.shutdown() runs if an assertion fails; wrap the assertions that call
engine._reset() in a try/finally so engine.shutdown() is always invoked for
cleanup. Concretely, after constructing engine (DaskEngine(...)) and the initial
shutdown calls, put the two with pytest.raises(...) blocks inside a try block
and call engine.shutdown() in the finally block to ensure cleanup even on
failure.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: d84be9bd-4cbf-4bc6-8d52-a0cdec7ade48
📒 Files selected for processing (1)
python/cudf_polars/tests/streaming/test_dask.py
|
/merge |
Similar to #22646 in approach to minimize Ray resource spin-up in cudf_polars tests * Removes `test_scan`, `test_filter`, `test_group_by`, `test_join`, and `test_empty_dataframe` as they already have coverage in other test where we parameterize over engine * For tests needing an instantiated DaskEngine, uses the session-scoped DaskEngine already created in conftest.py * Downsizing the Ray cluster's default parameters by sharing a `ray_init_options` fixture for initialization * `num_cpus` set to 2 instead of auto-detecting virtual cores * `num_gpus` set to 0 (IIUC this detection is only needed by the workers) * `include_dashboard` always `False` * `object_store_memory` set to 256 MB instead of `min(0.3 * system memory, 200GB)` Authors: - Matthew Roeschke (https://github.com/mroeschke) Approvers: - Tom Augspurger (https://github.com/TomAugspurger) - Mads R. B. Kristensen (https://github.com/madsbk) - Lawrence Mitchell (https://github.com/wence-) URL: #22661
Description
The motivation is to help alleviate potential CI issues due to Dask/Ray resource spin-up in cudf_polars tests, starting with
test_dask.pytest_scan,test_filter,test_group_by,test_join, andtest_empty_dataframeas they already have coverage in other test where we parameterize overengineDaskEngine, uses the session-scopedDaskEnginealready created inconftest.pyDaskEngineconstruction, uses a module-scopeddask_clientwith aLocalCluster(tests that use this are just testing engine properties so just uses 1 worker)Overall, this PR reduces the 5 Dask clusters allocated to just 2
Checklist