Repository navigation
[BREAKING, perf] Compact controller state with partition-local rows - #249
ji-huazhong wants to merge 2 commits into
Conversation
Signed-off-by: ji-huazhong <hzji210@gmail.com>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
This issue has been tackled in the Rust controller. Maybe it's better to fix the python controller in next release so that not all controller backends introduces breaking changes related to ckpt? |
Signed-off-by: ji-huazhong <hzji210@gmail.com>
|
Thanks for putting this together! Switching Before merging, there are a few design and edge-case issues I'd like to discuss: 1. Checkpoint compatibility & migration pathFollowing up on the earlier comment about avoiding another checkpoint breaking change in this release: this PR only changes
2. Aliasing vs. copy inconsistency in
|
Problem and implementation
The Python controller indexes each partition's production and consumption tensors by global sample index. A partition containing only 4,096 samples starting at index 1,000,000 therefore allocates more than a million rows. Multiple partitions duplicate these unused rows, and partition statistics scan them.
Store those tensors in partition-local rows and reuse cleared slots. Consecutive indexes use a range instead of a per-sample dictionary. Full-range queries generate indexes on demand; subsets and irregular layouts cache sorted lookups until membership changes. Queries and updates translate global indexes at the boundary. Sampling order, KV keys, global-indexed query results, and SimpleStorage payload routing are preserved. Reserved rows and consumption retained by
clear_consumption=Falsekeep their existing semantics. Explicit global-indexed status views materialize dense tensors when needed.Breaking change: Python checkpoint format
Python controller checkpoints now use format version 2. Convert existing unversioned checkpoints before loading them:
The converter preserves the original directory, copies storage files unchanged, retains reserved rows and historical consumption, and validates the converted checkpoint before publishing the destination. Load the result with
tq.load_checkpointas usual.Rust already stores partition-local rows. Its checkpoint format is unchanged; its Python snapshot adapter now constructs the compact representation. The converter does not convert between controller backends.
Performance
CPU microbenchmarks against
ffde754: 4,096 samples, 16 fields, two consumer tasks, ARM64, PyTorch 2.6.0, one Torch thread. Queries use the median of 15 interleaved rounds of 50 calls (five calls for statistics); insert/clear measurements use 21 independently prepared partitions. All query caches are warmed where applicable.Dense writes and partial clears still cost more than the original implementation. Compared with the initial compact-state commit
0a0cf72, the range optimization improves batch insertion from 1.28 ms to 0.92 ms and reduces retained index storage, while consumption queries increase from 7.9 µs to 12.8 µs because their indexes are now generated per request. These CPU measurements do not imply the same speedup for end-to-end training.Controller state memory
The comparison accounts for production/consumption tensor buffers, row mapping and free-list objects/integers, and unique query-index buffers. Unchanged metadata and small tensor/cache wrappers are excluded; shared small integers are counted conservatively. These are retained state-structure sizes, not process RSS or peak query/training memory.
For the 64-partition case, state tensors shrink from 38,338,560 to 1,179,648 bytes. Range descriptors and free lists add 12,028 bytes, giving 1,191,676 bytes in total. Complete contiguous ranges retain no query-index buffers; those tensors are created during a query and released afterward. Irregular layouts materialize the row dictionary, and partial ranges retain query caches. Explicit global-indexed status views still allocate dense tensors on demand. These figures apply to the Python controller; Rust already uses partition-local rows.
Validation
0a0cf72completed 20 Geo3K / Qwen3.5-35B-A3B steps using the Python controller and SimpleStorage, exit code 0, with matching input-sample multisets and process source hashes. Finalcritic/score/mean: 0.7144; last-five-step mean: 0.6334. The subsequent range/cache optimization has been validated by the tests above, without another training run.