Repository navigation
[core] impl backpressure for async streaming generators - #64383
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces non-blocking backpressure support for async streaming generators in Ray by utilizing an asyncio.Event and a C++ trampoline callback to wake the event loop when objects are consumed, preventing thread blockage. The changes span the Cython interface, C++ core worker, and include comprehensive test coverage. The review feedback highlights a potential segmentation fault in NotifyAsyncGeneratorBackpressureUnblock due to a missing null check on the callback, and suggests explicitly clearing the event and loop references in the finally block of execute_streaming_generator_async to avoid reference leaks.
5cc2a06 to
6c12d76
Compare
Signed-off-by: Rueian Huang <[email protected]>
6c12d76 to
c541446
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c541446aa1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Signed-off-by: Rueian Huang <[email protected]>
|
@karticam @sampan-s-nayak can you help review pls? |
Signed-off-by: Rueian Huang <[email protected]>
sampan-s-nayak
left a comment
There was a problem hiding this comment.
Thanks for working on this, mostly looks good except for a few concerns
| # Block inline on backpressure (no-op when disabled). Each sync | ||
| # generator runs on its own execution thread, so blocking here | ||
| # does not stall other tasks. | ||
| _wait_for_object_consumed(context) |
There was a problem hiding this comment.
why do we need this? wont _reserve_actor_generator_slot(context) check conditions for us?
There was a problem hiding this comment.
We do need this. This, WaitUntilObjectConsumed, was for task-level backpressure and was originally done inside the ReportGeneratorItemReturns. I moved it out because it would block the thread, but to support async, we need an async version of that, which is now _async_wait_for_object_consumed.
_wait_for_object_consumed here is making them symmetrical.
There was a problem hiding this comment.
ahh got it, I remember now thanks!
|
|
||
| # Fallback re-check interval for the async backpressure wait. The event is | ||
| # woken promptly by the core worker when consumption advances; this bounds how | ||
| # long an async generator can stay parked if a wake-up is ever missed (e.g. a |
There was a problem hiding this comment.
should we do without this and fix any issues we spot? wondering if keeping this ends up hiding issues in our implementation
There was a problem hiding this comment.
Yeah, makes sense. I added the wake-up everywhere it is needed in the latest commit.
Signed-off-by: Rueian Huang <[email protected]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit b260378. Configure here.
Signed-off-by: Rueian Huang <[email protected]>
Signed-off-by: Rueian Huang <[email protected]>
8387344 to
c92f4dd
Compare
Signed-off-by: Rueian Huang <[email protected]>
|
Thank you @sampan-s-nayak! |
Three independent Windows-only breaks, all verified against postmerge builds 18675/18684: - generator_waiter_test.cc: MSVC C2131 — a by-ref-captured constexpr local used as an array bound inside a lambda is not a constant expression to MSVC. Make the test constants static constexpr. Broken since #64383. - test_streaming_generator: move from the medium to the large shard. Passing Windows runs take ~296s against the moderate 300s limit (build 18675: PASSED in 296.2s; build 18684: TIMEOUT at 300s in 2/2 attempts, mid-suite at test 21-22 of 23) — it is slow, not hung. - test_runtime_env_uv::test_uv_with_version_and_check: use importlib.metadata instead of pkg_resources. virtualenv >= 21 (bumped in #64257) no longer seeds setuptools into the venvs Ray creates, and setuptools >= 83 removed pkg_resources entirely, so the test must not depend on it regardless of the virtualenv pin decision in #64739. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: elliot-barn <[email protected]>
…ile error, streaming-generator timeout, uv test (#64865) ## Why are these changes needed? Fixes all four Windows test failures on master postmerge (builds 18675/18684). Windows tests run only on release-automation-triggered postmerge builds, so these landed silently. ### 1. `test_experimental_collective` — torch gloo broken on Windows (pin torch 2.7.0) Fails since #64257 bumped torch `2.7.0 → 2.9.0`: ``` RuntimeError: makeDeviceForHostname(): unsupported gloo device ``` torch 2.8/2.9 stock Windows wheels are built **without libuv**, and gloo's TCP transport is Linux-only, so `torch.distributed`'s gloo backend cannot initialize at all on Windows (pytorch/pytorch#150381). Fixed upstream via pytorch/gloo#472, shipped in torch **2.10** and explicitly not cherry-picked into 2.9.x. Ray's own postmerge bisection (builds 18569–18574) confirmed #64257 as first-bad; Linux/macOS are unaffected. The windowsbuild image previously pip-installed its test deps constrained by `requirements_compiled.txt` directly, so there was no depset to override. This brings it under raydepsets (`ci_windows.depsets.yaml`), mirroring the relax/expand pattern from `ci_data.depsets.yaml`: - `windows_tests_ci_depset_310` — compile `requirements.txt` + `test-requirements.txt` + `dl-cpu-requirements.txt` for windows/py3.10 constrained by `requirements_compiled` (same inputs `build_base.sh` used). - `relaxed_windows_tests_ci_depset_310` — relax torch, torchvision, and the ABI-coupled PyG binaries. - `windows_tests_torch27_ci_depset_310` — expand with `python/requirements/windows-requirements.txt`: `torch==2.7.0`, `torchvision==0.22.0`, and the `+pt27cpu` PyG local builds (explicit local tags because the relaxed lock still emits the torch-2.9.0 find-links and unsafe-best-match would otherwise re-pick `+pt29cpu`). `build_base.sh` installs the final lock hash-stripped with `--no-deps` (same pattern as `ci/ray_ci/macos/macos_ci.sh`). The wanda srcs now key on the lock instead of the four requirements files. The final lock differs from the base resolution by exactly the six torch packages. Windows **wheel** builds are unaffected (hermetic `uv run` env in `build-wheel-windows.sh`). Delete `windows-requirements.txt` and the torch2.7 depsets once the repo-wide torch pin reaches ≥2.10. ### 2. `generator_waiter_test` — MSVC C2131 compile error (cpp tests job) Broken since #64383: a by-ref-captured `constexpr` local used as an array bound inside a lambda is not a constant expression to MSVC. Make the test constants `static constexpr`. ### 3. `test_streaming_generator` — timeout, moved to the large shard Passing Windows runs take ~296s against the moderate (300s) limit (build 18675: PASSED in 296.2s; build 18684: TIMEOUT at 300s in 2/2 attempts, dying mid-suite at test 21–22 of 23) — legitimately slow, not hung. The Windows job selects `//python/ray/tests/...` by path, so the size-tag move keeps Windows coverage. ### 4. `test_runtime_env_uv::test_uv_with_version_and_check` — pkg_resources removed Use `importlib.metadata` instead of `pkg_resources`: virtualenv ≥21 (bumped in #64257) no longer seeds setuptools into the venvs Ray creates, and setuptools ≥83 removed `pkg_resources` entirely, so the test must not depend on it regardless of the virtualenv pin decision in #64739. Ray's non-test code has zero pkg_resources usage. ## Related issue number Root causes: upstream pytorch/pytorch#150381 (item 1); regressions introduced by #64257 (items 1, 4) and #64383 (item 2). ## Checks - Not a duplicate: searched open PRs — none address the Windows gloo/torch failure, the MSVC break, or the streaming-generator timeout. #64739 (virtualenv pin) is complementary: item 4 here makes the test independent of that decision. - Tests run locally: `bazel run //ci/raydepsets:raydepsets -- build ci/raydepsets/configs/ci_windows.depsets.yaml` (all depsets compile; final lock pins `torch==2.7.0+cpu`, diff vs base is exactly the six torch packages); `bazel query` confirms `test_streaming_generator` is a unique target with `size = large`; `pre-commit` passed on all changed files. Windows image build + test runs can only be validated in CI — watch `windowsbuild` (cold rebuild expected) and the Windows cpp/python test jobs on this PR. - AI assistance was used for this change (diagnosis and implementation); reviewed and submitted by a human. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: elliot-barn <[email protected]> Co-authored-by: Claude Fable 5 <[email protected]>
…64383) Allow setting `_actor_generator_backpressure_num_objects` and `_generator_backpressure_num_objects` on async streaming generators by using asyncio.Event. --------- Signed-off-by: Rueian Huang <[email protected]> Signed-off-by: 400Ping <[email protected]>
…ile error, streaming-generator timeout, uv test (ray-project#64865) ## Why are these changes needed? Fixes all four Windows test failures on master postmerge (builds 18675/18684). Windows tests run only on release-automation-triggered postmerge builds, so these landed silently. ### 1. `test_experimental_collective` — torch gloo broken on Windows (pin torch 2.7.0) Fails since ray-project#64257 bumped torch `2.7.0 → 2.9.0`: ``` RuntimeError: makeDeviceForHostname(): unsupported gloo device ``` torch 2.8/2.9 stock Windows wheels are built **without libuv**, and gloo's TCP transport is Linux-only, so `torch.distributed`'s gloo backend cannot initialize at all on Windows (pytorch/pytorch#150381). Fixed upstream via pytorch/gloo#472, shipped in torch **2.10** and explicitly not cherry-picked into 2.9.x. Ray's own postmerge bisection (builds 18569–18574) confirmed ray-project#64257 as first-bad; Linux/macOS are unaffected. The windowsbuild image previously pip-installed its test deps constrained by `requirements_compiled.txt` directly, so there was no depset to override. This brings it under raydepsets (`ci_windows.depsets.yaml`), mirroring the relax/expand pattern from `ci_data.depsets.yaml`: - `windows_tests_ci_depset_310` — compile `requirements.txt` + `test-requirements.txt` + `dl-cpu-requirements.txt` for windows/py3.10 constrained by `requirements_compiled` (same inputs `build_base.sh` used). - `relaxed_windows_tests_ci_depset_310` — relax torch, torchvision, and the ABI-coupled PyG binaries. - `windows_tests_torch27_ci_depset_310` — expand with `python/requirements/windows-requirements.txt`: `torch==2.7.0`, `torchvision==0.22.0`, and the `+pt27cpu` PyG local builds (explicit local tags because the relaxed lock still emits the torch-2.9.0 find-links and unsafe-best-match would otherwise re-pick `+pt29cpu`). `build_base.sh` installs the final lock hash-stripped with `--no-deps` (same pattern as `ci/ray_ci/macos/macos_ci.sh`). The wanda srcs now key on the lock instead of the four requirements files. The final lock differs from the base resolution by exactly the six torch packages. Windows **wheel** builds are unaffected (hermetic `uv run` env in `build-wheel-windows.sh`). Delete `windows-requirements.txt` and the torch2.7 depsets once the repo-wide torch pin reaches ≥2.10. ### 2. `generator_waiter_test` — MSVC C2131 compile error (cpp tests job) Broken since ray-project#64383: a by-ref-captured `constexpr` local used as an array bound inside a lambda is not a constant expression to MSVC. Make the test constants `static constexpr`. ### 3. `test_streaming_generator` — timeout, moved to the large shard Passing Windows runs take ~296s against the moderate (300s) limit (build 18675: PASSED in 296.2s; build 18684: TIMEOUT at 300s in 2/2 attempts, dying mid-suite at test 21–22 of 23) — legitimately slow, not hung. The Windows job selects `//python/ray/tests/...` by path, so the size-tag move keeps Windows coverage. ### 4. `test_runtime_env_uv::test_uv_with_version_and_check` — pkg_resources removed Use `importlib.metadata` instead of `pkg_resources`: virtualenv ≥21 (bumped in ray-project#64257) no longer seeds setuptools into the venvs Ray creates, and setuptools ≥83 removed `pkg_resources` entirely, so the test must not depend on it regardless of the virtualenv pin decision in ray-project#64739. Ray's non-test code has zero pkg_resources usage. ## Related issue number Root causes: upstream pytorch/pytorch#150381 (item 1); regressions introduced by ray-project#64257 (items 1, 4) and ray-project#64383 (item 2). ## Checks - Not a duplicate: searched open PRs — none address the Windows gloo/torch failure, the MSVC break, or the streaming-generator timeout. ray-project#64739 (virtualenv pin) is complementary: item 4 here makes the test independent of that decision. - Tests run locally: `bazel run //ci/raydepsets:raydepsets -- build ci/raydepsets/configs/ci_windows.depsets.yaml` (all depsets compile; final lock pins `torch==2.7.0+cpu`, diff vs base is exactly the six torch packages); `bazel query` confirms `test_streaming_generator` is a unique target with `size = large`; `pre-commit` passed on all changed files. Windows image build + test runs can only be validated in CI — watch `windowsbuild` (cold rebuild expected) and the Windows cpp/python test jobs on this PR. - AI assistance was used for this change (diagnosis and implementation); reviewed and submitted by a human. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: elliot-barn <[email protected]> Co-authored-by: Claude Fable 5 <[email protected]> Signed-off-by: 400Ping <[email protected]>

Allow setting
_actor_generator_backpressure_num_objectsand_generator_backpressure_num_objectson async streaming generators by using asyncio.Event.