Skip to content
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
945cf21
fix(page-checkpoint): reserve block 0 as null page when PAGE checkpoi…
ZhiweiYan-96 Nov 9, 2026
ad05a55
Merge remote-tracking branch 'origin/main' into fix/reserve-null-bloc…
whx-sjtu Nov 18, 2026
e487dc0
fix(cache): reserve null storage at pool construction
whx-sjtu Nov 18, 2026
e63edaf
test(cache): reproduce sparse MLA reads beside raw state
whx-sjtu Nov 18, 2026
b0d041f
style: align null-block test imports
whx-sjtu Nov 18, 2026
c2c6932
fix(cache): warm checkpoint copies without writing pages
whx-sjtu Nov 18, 2026
3218500
refactor(cache): share checkpoint warmup in the base builder
whx-sjtu Nov 18, 2026
503c2b2
fix(vllm): bind inherited native checkpoint descriptors
whx-sjtu Nov 18, 2026
ec76c78
Allocate Kimi's block-residual bank once per forward
whx-sjtu Nov 19, 2026
beec9b6
Fix sliced block-residual bank slot writes
whx-sjtu Nov 20, 2026
1e2ef92
Bound Kimi residual reads and pipeline payloads
whx-sjtu Nov 20, 2026
e6350bc
Stabilize Engram registration fixture page spans
whx-sjtu Nov 20, 2026
1473016
Merge complete null-block prerequisite into residual-bank parent
whx-sjtu Nov 21, 2026
c916574
Merge main and preserve decode-image checkpoint warmup
whx-sjtu Nov 21, 2026
71a6aba
Fix wide Kimi residual bank offsets
whx-sjtu Nov 22, 2026
d3f31f5
Preserve configured DCP size during pipeline initialization
whx-sjtu Nov 22, 2026
7989461
Merge main and retain Engram owned-copy tests
whx-sjtu Nov 23, 2026
0915e4a
Fuse closing residual bank writes into attention residual kernel
whx-sjtu Nov 24, 2026
27e7369
Read required DCP width directly and clarify residual closes
whx-sjtu Nov 24, 2026
7698b4a
Merge main and preserve DCP and preload initialization options
whx-sjtu Nov 24, 2026
8839a3a
Merge main initialization policy and complete required test headers
whx-sjtu Nov 24, 2026
e5a5962
Merge branch 'main' into task-3312-bank-cpu-20261119
whx-sjtu Nov 26, 2026
0b6e5ba
Remove unreachable Kimi residual bank copy fallback
whx-sjtu Nov 26, 2026
c26e607
Merge branch 'main' into task-3312-bank-cpu-20261119
whx-sjtu Nov 26, 2026
5029bf6
Merge branch 'main' into task-3312-bank-cpu-20261119
whx-sjtu Nov 27, 2026
65793d2
Merge branch 'main' into task-3312-bank-cpu-20261119
whx-sjtu Nov 27, 2026
b426166
Merge branch 'main' into task-3312-bank-cpu-20261119
whx-sjtu Nov 27, 2026
447e88e
Merge branch 'main' into task-3312-bank-cpu-20261119
whx-sjtu Nov 27, 2026
529fb14
Merge branch 'main' into task-3312-bank-cpu-20261119
whx-sjtu Nov 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions atom/distributed/pp_comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@

# Keys carried between pipeline stages. `sparse_kv_indices` is optional: present
# only when a PP boundary splits a DSA IndexShare group (see model_runner).
# `block_residual` is Kimi-K3's AttnRes block window [T, k, H]. `PP_AUX_KEY`
# relays a drafter's target aux hidden states (`PPAuxRelay`, set/popped by
# model_runner). Keys missing here are silently dropped by the send.
# `block_residual` is Kimi-K3's written AttnRes prefix [T, closed_blocks, H].
# `PP_AUX_KEY` relays a drafter's target aux hidden states (`PPAuxRelay`,
# set/popped by model_runner). Keys missing here are silently dropped by the send.
PP_AUX_KEY = "pp_aux"

_PP_PROXY_KEYS = (
Expand Down
2 changes: 1 addition & 1 deletion atom/model_engine/model_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def init_model_env(
local_rank=local_device_rank,
data_parallel_size=dp_size,
prefill_context_model_parallel_size=config.pcp_group_size,
decode_context_parallel_size=getattr(config, "decode_context_parallel_size", 1),
decode_context_parallel_size=config.decode_context_parallel_size,
disable_custom_all_reduce=config.disable_custom_all_reduce,
device_communicators=device_communicators,
)
Expand Down
52 changes: 44 additions & 8 deletions atom/model_ops/attention_residual.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def _fused_quant_dtype(norm: RMSNorm | None) -> torch.dtype | None:
class AttnRes(nn.Module):
"""One attention-residual mixing site.

Mixes the B candidates of ``block_residual`` with a running ``prefix_sum``:
Mixes the active B candidates of a block bank with a running ``prefix_sum``:
rmsnorm each of the B+1, score = <normed, score_weight>, softmax over B+1,
weighted sum. ``proj`` and ``norm`` define that scoring; their product is a
load-time constant folded into a single [H] vector (see ``score_weight``).
Expand All @@ -68,7 +68,7 @@ class AttnRes(nn.Module):
False there is no mixing and no block state; forward degenerates to
``out_norm(prefix_sum + addends)``, i.e. the ordinary pre-norm residual
step. ``proj``/``norm`` are then unused and may be None.
* ``block_residual`` empty vs populated -- with no candidates yet the
* the active bank prefix empty vs populated -- with no candidates yet the
softmax is a no-op, so the same degenerate path applies.
* ``out_norm`` -- the caller's rmsnorm OF THE RESULT. Passing one is what
decides the fusion: it is folded into the kernel's store and the returned
Expand Down Expand Up @@ -112,9 +112,11 @@ def __init__(
self.eps = 1e-6 if norm is None else _rms_eps(norm)
self.out_eps = 1e-6 if out_norm is None else _rms_eps(out_norm)
self.score_weight: torch.Tensor | None = None
# Set only on the site that closes out blocks (see maybe_close_block).
# Decoder sites read the slots closed before their logical layer index;
# an unbounded site (the output mix) reads every supplied candidate.
self.block_size = block_size
self.layer_idx = layer_idx
self.num_blocks = None if block_size is None else -(-layer_idx // block_size)

@property
def out_quant_dtype(self) -> torch.dtype | None:
Expand Down Expand Up @@ -154,7 +156,8 @@ def forward(
block_residual: torch.Tensor | None = None,
add_hidden: torch.Tensor | None = None,
add_hidden2: torch.Tensor | None = None,
) -> tuple[torch.Tensor | tuple[torch.Tensor, torch.Tensor], torch.Tensor]:
close_block: bool = False,
) -> tuple[torch.Tensor | tuple[torch.Tensor, torch.Tensor], torch.Tensor | None]:
"""Returns ``(mixed_output, prefix_out)``.

The addends are the caller's ``prefix_sum = prefix_sum + ...``, folded
Expand All @@ -166,12 +169,29 @@ def forward(
``mixed_output`` is a ``(quantized, scale)`` tuple when ``out_norm``
fuses a per-token quant, on BOTH branches below -- the kernel folds it,
and the fallback gets it from calling that same out_norm.

``close_block`` banks the prefix at block boundaries and returns None
for it, so the next site starts a fresh prefix.
"""
if prefix_sum is None:
prefix_sum, add_hidden, add_hidden2 = add_hidden, add_hidden2, None
assert prefix_sum is not None

if self.enabled and block_residual is not None and block_residual.shape[1] > 0:
close_block = (
close_block
and self.enabled
and self.block_size is not None
and self.layer_idx % self.block_size == 0
)
if (
self.enabled
and block_residual is not None
and (
self.num_blocks
if self.num_blocks is not None
else block_residual.shape[1]
)
> 0
):
score_weight = self.score_weight
if score_weight is None: # loader hook did not run (plugin hosts)
self.process_weights_after_loading()
Expand All @@ -188,6 +208,8 @@ def forward(
self.out_eps,
add_hidden2,
self.out_quant_dtype,
self.num_blocks,
close_block=close_block,
)

# Nothing to mix (residuals off, or no candidates yet). Apply by hand
Expand All @@ -197,14 +219,27 @@ def forward(
if add_hidden2 is not None:
prefix_sum = prefix_sum + add_hidden2
mixed = prefix_sum if self.out_norm is None else self.out_norm(prefix_sum)
if close_block:
_, prefix_sum = self.maybe_close_block(prefix_sum, block_residual)
return mixed, prefix_sum

def window(self, block_residual: torch.Tensor | None) -> torch.Tensor | None:
"""Materialize the candidate view for auxiliary extraction.

Normal forwards pass the bound to the opaque op without creating a view.
"""
if self.num_blocks is None or block_residual is None:
return block_residual
if block_residual.shape[1] < self.num_blocks:
raise RuntimeError(f"expected a bank of >= {self.num_blocks} blocks")
return block_residual[:, : self.num_blocks]

def maybe_close_block(
self,
prefix_sum: torch.Tensor,
block_residual: torch.Tensor | None,
) -> tuple[torch.Tensor | None, torch.Tensor | None]:
"""Append ``prefix_sum`` as a candidate every ``block_size`` layers.
"""Copy ``prefix_sum`` into its slot of the bank every ``block_size`` layers.

Returns the new ``(block_residual, prefix_sum)``. A closed-out block
leaves prefix_sum None: the running sum has been banked as a candidate
Expand All @@ -216,5 +251,6 @@ def maybe_close_block(
if self.layer_idx % self.block_size != 0:
return block_residual, prefix_sum
assert block_residual is not None
block_residual = torch.cat([block_residual, prefix_sum.unsqueeze(1)], dim=1)
# Keep the write relative to the bank view's own storage offset.
block_residual.select(1, self.layer_idx // self.block_size).copy_(prefix_sum)
Comment thread
whx-sjtu marked this conversation as resolved.
Resolved
return block_residual, None
Loading
Loading