Skip to content
Closed
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
39 changes: 39 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1191,6 +1191,45 @@ encoding must be identity (or absent); compressed multipart returns HTTP 415.
JSON supports the usual compressed encodings. Box,
audio/video and custom question types are unsupported.

## Prefill-only requests

Setting the `X-Flare-Prefill-Only: true` (or `1`) request header on
`POST /v1/chat/completions`, `POST /v1/completions`, `POST /v1/messages`, or
`POST /v1/responses` renders and prefills the prompt, publishes an anchor
checkpoint at the full prompt endpoint, waits for any attached Selene pool
instance to confirm queued index announcements through an ordered barrier, and
returns without emitting generated tokens or response-stream events.

Valid header values are `true`, `1`, `false`, and `0` (case-insensitive, sent at
most once); any other value or enabling prefill-only (`true`/`1`) on
`POST /v1/messages/count_tokens` or on a multi-prompt `/v1/completions` batch
returns HTTP 400. Requests with `"stream": true` still return HTTP 200 JSON:

```json
{
"id": "chatcmpl-...",
"object": "prefill",
"created": 1700000000,
"model": "local",
"usage": {
"prompt_tokens": 1024,
"prompt_tokens_details": {"cached_tokens": 0}
},
"checkpoint": {
"tokens": 1024,
"key": "0123456789abcdef0123456789abcdef",
"announced": true
}
}
```

Responses carry `X-Request-Id`, `X-Flare-Pool-Announced` (`true` or `false`),
and `X-Flare-Checkpoint-Key` when a prompt-endpoint checkpoint is published
(otherwise `checkpoint.key` is `null` and `X-Flare-Checkpoint-Key` is omitted).
`X-Flare-Pool-Announced` is `false` when no prompt-endpoint checkpoint was
published, when no Selene pool is attached, or when the manager could not confirm
the barrier within its 5-second window.

## Decisions

`POST /v1/decisions` adapts the System One scorer to the concrete vLLM Decisions
Expand Down
13 changes: 9 additions & 4 deletions docs/prefix-cache-offload.md
Original file line number Diff line number Diff line change
Expand Up @@ -1349,7 +1349,12 @@ same completion events the store produces.
ends, because its copies could not be drained, keeps its pin. A store that
rejects a pinned export gets the pin back at once. The store, which knows the
record sizes, refuses an export larger than the staging the manager reserved
(`NoWindows`).
(`NoWindows`). Because `selene-manager` backs staging with a power-of-two
buddy allocator (`Arena`), each staging window rounds up to the next power of
two and a non-power-of-two `--staging` value splits into descending
power-of-two blocks (for example, `--staging 14G` splits into `8G + 4G + 2G`,
capping single-window allocations at `8 GiB`, so `>8 GiB` exports require
`--staging 16G`).
- **Headroom.** `RequestScheduler::export_fits` is read-only. It asks whether,
with the checkpoint pinned, the free pages and rows, those awaiting
retirement fences, and what eviction could still reclaim cover the next step
Expand Down Expand Up @@ -1535,11 +1540,11 @@ local disks, the manager can restore records it retained before shutdown.

With only a pool configured and all ranks in one process, Flare registers a
CPU-readable capture buffer. Its slot count is the larger of automatic intake
and the largest GPU page capacity plus one row's slots, bounded by the host
and one full single-sequence capture chain (`min(GPU page capacity, prepared max-sequence pages)` where prepared max-sequence pages is `ceil(max_sequence_tokens / page_tokens)`, plus one row's slots), bounded by the host
budget. All slots are available for capture. For GLM-5.3-Flash NVFP4 at TP4
with 32 concurrent requests, automatic intake sets it to 11.0 GiB (1,664 slots);
the full-chain floor is 7.1 GiB. Helios limits GPU page capacity so the buffer
fits the host budget. If even the minimum page capacity plus one row does not
the full-chain floor is 7.1 GiB. Helios limits GPU page capacity so one sequence chain plus one row
fits the host budget. If even the capped minimum page capacity plus one row does not
fit, startup fails with `host budget cannot hold a full pool capture`. Configure `--prefix-cache-memory` to choose
the host memory explicitly. While the manager can accept
records, each poll selects completed leaves for retirement, with up to four
Expand Down
2 changes: 1 addition & 1 deletion helios/src/model/packed_round_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ fn packed_combined_packing_preserves_sparse_slot_keys_and_ceiling_padding() {
for _ in 0..4 {
let prompt = vec![7; 64];
let h = scheduler.admit(RequestSpec { prompt_logprobs: false, message_boundaries: vec![], prompt: prompt.clone(), conditioning: vec![],
max_new_tokens: 64, grammar_constrained: false, growable_output: false, preserve_message_anchor: false }).unwrap();
max_new_tokens: 64, grammar_constrained: false, growable_output: false, preserve_message_anchor: false, prefill_only: false }).unwrap();
admissions[h.slot as usize] = Some(Admission { prompt_logprobs: false, handle: h,
sampling: SamplingParameters::default(), core_parameters: Default::default(),
max_new_tokens: 64, prompt, data: PromptData { positions: (0..64).map(|i| [i; 3]).collect(),
Expand Down
13 changes: 12 additions & 1 deletion helios/src/model/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ fn generic_core_parameters_resolve_pack_and_enforce_text_forward_contracts() {
prompt_logprobs: false,
growable_output: false,
preserve_message_anchor: false,
prefill_only: false,
};
// Unified validation rejects out-of-range and non-canonical -0.0 values in plan_admission_with_core_parameters.
let out_of_range =
Expand Down Expand Up @@ -380,6 +381,7 @@ fn core_parameters_pack_sparse_permuted_rows_and_preserve_prefix_values() {
prompt_logprobs: false,
growable_output: false,
preserve_message_anchor: false,
prefill_only: false,
};
let requests = [0.125f32, 0.25, 0.5, 0.75]
.into_iter()
Expand Down Expand Up @@ -529,6 +531,7 @@ fn admission_histogram_seed_and_partial_page_uploads_preserve_native_semantics()
prompt_logprobs: false,
growable_output: false,
preserve_message_anchor: false,
prefill_only: false,
})
.unwrap();
let mut admissions: [Option<Admission>; 4] = std::array::from_fn(|_| None);
Expand Down Expand Up @@ -678,6 +681,7 @@ fn large_prefill_uploads_preserve_token_position_and_image_indices_without_tail_
prompt_logprobs: false,
growable_output: false,
preserve_message_anchor: false,
prefill_only: false,
})
.unwrap();
let mut admissions: [Option<Admission>; 4] = std::array::from_fn(|_| None);
Expand Down Expand Up @@ -991,6 +995,7 @@ fn packing_follows_value_bindings_after_buffers_and_model_are_renamed() {
prompt_logprobs: false,
growable_output: false,
preserve_message_anchor: false,
prefill_only: false,
})
.unwrap();
let mut admissions: [Option<Admission>; 4] = std::array::from_fn(|_| None);
Expand Down Expand Up @@ -1107,6 +1112,7 @@ fn legacy_copy_bindings_pack_neutral_sentinels_without_copy_proposals() {
prompt_logprobs: false,
growable_output: false,
preserve_message_anchor: false,
prefill_only: false,
})
.unwrap();
let step = scheduler.plan().unwrap();
Expand Down Expand Up @@ -1238,6 +1244,7 @@ fn mixed_native_uploads_pack_prompt_after_the_decode_extent_and_sample_only_elig
prompt_logprobs: false,
growable_output: false,
preserve_message_anchor: false,
prefill_only: false,
})
.unwrap();
admissions[h.slot as usize] = Some(Admission {
Expand Down Expand Up @@ -1452,6 +1459,7 @@ fn state_transfer_and_resume_upload_fixture() {
prompt_logprobs: false,
growable_output: false,
preserve_message_anchor: false,
prefill_only: false,
})
.unwrap();
let mut admissions: [_; 4] = std::array::from_fn(|_| None);
Expand Down Expand Up @@ -1672,6 +1680,7 @@ fn grammar_packing_fixture() -> (
prompt_logprobs: false,
growable_output: false,
preserve_message_anchor: false,
prefill_only: false,
})
.unwrap();
admissions.push(Some(Admission {
Expand Down Expand Up @@ -1906,6 +1915,7 @@ fn prefill_compacts_execution_feature_indices_and_preserves_admission_metadata()
prompt_logprobs: false,
growable_output: true,
preserve_message_anchor: false,
prefill_only: false,
})
.unwrap();
scheduler
Expand Down Expand Up @@ -2014,7 +2024,7 @@ fn committed_generation_cursors_require_feedback_while_unused_prompt_positions_d
}
scheduler.measured_graph_durations(&manifest.graphs).unwrap();
let handle = scheduler.admit(RequestSpec { message_boundaries: vec![], prompt: vec![7; 64], conditioning: vec![],
max_new_tokens: 64, grammar_constrained: false, prompt_logprobs: false, growable_output: false, preserve_message_anchor: false }).unwrap();
max_new_tokens: 64, grammar_constrained: false, prompt_logprobs: false, growable_output: false, preserve_message_anchor: false, prefill_only: false }).unwrap();
let mut admissions: [Option<Admission>; 4] = std::array::from_fn(|_| None);
admissions[handle.slot as usize] = Some(Admission { handle, sampling: SamplingParameters::default(),
core_parameters: Default::default(),
Expand Down Expand Up @@ -2275,6 +2285,7 @@ fn prompt_lookahead_packing_distributes_budget_across_single_multi_and_mixed_lan
prompt_logprobs: false,
growable_output: false,
preserve_message_anchor: false,
prefill_only: false,
})
.unwrap();
admissions[h.slot as usize] = Some(Admission {
Expand Down
1 change: 1 addition & 0 deletions helios/src/offload/pool/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ fn peer_registration_budget_fails_startup() {
input_staging: 0,
shard: Some((1, 2)),
integrated: false,
max_sequence_pages: None,
},
)
.unwrap();
Expand Down
8 changes: 6 additions & 2 deletions helios/src/runtime_core/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,7 @@ impl NativeModel {
.as_u64()
.ok_or_else(|| invalid("model requires a prepared context ceiling"))?;
let ceiling = page_ceiling(options.kv_cache_limit, context, active as u64, &contract)?;
let max_sequence_pages = context.div_ceil(contract.cache.page_tokens as u64);
let minimum_pages = ceiling.map_or(active as u64 * 8192u64.div_ceil(page_tokens), |limit| limit.minimum);
let capture = options.prefix_cache.pool_only() && self.cluster().is_none();
let cfg = &options.prefix_cache;
Expand Down Expand Up @@ -1018,8 +1019,9 @@ impl NativeModel {
input_staging: staging,
shard: self.cluster().map(|cluster| (cluster.rank, cluster.world)),
integrated: integrated > 0,
max_sequence_pages: Some(max_sequence_pages),
},
capture.then_some(minimum_pages),
capture.then_some(minimum_pages.min(max_sequence_pages)),
initial_budget,
)?;
let device = device
Expand Down Expand Up @@ -1373,7 +1375,7 @@ impl NativeModel {
return Some(0);
};
let shared = if self.ranks[rank].integrated { integrated } else { 0 };
capture_growth(layout, pages, tier_host, host_growth, shared)
capture_growth(layout, pages.min(max_sequence_pages), tier_host, host_growth, shared)
},
)?;
// Fewer pages only shrink KV, and fewer rows only the snapshot slots aliased into it, so
Expand Down Expand Up @@ -1440,6 +1442,7 @@ impl NativeModel {
let planned_offload_host = if capture {
let layout = capture_layout.as_ref().unwrap();
let chain_bytes = pages
.min(max_sequence_pages)
.saturating_add(layout.row_slots() as u64)
.saturating_mul(layout.page_record_bytes);
Some(tier_host.max(chain_bytes))
Expand Down Expand Up @@ -1905,6 +1908,7 @@ mod tests {
input_staging: 0,
shard: None,
integrated: true,
max_sequence_pages: None,
};
let disk_only = crate::offload::PrefixCacheOffload {
memory_bytes: Some(0),
Expand Down
5 changes: 5 additions & 0 deletions helios/src/runtime_core/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,10 @@ impl NativeModel {
.as_ref()
.map(|cluster| (cluster.rank, cluster.world));
let integrated = self.ranks.iter().any(|rank| rank.integrated);
let max_sequence_pages = self
.server_config["max_sequence_tokens"]
.as_u64()
.map(|tokens| tokens.div_ceil(contract.cache.page_tokens as u64));
let prepared = crate::offload::prepare_with_inputs_budget_with_progress(
&options.prefix_cache,
identity,
Expand All @@ -1088,6 +1092,7 @@ impl NativeModel {
input_staging: staging,
shard,
integrated,
max_sequence_pages,
},
planned_host_budget,
|step| phase.detail(step),
Expand Down
9 changes: 9 additions & 0 deletions helios/src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ pub struct RequestSpec {
/// Retain the last eligible interior message boundary as the conversation anchor
/// under nonzero `checkpoint_extra_work_fraction` instead of budgeting its split.
pub preserve_message_anchor: bool,
/// Anchor checkpoint capture at the full prompt endpoint so another worker can
/// reuse the prefilled state immediately after completion.
pub prefill_only: bool,
}

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
Expand Down Expand Up @@ -229,6 +232,7 @@ pub struct LiveRequest {
pub prompt_tokens: usize,
pub grammar_constrained: bool,
pub preserve_message_anchor: bool,
pub prefill_only: bool,
pub error_code: Option<i64>,
prompt_logprobs: bool,
execution_limit: u64,
Expand Down Expand Up @@ -1868,6 +1872,7 @@ impl RequestScheduler {
prompt_tokens: spec.prompt.len(),
grammar_constrained: spec.grammar_constrained,
preserve_message_anchor: spec.preserve_message_anchor,
prefill_only: spec.prefill_only,
prompt_logprobs: spec.prompt_logprobs,
execution_limit: execution_limit as u64,
error_code: None,
Expand Down Expand Up @@ -2050,6 +2055,10 @@ impl RequestScheduler {
std::mem::take(&mut self.reused)
}

pub fn checkpoint_key(&self, id: CheckpointId) -> Option<PrefixKey> {
self.cache.checkpoint(id).ok().map(|cp| cp.prefix())
}

pub(crate) fn publication(&self, id: CheckpointId) -> Option<PublishedCheckpoint> {
let checkpoint = self.cache.checkpoint(id).ok()?;
let ancestors =
Expand Down
1 change: 1 addition & 0 deletions helios/src/scheduler/boundary_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ fn spec(system: Option<usize>, prompt: usize, output: u32) -> RequestSpec {
prompt_logprobs: false,
growable_output: false,
preserve_message_anchor: false,
prefill_only: false,
}
}
fn run_step(s: &mut RequestScheduler) -> ScheduledPlan {
Expand Down
1 change: 1 addition & 0 deletions helios/src/scheduler/checkpoint_lifecycle_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,7 @@ fn deferred_prefill_reservations_match_lifecycle_model() {
prompt_logprobs: false,
growable_output: false,
preserve_message_anchor: false,
prefill_only: false,
})
.unwrap();
let init = s.plan().unwrap();
Expand Down
68 changes: 68 additions & 0 deletions helios/src/scheduler/checkpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ fn cheaper(work: usize, nanos: u64, best: Option<(usize, u64)>) -> bool {

impl LiveRequest {
pub(super) fn checkpoint_anchor(&self) -> usize {
if self.prefill_only {
return self.prompt_tokens;
}
self.message_boundaries
.iter()
.rev()
Expand Down Expand Up @@ -5517,4 +5520,69 @@ mod tests {
Some(60_000_000)
);
}

#[test]
fn prefill_only_anchors_at_prompt_end_even_without_snapshot_cost_or_extra_work_budget() {
let mut scheduler = super::super::tests::scheduler(2, 128, 16);
scheduler.prefill_graphs(&[128, 256, 512]).unwrap();
scheduler.enable_publications();
scheduler
.configure_policy(PolicyConfig {
checkpoint_extra_work_fraction: 0.0,
..Default::default()
})
.unwrap();

// Notice we intentionally do NOT measure GraphKind::Snapshot or GraphKind::Prefill,
// and we supply an interior message boundary. `prefill_only` must still anchor at prompt end.
let mut spec = super::super::tests::spec(512, 1);
spec.message_boundaries = vec![256];
spec.prefill_only = true;
let handle = scheduler.admit(spec).unwrap();
let req = scheduler.request(handle).unwrap();
assert_eq!(req.checkpoint_anchor(), 512);
let (sel, _, _) = scheduler.checkpoint_selection(req);
assert_eq!(sel.cuts.len(), 1);
assert_eq!(sel.cuts[0].endpoint, 512);
assert_eq!(sel.cuts[0].role, RetentionRole::Anchor);

let mut fence = 1u64;
while scheduler.request(handle).unwrap().phase != RequestPhase::Finishing {
let step = scheduler.plan().unwrap();
scheduler.commit(&step, Fence(fence)).unwrap();
complete_test_step(&mut scheduler, &step, Fence(fence), 50);
fence += 1;
}
let req = scheduler.request(handle).unwrap();
let cp_id = req.prefix().expect("prompt endpoint must be published");
assert_eq!(req.prefix_tokens, 512);
let key = scheduler.checkpoint_key(cp_id).expect("key must exist");
assert_eq!(key.consumed_tokens, 512);
let pubs = scheduler.take_publications();
assert!(pubs.iter().any(|p| p.id == cp_id));
scheduler.finish(handle).unwrap();
scheduler.assert_idle().unwrap();

// Second identical `prefill_only` request reuses all 512 tokens cleanly with zero duplicate snapshots.
let mut repeat = super::super::tests::spec(512, 1);
repeat.message_boundaries = vec![256];
repeat.prefill_only = true;
let repeat_handle = scheduler.admit(repeat).unwrap();
assert_eq!(
scheduler.request(repeat_handle).unwrap().reused_prompt_tokens(),
512
);
while scheduler.request(repeat_handle).unwrap().phase != RequestPhase::Finishing {
let step = scheduler.plan().unwrap();
scheduler.commit(&step, Fence(fence)).unwrap();
complete_test_step(&mut scheduler, &step, Fence(fence), 50);
fence += 1;
}
let repeat_req = scheduler.request(repeat_handle).unwrap();
assert_eq!(repeat_req.prefix(), Some(cp_id));
assert_eq!(repeat_req.prefix_tokens, 512);
assert_eq!(scheduler.checkpoint_key(cp_id), Some(key));
scheduler.finish(repeat_handle).unwrap();
scheduler.assert_idle().unwrap();
}
}
Loading