Skip to content

[Data] Preserve count task environment and placement - #68512

Open
jiangxt2 wants to merge 1 commit into
ray-project:masterfrom
jiangxt2:fix/count-remote-args
Open

jiangxt2 wants to merge 1 commit into
ray-project:masterfrom
jiangxt2:fix/count-remote-args

Conversation

@jiangxt2

Copy link
Copy Markdown
Contributor

Description

Preserve the read task's runtime environment and placement options when pushing count() down to file metadata. This lets metadata reads use the same storage access and placement constraints as the original read.

Before: Count tasks discard the read task's environment and placement options and always request 0.5 CPU.

After: Count tasks inherit runtime_env, label_selector, fallback_strategy, and scheduling_strategy. They request 0.5 CPU by default or the smaller explicit read CPU request; an explicit None requests no CPU. GPU and other read resources are not carried over.

Subsystem: Logical planning / query optimization.

Related issues

Related to #67269. This is the count-task option fix split out at the reviewer's request; row-count reuse remains separate.

Additional information

Testing: PYTHONPATH=python:python/ray/data/tests/datasource pytest -q python/ray/data/tests/datasource/test_read_parquet_v2.py — 131 passed with Python 3.12 and PyArrow 23 using a prebuilt Ray Core. The count test checks default, explicit None, 0.1 CPU placement group, and 1 CPU options; it executes count for the zero-CPU fallback and placement group cases.

AI assistance was used to prepare this change.

@jiangxt2
jiangxt2 marked this pull request as ready for review November 24, 2026 09:27
@jiangxt2
jiangxt2 requested review from a team as code owners November 24, 2026 09:27

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request ensures that environment and placement configurations (such as runtime_env, label_selector, fallback_strategy, and scheduling_strategy) are preserved from the original read operation during count pushdown optimization. A corresponding test has been added to verify this behavior. The feedback suggests also preserving placement group-related arguments (placement_group, placement_group_bundle_index, and placement_group_capture_child_tasks) to prevent scheduling violations when placement groups are defined directly in ray_remote_args.

Comment on lines +166 to +178
ray_remote_args={
"num_cpus": min(self._PER_TASK_NUM_CPUS_ALLOCATION, read_num_cpus),
**{
key: read_files.ray_remote_args[key]
for key in (
"runtime_env",
"label_selector",
"fallback_strategy",
"scheduling_strategy",
)
if key in read_files.ray_remote_args
},
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

In Ray, placement groups can be specified either via scheduling_strategy (using PlacementGroupSchedulingStrategy) or directly via the placement_group option in ray_remote_args (along with placement_group_bundle_index and placement_group_capture_child_tasks).

If a user specifies the placement group directly using placement_group in ray_remote_args, this constraint will currently be discarded for the count task, which could lead to scheduling violations or failures if the count task runs on a node without the required access/placement.

To ensure all placement constraints are preserved, we should also carry over placement_group, placement_group_bundle_index, and placement_group_capture_child_tasks.

            ray_remote_args={
                "num_cpus": min(self._PER_TASK_NUM_CPUS_ALLOCATION, read_num_cpus),
                **{
                    key: read_files.ray_remote_args[key]
                    for key in (
                        "runtime_env",
                        "label_selector",
                        "fallback_strategy",
                        "scheduling_strategy",
                        "placement_group",
                        "placement_group_bundle_index",
                        "placement_group_capture_child_tasks",
                    )
                    if key in read_files.ray_remote_args
                },
            },

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The legacy placement_group options are deprecated. When neither scheduling_strategy nor label_selector is present, Ray Data adds a default scheduling strategy; Ray rejects combining a non-None strategy with a concrete legacy placement_group. Blindly forwarding these options can therefore fail. Explicit scheduling_strategy=None may allow the legacy path, but this PR does not forward those legacy options. For placement groups, I'd keep this change scoped to scheduling_strategy.

@ray-gardener ray-gardener Bot added data Ray Data-related issues community-contribution Contributed by the community labels Nov 24, 2026
@abhishekverma-ray abhishekverma-ray added the go add ONLY when ready to merge, run all tests label Nov 27, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Contributed by the community data Ray Data-related issues go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants