Repository navigation
perf(data_plane): stop the TQ controller rescanning nested shapes on clear - #5141
Merged
Merged
Conversation
…clear PR #4769 throttled the nested-shape rescan in FieldMeta.remove_samples to once per 1/8 of live samples removed. The rescan is still O(live samples) on the controller's only request thread, so it still stalls every request type: ~1.3 s per 20 s window at 300k live rows. Override remove_samples to never collapse a nested field to non-nested. The collapse has no reader that needs it: storage rebuilds tensors from the stored rows, BatchMeta.get_shapes serves correct per-sample shapes in both forms, and NeMo-RL densifies by row shape in _from_wire. A clear now costs O(cleared samples), and the per-sample dict is skipped for non-nested fields. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Zhiyu Li <[email protected]>
…e drops The override no longer relabels a nested field as regular once its odd-shaped rows are cleared, which fails TQ's test_clear_data_nested_field_becomes_regular. State that in the module docstring, and that code in this repo must not read a field's is_nested or shape label from TQ metadata. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Zhiyu Li <[email protected]>
… relabel Add two guards for the remove_samples override: - test_rows_survive_a_clear_that_stock_would_collapse puts token rows through the real adapter on the simple and mooncake_cpu backends, clears the odd-length row where stock TQ would relabel the field as regular, adds a new length, and checks every row comes back unchanged. - test_no_code_reads_the_tq_field_label fails if nemo_rl code reads TQ's field_schema, get_shapes or is_nested label, which the override leaves nested. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Zhiyu Li <[email protected]>
With one row left, stock TQ always relabels a nested field as regular. Clear down to that one row and check it, then add a row of a new length. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Zhiyu Li <[email protected]>
…ld relabel State in the module docstring and the single-controller guide what the remove_samples override skips and why it is safe: stock TQ re-checks every nested field's label on every clear at O(live rows), the relabel does happen in NeMo-RL, but nothing in NeMo-RL reads the label and data is rebuilt from the stored rows. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Zhiyu Li <[email protected]>
Contributor
Author
|
/ok to test e6f977c |
…he label Replace the regex scan for TQ's field label with an AST test that only nemo_rl/data_plane imports transfer_queue. NeMo-RL never sees TQ's BatchMeta outside the adapter, so the boundary is the real guarantee, and the rule in interfaces.py was not enforced by any test. Say in the docstring and guide that row-shape readers, including the Mooncake read path, get shapes from BatchMeta.get_shapes, which serves the same per-row shapes under either label. Make remove_samples the stock loop minus the relabel block, compare the stock-equivalence replay once, trim the wiring test to wiring, and reuse register_train_partition. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Zhiyu Li <[email protected]>
Contributor
Author
|
/ok to test e9d98d1 |
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Zhiyu Li <[email protected]>
Contributor
Author
|
/ok to test d467335 |
jthomson04
added a commit
to jthomson04/RL
that referenced
this pull request
Nov 18, 2026
…Q clear fix) into jthomson04/dynamo-1.7 Brings in NVIDIA-NeMo#5258, NVIDIA-NeMo#4845, NVIDIA-NeMo#5141 and NVIDIA-NeMo#5201. Git merged the six files both sides changed without a conflict. pyproject.toml, uv.lock and the submodule pins are unchanged. Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: jthomson04 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Follow-up to #4769.
FieldMeta.remove_samples(TQ 0.1.11) rescans every live shape of a nested field to decide whether the field can collapse to non-nested. #4769 throttled that to once per 1/8 of live samples removed, but each rescan is still O(live samples) on the controller's only request thread. Every request type queues behind it.This PR overrides
remove_samplesto skip the nested-to-regular relabel. It is exactly the stock method minus that block, so a clear costs O(cleared rows).Why dropping the collapse is safe
Nothing that needs the collapse reads it:
storage/managers/base.pyprocess_field,simple_storage_manager.py_pack_field_values).BatchMeta.get_shapes, which returns correct per-sample shapes in both forms.transfer_queue.py:_from_wire. It never readsfield_schemaoris_nestedotherwise.Warning
Behavior change: this drops a documented TQ feature. Stock TQ relabels a nested field as regular once its odd-shaped rows are cleared. This override keeps it nested. TQ's own
tests/test_controller_data_partitions.py::test_clear_data_nested_field_becomes_regularfails under the override; the other 48 tests in that file pass. The shapes a client receives do not change. Checked: rows of shape 256, 256 and 128; clear the 128 row; add a 512 row. Both stock and this PR serve[(256,), (256,), (512,)].Nothing in NeMo-RL reads the label. Readers of row shapes, including NeMo-RL's own Mooncake read path (
_get_tensors_thread_workerintransfer_queue.py), get them fromBatchMeta.get_shapes. That serves the same shape for every row under either label. Onlynemo_rl/data_planemay importtransfer_queue, so no other code can read TQ metadata.test_only_the_data_plane_imports_transfer_queuenow enforces that rule, whichinterfaces.pyalready stated but no test checked.Benchmarks
Setup: one TQ 0.1.11 controller over real ZMQ, 64 clients, 300k live rows on average, 8 nested + 8 flat fields. Each client puts 16-row groups and clears 16 keys per cycle (
KV_RETRIEVE_META→MARK_CLEARING→CLEAR_META). Clears are desynchronized across clients, the measured window is 20 s, and the node is an exclusive CPU node.In-process cost of a 16-key clear at 300k live rows: stock p50 797 ms; #4769 p50 0.14 ms with a 686 ms burst; this PR p50 0.13 ms, max 0.23 ms over 3,000 clears.
Not fixed here: a separate ~1 s stall remains. Its timing matches the controller's own GC pause log (1,013 ms GC vs 1,035 ms worst request). With GC frozen after load it drops to ~130 ms. That needs its own change, because freezing at controller start does not cover rows written later.
Tests
tests/unit/data_plane/test_tq_controller_patch.py, 9 tests:clear_metathrough the controller keeps the field nestedGuards against the dropped relabel corrupting a run:
test_rows_survive_a_clear_that_stock_would_collapse(simpleandmooncake_cpu, real adapter). It puts token rows of length 256, 256 and 128 and clears the 128 row, where stock relabels the field as regular. It then clears down to one row, where stock always relabels, puts a 512 row, and asserts every row comes back unchanged at each step. The same sequence on real Ray + TQ 0.1.11 storage: stock reportsis_nested=Falseand this PR reportsTrue, and the rows are identical in both.test_only_the_data_plane_imports_transfer_queueintest_architecture_invariants.py(AST). It passes on today's tree, where all 6 importers are undernemo_rl/data_plane, and fails on a planted import.Ran against TQ at the pinned commit.
ruff0.9.9 andpyreflypass on the changed files.🤖 Generated with Claude Code