Skip to content

feat(compile): prepare tensor inputs for document compression - #12

Open
yu-chen-code wants to merge 1 commit into
masterfrom
feat-graph-packed-metadata
Open

yu-chen-code wants to merge 1 commit into
masterfrom
feat-graph-packed-metadata

Conversation

@yu-chen-code

@yu-chen-code yu-chen-code commented Nov 6, 2026 •

Copy link
Copy Markdown
Owner

What type of PR is this?
/kind feature

What does this PR do / why do we need it:

Refreshed on 2026-11-09 against fork/upstream master a6be99d3. PR1421 is now merged upstream, so its duplicate prerequisite has been removed. Current head: cc5e07742b4cebd421cedb340ac3fcaa3b000947; retained feature/dependency commits: cc5e0774. Git range-diff confirms unchanged feature patches. Focused CPU regression on this exact head: 110 JUnit records, 0 failures, 0 errors. The isolated refresh environments now include master-required PEFT 0.21.2 and accelerate 1.13.0; pip check passes. All numerical runs and older source hashes below are pre-refresh evidence. NPU precision training and formal upstream CI were not rerun for this rebase.

Separate CPU document-boundary planning from graph replay for document-local compression. DocumentCompressionPlan.prepare(device) reuses the existing plan to materialize row indices and original block-start positions before capture. The resulting PreparedCompressionPlan is a pytree: its two index tensors are runtime inputs, while only the model's compression ratio is static.

Its pooling and rotary-position selection avoid Python document loops during replay. Pooling shares the original FP32-softmax helper with the eager plan, preserving its numerical formula and dtype. A single captured joint graph can consume changing document boundaries and complete-block counts at a fixed sequence length.

This is the CP1 metadata foundation, not complete packed DeepSeek-V4.1 DSA support. Multi-rank CP preparation is rejected. The existing model runtime and DSA/Indexer packing-only admission guard remain unchanged: consuming these prepared tensors in native DSA and replacing the Indexer's document loops are separate follow-up work. No fused-attention math or model-specific behavior is added to the compiler.

Validation:

  • Three new CPU tests cover exact FP32/BF16 eager/prepared pooling, positions and gradients; joint-graph replay with changing block counts and index values; and explicit rejection of multi-rank CP preparation.
  • The related new and existing compression-attention, V4.1 model and CP batch-planning regressions passed: 43 tests and 69 subtests.
  • Fixed S=24 and ratio=4: aligned documents and unaligned boundaries use 6, 5 and 4 complete blocks; two distinct boundary layouts have the same tensor shapes. These cases include incomplete document tails without pooling across documents.
  • Ascend 910B2, Torch 2.15.0.dev20261005 / torch-npu 2.15: four ranks, FSDP4, ten AdamW updates, two microbatches per update, changing packed boundaries, and a real shared-bank producer with two consumers. An independent eager model uses per-backward AVG ReduceScatter followed by reconstruction before accumulation, matching the FSDP synchronization contract. Loss, each microbatch's gradients, accumulated gradients, updated parameters, and Adam tensors were exact on all ranks. The fixed acceptance limit remained 1e-3 with denominator floor 1e-8, and all recorded nonfinite counts were zero.
  • Shared eager helper before/after comparisons were torch.equal across 1200 recorded gradient/parameter/Adam tensors. CPU before/after eager and dynamic-graph runs also passed.
  • A separate real runtime-entry probe still raises ValueError: packing-only graph inputs require compression and indexing to be disabled, confirming this PR does not silently admit unsupported native DSA/Indexer execution.
  • Public CI pylint configuration passed with both Python 3.9 and 3.12 targets. No performance claim is made.

Exact source manifests, commands, before/after tensor receipts and raw failures are retained under T020 runs/20261106-graph-capability-spikes. No formal upstream gate is requested or claimed.

Which issue(s) this PR fixes:

None.

Code review checklist [illustration]:

  • whether to verify the function's return value (It is forbidden to use void to mask the return values of security functions and self-developed functions. C++ STL functions can be masked if there is no problem)
  • Whether to comply with SOLID principle / Demeter's law
  • Whether there is UT test case && the test case is a valid (if there is no test case, please explain the reason)
  • Whether the API change is involved
  • Whether official document modification is involved

@yu-chen-code
yu-chen-code force-pushed the feat-graph-packed-metadata branch from b7c7b9c to cc5e077 Compare November 9, 2026 11:24
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