Explicit lifetime for the streaming collectives #1316
All Vouch review confidence checks passed
Residual risk 0.19 = Change Risk (0.47) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.47 · 487 lines diff across 6 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.370
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #1316"
general
weight: 0.35
pentschev
Closes #1311, together with #1315.
The Python streaming collectives
ShufflerAsync,SparseAlltoallandAllGatherhad no way to be released. Unextracted data, the progress function and the spill function lived until__dealloc__, which in async code can be much later. In cudf#25074 a failed query kept two completed shufflers alive in a reference cycle.This PR adds
aclose()to all three classes, andasync withtoShufflerAsyncandSparseAlltoall:When
aclose()returns, the collective has completed on this rank, its resources are released and theop_idmay be reused. Unextracted data is freed. Ifinsert_finished()was not called,aclose()inserts the finish markers so that peers do not hang, closes the object and raisesRuntimeError, since skippinginsert_finished()is a bug in the caller.__aexit__does not raise that error when the body raised, so the body's exception propagates unchanged.aclose()waits for every peer. Cancelling it gives control back while the collective keeps finishing in the background, and awaitingaclose()again waits for the same completion.The Cython wrappers now hold the C++ objects in a
shared_ptr, and every background task holds its own reference. A cancelled Python awaiter or a dropped wrapper therefore no longer leaves a task pointing at a destroyed object. The three wrappers derive from a new public abstract base class,rapidsmpf.streaming.coll.Collective, which providesaclose()and can be used to type or check for any streaming collective.cpp_set_py_futurenow leaves a future alone when its event loop has been closed, instead of reporting an ignored exception.Breaking change
In C++,
streaming::ShufflerAsync::insert_finished()andstreaming::SparseAlltoall::insert_finished()are now synchronous and only insert the finish markers. Awaiting completion is a separatewait()coroutine, whichstreaming::AllGatheralso gets. All three classes now follow the same pattern as the non-streaming collectives,insert_finished()followed bywait(). The split lets the Python wrappers raise errors frominsert_finished()at the call, and lets several tasks await completion, whichaclose()needs after a cancelledinsert_finished().No deprecation period is needed. Outside this repository, the only caller is the ndsh join benchmark in libcudf_streaming, which needs a one-line change once this PR is in a nightly (NVIDIA/cudf PR to follow). Old code fails to compile instead of changing behavior, since a
voidcannot be awaited.The Python API is not broken. The wrappers now store the
Contextthey were created with, so thectxargument ofShufflerAsync.insert_finished(),SparseAlltoall.insert_finished()andAllGather.extract_all()is optional and ignored. It will be removed once cudf-polars no longer passes it.Naming
aclose()is the first method of that name in rapidsmpf. Elsewhere we useshutdown(), for example the asyncChannel.shutdown()andMemoryReserveOrWait.shutdown(), and the C++Shuffler::shutdown(). I choseaclose()because it is the Python protocol for closing an async resource: async generators,contextlib.AsyncExitStack, httpx, anyio and Trio use it, andcontextlib.aclosing()calls it.Channel.shutdown()also does something different, since it stops the channel without waiting for anything. What do you guys think?