Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions docs/TODO.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@
catalogs, host copy-out pressure, and tensor-parallel execution. See
core-design.md#exact-endpoint-capture and scheduling-runtime-design.md.

[ ] Qualify capacity-blocked host restores and demand recency for individual checkpoints
through exported Kimi K3.1 cores under concurrent long prompts, immediate
continuations, and aliased snapshot pressure. Compare reused tokens, request
latency, throughput, snapshot backing pages, and storage skips with equivalent
clocks and cache budgets; include prompt-end and message-boundary follow-ups.
Remove after native serving confirms restoration progress and retention behavior;
CPU scheduler and worker tests do not establish serving performance.

[ ] Correct the 10-byte core payload fixtures in Orbit agent tests
running_groups_are_stopped_and_outlive_their_controller_session and
groups_run_together_on_disjoint_gpus_and_status_lists_them; their transfer
Expand Down
23 changes: 19 additions & 4 deletions docs/core-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -1528,10 +1528,25 @@ role, then consumed-token count, then checkpoint identity. Prompt and terminal
endpoints have the lowest role, earlier message checkpoints follow, and the
conversation anchor has the highest role. Demand recency takes precedence over
role, so an idle conversation's anchor can be reclaimed before a recently used
endpoint. One successfully admitted logical request receives one demand epoch;
all its captures inherit that epoch. Cache reuse touches the matched checkpoint
and its ancestors. Duplicate publication retains the maximum role and epoch.
Preemption carries the epoch into readmission.
endpoint. Each successfully admitted logical request receives a demand epoch;
its captures inherit that epoch. Cache reuse and promotion touch only the selected
checkpoint's snapshot. Successful completion refreshes a published terminal and
its direct parent with one completion-time epoch. The parent commonly holds the
prompt end or last captured message boundary, which remains useful when a follow-up
rewrites generated history. The parent comes from the published checkpoint's cache
record, including duplicate publication; it need not have been captured by the
completing request and may have been restored from a host tier.

Completion refreshes at most two checkpoints. Grandparents retain their own demand
epochs: sharing their pages does not require restoring their rows. Older single-child
ancestors can therefore be compacted under pressure without discarding descendant
pages. When no terminal is published, completion refreshes only the retained prefix.
Cancellation after completed inference also refreshes only that prefix, including
client stop sequences. Cancellation before inference and execution failure do not
refresh recency. Preemption carries the admission epoch into readmission without
refreshing it. Duplicate publication retains the maximum role and epoch of the
matching checkpoint; successful retirement then refreshes it and its direct parent.
Branch points and direct pins still constrain which checkpoints are removable.

The global allocator compares victims for both snapshot rows and physical page
backing. A removable checkpoint is an unpinned leaf or an ancestor with exactly
Expand Down
28 changes: 23 additions & 5 deletions docs/prefix-cache-offload.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,16 @@ unrestorable.

GPU eviction ranks eligible checkpoints by logical-request demand epoch,
retention role, consumed-token count, and identity, as specified in
[checkpoint lifetime](core-design.md#branching-and-lifetime). Host-store eviction
independently removes the least recently used unpinned leaf; when every leaf is
pinned, it compacts the least recently used unpinned single-child ancestor by
[checkpoint lifetime](core-design.md#branching-and-lifetime). GPU demand recency
belongs to the selected snapshot, not every ancestor supplying its pages.
Successful terminal retirement also refreshes its direct parent, including a
shared or host-restored checkpoint, without refreshing earlier ancestors.
Pressure can compact an older single-child ancestor while preserving the reused
descendant's complete page chain and reporting its compaction heir. Direct
copy-out pins and outstanding GPU-use fences still protect transfer resources.
Host-store eviction independently removes the least recently used unpinned leaf;
when every leaf is pinned, it compacts the least recently used unpinned
single-child ancestor by
dropping its row and keeping its pages. A compacted host node stays in the tree
as page-only, no longer matches lookups, and continues to supply chain pages.
A node is evictable only when its store's policy allows it: the memory store standalone evicts any unpinned node, the
Expand Down Expand Up @@ -653,8 +660,19 @@ call from the worker returns without waiting.

Admission consults the store after `plan_admission`: `lookup` runs above the
GPU hit, the policy in section 2.10 decides whether to fetch, and
`admit_planned` receives the inbound request. A newly created ticket starts
the inbound job through `fetch`. On inbound failure the worker cancels each
`admit_planned` receives the inbound request. If capacity prevents reserving
the restore's pages and snapshot row, admission waits while existing requests,
inbound tickets, checkpoint pins, or fenced retirement may release resources.
Waiting plus estimated transfer time must remain below half the estimated
prefill time of the tokens gained. The worker retries after resource changes,
pin release, transfer completion, or wait-budget expiry; expiry is checked even
when resource counts stay unchanged. Other eligible requests can be admitted during this wait.
If no resource holder remains or the budget expires, admission tries recomputation.
If recomputation also lacks capacity, it waits for resource changes without
repeated timeout retries. A successful admission clears the wait accounting so
readmission after preemption starts a separate wait. Pooled lookups keep their
ticket and validated history across retries and recheck GPU residency.
A newly created ticket starts the inbound job through `fetch`. On inbound failure the worker cancels each
waiter and pushes its `Incoming` to the front of the pending queue with host
lookup disabled for that attempt.

Expand Down
8 changes: 6 additions & 2 deletions docs/runtime-core-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -725,8 +725,12 @@ Admission reserves the request's KV pages. System, prompt, and terminal snapshot
acquire backing at their capture boundaries, evicting unpinned checkpoints when
needed. If active requests or transfers hold all suitable backing, optional
retention is skipped. An inbound host restore reserves both its row and pages
before transfer; if its snapshot prevents admission, the request recomputes its
prompt. Snapshot and page ownership remain exclusive through graph
before transfer. A capacity-blocked restore waits while requests, transfers,
or fenced retirement may release backing and its accumulated wait plus estimated
transfer time remains below half the estimated prefill time it replaces. Wait-budget expiry
permits a recompute attempt even without resource progress. With no remaining
resource holder, admission tries recomputation immediately.
Snapshot and page ownership remain exclusive through graph
and transfer completion, including cancellation and duplicate publication.
Once generation drains, unused output-page reservations are released before
retaining the final checkpoint.
Expand Down
13 changes: 9 additions & 4 deletions helios/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,11 @@ impl PrefixCheckpointCache {
})
}

#[cfg(feature = "server")]
pub(crate) fn has_pins(&self) -> bool {
self.nodes.values().any(|node| node.direct_pins != 0)
}

pub(crate) fn single_child(&self, id: CheckpointId) -> Option<CheckpointId> {
if self.nodes.get(&id)?.child_count != 1 {
return None;
Expand Down Expand Up @@ -301,11 +306,11 @@ impl PrefixCheckpointCache {
Ok(self.clock)
}

/// Refresh this snapshot's demand; sharing ancestor pages does not reuse their snapshots.
pub fn touch(&mut self, id: CheckpointId, use_epoch: u64) -> Result<()> {
for ancestor in self.chain(id)? {
let node = self.nodes.get_mut(&ancestor).unwrap();
node.accessed = node.accessed.max(use_epoch);
}
self.checkpoint(id)?;
let node = self.nodes.get_mut(&id).unwrap();
node.accessed = node.accessed.max(use_epoch);
Ok(())
}

Expand Down
121 changes: 115 additions & 6 deletions helios/src/cache/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1144,18 +1144,127 @@ fn retention_prioritizes_demand_epoch_before_role_and_promotes_duplicates() {
}

#[test]
fn lookup_is_read_only_and_admission_touch_refreshes_ancestors() {
fn lookup_is_read_only_and_touch_refreshes_only_the_selected_snapshot() {
let mut cache = cache();
let history = history(2, 0);
let parent = cache.publish_with_retention(&history, &proposal(None, 64, &[0], 0, 0), RetentionRole::Anchor, 1).unwrap().id();
let child = cache.publish_with_retention(&history, &proposal(Some(parent), 128, &[1], 1, 0), RetentionRole::Endpoint, 1).unwrap().id();
let parent = cache
.publish_with_retention(
&history,
&proposal(None, 64, &[0], 0, 0),
RetentionRole::Anchor,
1,
)
.unwrap()
.id();
let child = cache
.publish_with_retention(
&history,
&proposal(Some(parent), 128, &[1], 1, 0),
RetentionRole::Endpoint,
1,
)
.unwrap()
.id();
cache.lookup(&history).unwrap();
assert_eq!(cache.checkpoint(child).unwrap().retention_rank().use_epoch, 1);
assert_eq!(
cache.checkpoint(child).unwrap().retention_rank().use_epoch,
1
);
cache.new_use_epoch().unwrap();
let epoch = cache.new_use_epoch().unwrap();
cache.touch(child, epoch).unwrap();
assert_eq!(cache.checkpoint(parent).unwrap().retention_rank().use_epoch, epoch);
assert_eq!(cache.checkpoint(child).unwrap().retention_rank().use_epoch, epoch);
assert_eq!(
cache.checkpoint(parent).unwrap().retention_rank().use_epoch,
1
);
assert_eq!(
cache.checkpoint(child).unwrap().retention_rank().use_epoch,
epoch
);
cache.touch(child, 1).unwrap();
assert_eq!(
cache.checkpoint(child).unwrap().retention_rank().use_epoch,
epoch
);
assert!(cache.touch(CheckpointId::new(999), epoch).is_err());
}

#[test]
fn duplicate_publication_and_promotion_do_not_refresh_ancestor_snapshots() {
for page_tokens in [64, 128, 256, 2048] {
let mut cache = PrefixCheckpointCache::new([7; 32], 32, 32, page_tokens).unwrap();
let history = history((2 * page_tokens / 64) as u32, 0);
let endpoint = page_tokens as u64;
let parent = cache
.publish_with_retention(
&history,
&proposal(None, endpoint, &[0], 0, 0),
RetentionRole::Anchor,
1,
)
.unwrap()
.id();
let child = cache
.publish_with_retention(
&history,
&proposal(Some(parent), 2 * endpoint, &[1], 1, 0),
RetentionRole::Endpoint,
2,
)
.unwrap()
.id();
let duplicate = cache
.publish_with_retention(
&history,
&proposal(Some(parent), 2 * endpoint, &[2], 2, 5),
RetentionRole::Message,
3,
)
.unwrap();
assert_eq!(duplicate.id(), child);
assert_eq!(
cache.checkpoint(parent).unwrap().retention_rank().use_epoch,
1
);
cache.promote(child, RetentionRole::Anchor, 4).unwrap();
cache.promote(child, RetentionRole::Endpoint, 2).unwrap();
assert_eq!(
cache.checkpoint(parent).unwrap().retention_rank().use_epoch,
1
);
assert_eq!(
cache.checkpoint(child).unwrap().retention_rank(),
RetentionRank {
use_epoch: 4,
role: RetentionRole::Anchor,
consumed_tokens: 2 * endpoint,
}
);
// Recency is local to the snapshot; outstanding GPU reads still protect shared pages.
let retired = cache.evict(EvictionTarget {
pages: 0,
snapshots: 1,
});
assert_eq!(retired.retired[0].checkpoint, parent);
assert_eq!(retired.retired[0].retire_after, Fence(5));
assert_eq!(cache.page_chain(child).unwrap(), [PageId(0), PageId(1)]);
assert!(
cache
.advance_completed(Fence(4))
.unwrap()
.reusable
.snapshots
.is_empty()
);
assert_eq!(
cache
.advance_completed(Fence(5))
.unwrap()
.reusable
.snapshots,
[SnapshotId(0)]
);
}
}

#[test]
Expand Down
24 changes: 24 additions & 0 deletions helios/src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,15 @@ impl RequestScheduler {
pub fn free_snapshot_count(&self) -> usize {
self.free_snapshots.len()
}
/// Whether requests, transfers, or retirement fences may release admission resources.
#[cfg(feature = "server")]
pub(crate) fn resources_in_flight(&self) -> bool {
self.slots.iter().any(|slot| slot.request.is_some() || slot.retiring)
|| !self.cache.pending_retirement().is_empty()
|| !self.retired.is_empty()
|| !self.tickets.is_empty()
|| self.cache.has_pins()
}
pub fn has_available_slot(&self) -> bool {
self.slots.iter().any(|slot| {
slot.request.is_none() && !slot.retiring && slot.generation < i64::MAX as u64
Expand Down Expand Up @@ -2864,13 +2873,28 @@ impl RequestScheduler {
},
ready_after: request.last_use,
});
let refresh_recency = !request.preempted
&& request.error_code.is_none()
&& (publish || request.consumed_tokens > request.admission_reused_tokens
|| request.generated_tokens > 0);
let prefix = request.prefix;
let result = match &publication {
Some(proposal) => {
let history = request.history.clone();
Some(self.cache.publish_with_retention(&history, proposal, RetentionRole::Endpoint, request.checkpoints.demand_epoch)?)
}
None => None,
};
// Completed work is conversation activity, including a client stop after progress.
// Preemption and cancellation before inference must not advance cache recency.
if refresh_recency && let Some(id) = result.map(PublishResult::id).or(prefix) {
let epoch = self.cache.new_use_epoch()?;
self.cache.touch(id, epoch)?;
// Duplicate publication can retain a different parent than the request's prefix.
if result.is_some() && let Some(parent) = self.cache.checkpoint(id)?.parent() {
self.cache.touch(parent, epoch)?;
}
}
let mut request = self.slots[handle.slot as usize].request.take().unwrap();
if let Some(guard) = request.anchor_guard.take() { self.release_snapshot(guard); }
let mut snapshot = request.terminal_snapshot;
Expand Down
Loading
Loading