Skip to content
Open
Show file tree
Hide file tree
Changes from 14 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
2 changes: 1 addition & 1 deletion crates/skippy-api/src/native-recipe.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"llama_upstream_sha": "5bacb7c868a2bc98682de15f447fc1ce17c9c49c",
"patch_queue_sha256": "111ab9739c5c50d6d1841d2d15a805f7d2aa7b8221e7271efcab3cb6f1952ce4"
"patch_queue_sha256": "4f731cfaf55b9b078c4784c3a7e9113b72a5f6c845f41eec6c4a03f58b65e50d"
}
10 changes: 7 additions & 3 deletions crates/skippy-correctness/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,12 @@ same activation/cache contracts without requiring a monolithic full GGUF.
- `state-handoff` validates state export/import for a whole model or a
stage range selected with `--state-layer-start`, `--state-layer-end`, and
`--state-stage-index`. `--state-payload-kind` selects `full-state`,
`resident-kv`, `recurrent-only`, or `kv-recurrent` payloads. All ranges use
direct local runtime handoff; `full-state` remains the default payload.
`resident-kv`, or `kv-recurrent` payloads. All ranges use direct local
runtime handoff; `full-state` remains the default payload. `kv-recurrent`
carries the parts the stage itself is checkpointed by: a KV page where it
holds attention layers, and recurrent state where it holds recurrent layers,
so a hybrid model's middle stage with no attention layers carries recurrent
state alone.
`--binary-control` is rejected because binary state export/import is
unavailable. Omit it to run the supported local handoff.
The report includes the handoff transport, payload kind, state payload size,
Expand All @@ -233,7 +237,7 @@ same activation/cache contracts without requiring a monolithic full GGUF.
input to exactly that prefix plus one continuation token. Use
`--cache-hit-repeats` to repeatedly attach the exported state and decode the
same continuation, producing a recompute-vs-cache-hit speedup estimate. Use
`--allow-mismatch` only for diagnostic payloads such as recurrent-only.
`--allow-mismatch` only for diagnostic payloads.
- `native-mtp-open-ai-ab` launches a real two-stage `skippy-serving
serve-binary` split three times through the embedded OpenAI frontend. The
baseline run selects `--native-mtp=false --speculative-strategy disabled`.
Expand Down
3 changes: 2 additions & 1 deletion crates/skippy-correctness/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,8 @@ pub struct GlmDsaStage0TraceArgs {
pub enum StatePayloadKind {
ResidentKv,
FullState,
RecurrentOnly,
/// The stage's exact checkpoint: a KV page where it holds attention
/// layers, and the recurrent state where it holds recurrent layers.
KvRecurrent,
}

Expand Down
1 change: 0 additions & 1 deletion crates/skippy-correctness/src/runner/remote_handoff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1766,7 +1766,6 @@ fn payload_kind_name(kind: StatePayloadKind) -> &'static str {
match kind {
StatePayloadKind::ResidentKv => "resident-kv",
StatePayloadKind::FullState => "full-state",
StatePayloadKind::RecurrentOnly => "recurrent-only",
StatePayloadKind::KvRecurrent => "kv-recurrent",
}
}
Expand Down
104 changes: 40 additions & 64 deletions crates/skippy-correctness/src/runner/state_handoff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use skippy_protocol::binary::{
recv_reply, state_flags, write_stage_message,
};
use skippy_runtime::{
ActivationFrame, GgufStageRuntimePlan, MtpSource, RuntimeConfig, RuntimeKvPageDesc, StageModel,
StageSession,
ActivationFrame, CheckpointParts, CheckpointShape, GgufStageRuntimePlan, MtpSource,
RuntimeConfig, RuntimeKvPageDesc, StageModel, StageSession,
};

use crate::{
Expand Down Expand Up @@ -96,7 +96,6 @@ pub(in crate::runner) enum LocalStatePayload {
token_count: u64,
},
FullState(Vec<u8>),
RecurrentOnly(Vec<u8>),
KvRecurrent {
kv_desc: Option<RuntimeKvPageDesc>,
kv: Vec<u8>,
Expand All @@ -108,7 +107,7 @@ impl LocalStatePayload {
fn byte_len(&self) -> usize {
match self {
Self::ResidentKv { .. } => 0,
Self::FullState(bytes) | Self::RecurrentOnly(bytes) => bytes.len(),
Self::FullState(bytes) => bytes.len(),
Self::KvRecurrent { kv, recurrent, .. } => kv.len().saturating_add(recurrent.len()),
}
}
Expand All @@ -125,8 +124,7 @@ impl LocalStatePayload {
..
},
) => a_count == b_count,
(Self::FullState(a), Self::FullState(b))
| (Self::RecurrentOnly(a), Self::RecurrentOnly(b)) => a == b,
(Self::FullState(a), Self::FullState(b)) => a == b,
(
Self::KvRecurrent {
kv_desc: a_desc,
Expand Down Expand Up @@ -157,12 +155,6 @@ impl LocalStatePayload {
None,
None,
),
Self::RecurrentOnly(recurrent) => payload_digest_report(
state_payload_kind_name(StatePayloadKind::RecurrentOnly),
recurrent,
None,
Some(recurrent.as_slice()),
),
Self::KvRecurrent { kv, recurrent, .. } => {
let mut hasher = Sha256::new();
hasher.update(b"kv-recurrent:kv:");
Expand Down Expand Up @@ -796,7 +788,7 @@ fn run_local_state_handoff(
let source_prefill_ms = elapsed_ms(source_prefill_started);

let source_export_started = Instant::now();
let state_payload = export_local_state_payload(&mut source, args, prefix.len() as u64)
let state_payload = export_local_state_payload(&model, &mut source, args, prefix.len() as u64)
.context("local state handoff source export failed")?;
let source_export_ms = elapsed_ms(source_export_started);

Expand Down Expand Up @@ -850,7 +842,7 @@ fn run_local_state_handoff(
{
state_payload.clone()
} else {
export_local_state_payload(&mut restore, args, prefix.len() as u64)
export_local_state_payload(&model, &mut restore, args, prefix.len() as u64)
.context("local state handoff restore export failed")?
};
let restore_export_ms = elapsed_ms(restore_export_started);
Expand Down Expand Up @@ -1309,11 +1301,12 @@ fn create_local_cache_hit_session(
let mut session = model
.create_session()
.context("failed to create local state handoff cache-hit session")?;
import_local_state_payload(&mut session, args, payload, token_count, token_ids)?;
import_local_state_payload(model, &mut session, args, payload, token_count, token_ids)?;
Ok(session)
}

fn export_local_state_payload(
model: &StageModel,
session: &mut StageSession,
args: &BinaryStateHandoffConfig,
token_count: u64,
Expand All @@ -1331,18 +1324,24 @@ fn export_local_state_payload(
session
.export_full_state(args.state_layer_start as i32, args.state_layer_end as i32)?,
)),
StatePayloadKind::RecurrentOnly => Ok(LocalStatePayload::RecurrentOnly(
session.export_recurrent_state()?,
)),
StatePayloadKind::KvRecurrent => {
let page = export_optional_kv_page(
session,
args.state_layer_start as i32,
args.state_layer_end as i32,
0,
token_count,
)?;
let recurrent = session.export_recurrent_state()?;
let shape = stage_checkpoint_shape(model)?;
let page = shape
.has_page()
.then(|| {
session.export_kv_page(
args.state_layer_start as i32,
args.state_layer_end as i32,
0,
token_count,
)
})
.transpose()?;
let recurrent = if shape.has_recurrent() {
session.export_recurrent_state()?
} else {
Vec::new()
};
Ok(LocalStatePayload::KvRecurrent {
kv_desc: page.as_ref().map(|page| page.desc.clone()),
kv: page.map(|page| page.payload).unwrap_or_default(),
Expand Down Expand Up @@ -1374,7 +1373,14 @@ fn measure_resident_state_bytes(
))
}

fn stage_checkpoint_shape(model: &StageModel) -> Result<CheckpointShape> {
model
.checkpoint_shape()
.context("this stage has no exact checkpoint; use --state-payload-kind full-state")
}

fn import_local_state_payload(
model: &StageModel,
session: &mut StageSession,
args: &BinaryStateHandoffConfig,
payload: &LocalStatePayload,
Expand All @@ -1400,51 +1406,26 @@ fn import_local_state_payload(
bytes,
token_count,
),
LocalStatePayload::RecurrentOnly(bytes) => {
session.import_recurrent_state_for_token_count(bytes, token_count)
}
LocalStatePayload::KvRecurrent {
kv_desc,
kv,
recurrent,
} => {
if let Some(kv_desc) = kv_desc {
session.import_kv_page(kv_desc, kv)?;
} else if !kv.is_empty() {
bail!("KV-recurrent payload has KV bytes but no KV descriptor");
}
session.import_recurrent_state_for_token_count(recurrent, token_count)
let page = match kv_desc {
Some(kv_desc) => Some((kv_desc, kv.as_slice())),
None if kv.is_empty() => None,
None => bail!("KV-recurrent payload has KV bytes but no KV descriptor"),
};
let parts = CheckpointParts::fit(stage_checkpoint_shape(model)?, page, recurrent)?;
session.import_checkpoint(&parts, token_count, &[])
}
}
}

fn export_optional_kv_page(
session: &mut StageSession,
layer_start: i32,
layer_end: i32,
token_start: u64,
token_count: u64,
) -> Result<Option<skippy_runtime::RuntimeKvPage>> {
match session.export_kv_page(layer_start, layer_end, token_start, token_count) {
Ok(page) => Ok(Some(page)),
Err(error) if is_native_kv_unavailable(&error) => Ok(None),
Err(error) => Err(error),
}
}

fn is_native_kv_unavailable(error: &anyhow::Error) -> bool {
error.chain().any(|cause| {
let message = cause.to_string();
message.contains("runtime memory type is not supported for native KV pages")
|| message.contains("runtime has no attention KV cache")
})
}

fn state_payload_kind_name(kind: StatePayloadKind) -> &'static str {
match kind {
StatePayloadKind::ResidentKv => "resident-kv",
StatePayloadKind::FullState => "full-state",
StatePayloadKind::RecurrentOnly => "recurrent-only",
StatePayloadKind::KvRecurrent => "kv-recurrent",
}
}
Expand Down Expand Up @@ -1872,12 +1853,7 @@ mod tests {

#[test]
fn binary_control_rejects_every_payload_before_model_or_server_access() {
for payload in [
"resident-kv",
"full-state",
"recurrent-only",
"kv-recurrent",
] {
for payload in ["resident-kv", "full-state", "kv-recurrent"] {
let cli = Cli::try_parse_from([
"skippy-correctness",
"state-handoff",
Expand Down
Loading
Loading