control-plane serves /props, /slots, /v1/status, /api/health, /settings, /load, /unload, /v1/load, /v1/unload, model aliases, CORS with the preflight ahead of authentication and the own-page guard; replayed scenario by scenario against the real Python handlers. The worker supervisor gains load/unload, lazy start, idle unload, reload gates (before_load, min free VRAM), an outside stall watchdog and the reasoning-budget wrap-up (budget tracker golden-tested against the Python Detokenizer/OutputParser loop). leleka-serving-policy adds CORS, idle, stall watchdog, logits stride (golden vs the C++ header), request timings and alias rules. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
84 lines
2.6 KiB
Rust
84 lines
2.6 KiB
Rust
//! Logits-selection stride (`include/strata/program/logits_selection.hpp`): which prompt positions
|
||
//! keep their logits rows when a diagnostic dump asks for every `stride`-th row.
|
||
//!
|
||
//! "Storage selection only: callers must still condition on every input token." The functions are
|
||
//! integer-exact transcriptions, golden-tested against the Original's header compiled on the host.
|
||
|
||
/// Positive decimal `int64`, with no sign, whitespace, suffix or overflow (`parse_stride`).
|
||
pub fn parse_stride(text: &str) -> Option<i64> {
|
||
let bytes = text.as_bytes();
|
||
if bytes.first().is_none_or(|b| !b.is_ascii_digit()) {
|
||
return None;
|
||
}
|
||
if !bytes.iter().all(u8::is_ascii_digit) {
|
||
return None;
|
||
}
|
||
text.parse::<i64>().ok().filter(|v| *v > 0)
|
||
}
|
||
|
||
/// Zero-based multiples of `stride`, followed by the final input position once.
|
||
pub fn selected(position: i64, total: i64, stride: i64) -> bool {
|
||
total > 0
|
||
&& stride > 0
|
||
&& position >= 0
|
||
&& position < total
|
||
&& (position % stride == 0 || position == total - 1)
|
||
}
|
||
|
||
/// How many positions [`selected`] keeps.
|
||
pub fn row_count(total: i64, stride: i64) -> i64 {
|
||
if total > 0 && stride > 0 {
|
||
(total - 1) / stride + 1 + i64::from((total - 1) % stride != 0)
|
||
} else {
|
||
0
|
||
}
|
||
}
|
||
|
||
#[cfg(test)]
|
||
mod tests {
|
||
use super::*;
|
||
|
||
#[test]
|
||
fn parse_is_strict() {
|
||
assert_eq!(parse_stride("1"), Some(1));
|
||
assert_eq!(parse_stride("128"), Some(128));
|
||
assert_eq!(parse_stride("9223372036854775807"), Some(i64::MAX));
|
||
for bad in [
|
||
"",
|
||
"0",
|
||
"00",
|
||
"-1",
|
||
"+1",
|
||
" 1",
|
||
"1 ",
|
||
"1x",
|
||
"x",
|
||
"9223372036854775808",
|
||
"1",
|
||
] {
|
||
assert_eq!(parse_stride(bad), None, "{bad:?}");
|
||
}
|
||
}
|
||
|
||
#[test]
|
||
fn selection_is_multiples_plus_the_last_position() {
|
||
let kept: Vec<i64> = (0..10).filter(|p| selected(*p, 10, 4)).collect();
|
||
assert_eq!(kept, vec![0, 4, 8, 9]);
|
||
assert_eq!(row_count(10, 4), 4);
|
||
assert_eq!(row_count(9, 4), 3);
|
||
assert_eq!(row_count(1, 5), 1);
|
||
assert_eq!(row_count(0, 5), 0);
|
||
assert_eq!(row_count(5, 0), 0);
|
||
}
|
||
|
||
#[test]
|
||
fn row_count_equals_the_number_of_selected_positions() {
|
||
for total in 0..60 {
|
||
for stride in 0..13 {
|
||
let n = (-1..=total).filter(|p| selected(*p, total, stride)).count() as i64;
|
||
assert_eq!(n, row_count(total, stride), "total {total} stride {stride}");
|
||
}
|
||
}
|
||
}
|
||
}
|