Skip to content

[BREAKING, perf] Compact controller state with partition-local rows - #248

Closed
ji-huazhong wants to merge 1 commit into
Ascend:mainfrom
ji-huazhong:perf/optimization
Closed

ji-huazhong wants to merge 1 commit into
Ascend:mainfrom
ji-huazhong:perf/optimization

Conversation

@ji-huazhong

Copy link
Copy Markdown
Collaborator

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, reuse cleared slots, and cache sorted global-index/row lookups until partition 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=False keep 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:

python scripts/convert_checkpoint.py /path/to/old_checkpoint /path/to/converted_checkpoint

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_checkpoint as 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, with 4,096 samples, 16 fields and two consumer tasks, using one Torch thread and warmed query caches:

Operation Before After
Scan ready samples, dense indexes 337.6 µs 223.9 µs
Query production status, dense indexes 290.2 µs 153.7 µs
Query consumption status, dense indexes 131.5 µs 7.9 µs
Partition statistics, indexes starting at 1,000,000 33.31 ms 0.224 ms

For 64 partitions of 1,024 samples each, measured state storage falls from 38,338,560 to 7,480,576 bytes (80.5% less), including the new row maps, free lists and cached index tensor data. This measures those structures, not process RSS, and excludes small tensor/cache wrapper overhead. Dense single-partition workloads retain the same state tensor size and add mapping/cache memory. These measurements do not imply the same speedup for end-to-end training.

Validation

  • Full pre-commit checks, compileall, Rust clippy, and 18 Rust unit tests passed.
  • Controller partition/Rust tests: 58 passed. Python checkpoint tests: 16 passed. Rust checkpoint tests: 15 passed, one Python-only conversion case skipped.
  • Linux SimpleStorage E2E: 229 passed, six skipped. Final checkpoint suites also passed for both controller backends. Legacy conversion was additionally checked with a checkpoint created by the unchanged main implementation.
  • Full Python suite: 1,006 passed, 16 skipped, one failure and six errors. The same failure/error cases reproduce on main: a worker-death test affected by suite order and six Yuanrong datasystem fixture errors.
  • Geo3K / Qwen3.5-35B-A3B completed 20 steps with the Python controller and SimpleStorage, exit code 0. All 20 steps retained the baseline input-sample multisets, and all 11 recorded process source hashes matched the tested source. Final critic/score/mean: 0.7144; last-five-step mean: 0.6334. This is a training regression run, not evidence of a quality improvement.

Signed-off-by: ji-huazhong <hzji210@gmail.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-30T15:49:54.259346Z 0a0cf72 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant