STRA-338 size3 en7: WIP of the slice (unverified, committed by the new integrator)
This commit is contained in:
@@ -282,128 +282,4 @@ pub fn describe(
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn base() -> (OriginalServeOptions, u32) {
|
||||
let options = OriginalServeOptions {
|
||||
prefix_cache: Some(PrefixCacheOptions {
|
||||
tail: PrefixTail::Off,
|
||||
budget_bytes: None,
|
||||
block_tokens: 0,
|
||||
retention_s: None,
|
||||
}),
|
||||
..OriginalServeOptions::default()
|
||||
};
|
||||
(options, 262_144)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_empty_or_unknown_document_is_refused() {
|
||||
assert!(Tuning::parse("{}").is_err());
|
||||
assert!(Tuning::parse("{\"context\": 5}").unwrap_err().contains("unknown field"));
|
||||
assert!(Tuning::parse("not json").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn values_apply_and_the_changed_members_are_named() {
|
||||
let (mut options, mut context) = base();
|
||||
let tuning = Tuning::parse(r#"{"context_tokens":65536,"prefix_cache_tail":"reply","prefix_cache_mib":"20480","prefill_capacity":8192,"prefix_cache_block":8192,"prefix_retention_min":30,"cpu_workers":8,"spec_min_p":0.5}"#).unwrap();
|
||||
let changed = tuning.apply(&mut options, &mut context).unwrap();
|
||||
assert_eq!(context, 65_536);
|
||||
assert_eq!(options.prefill_capacity, Some(8192));
|
||||
assert_eq!(options.cpu_workers, Some(8));
|
||||
assert_eq!(options.spec_min_p, 0.5);
|
||||
let prefix = options.prefix_cache.as_ref().unwrap();
|
||||
assert_eq!(
|
||||
(prefix.tail, prefix.budget_bytes, prefix.block_tokens, prefix.retention_s),
|
||||
(PrefixTail::Reply, Some(20_480 << 20), 8192, Some(1800))
|
||||
);
|
||||
for name in [
|
||||
"context_tokens",
|
||||
"prefill_capacity",
|
||||
"cpu_workers",
|
||||
"spec_min_p",
|
||||
"prefix_cache_mib",
|
||||
"prefix_cache_tail",
|
||||
"prefix_cache_block",
|
||||
"prefix_retention_min",
|
||||
] {
|
||||
assert!(changed.contains(&name), "{name} in {changed:?}");
|
||||
}
|
||||
// the same document again changes nothing
|
||||
assert!(tuning.apply(&mut options, &mut context).unwrap().is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_values_change_nothing() {
|
||||
for bad in [
|
||||
r#"{"context_tokens":0}"#,
|
||||
r#"{"context_tokens":300000}"#,
|
||||
r#"{"prefill_capacity":5000}"#,
|
||||
r#"{"kv_resident":1000}"#,
|
||||
r#"{"kv_resident":0}"#, // fixed per process: only the value in force is accepted
|
||||
r#"{"cpu_workers":0}"#,
|
||||
r#"{"cpu_workers":16}"#,
|
||||
r#"{"spec_min_p":1.5}"#,
|
||||
r#"{"prefix_cache_tail":"always"}"#,
|
||||
r#"{"prefix_cache_mib":"lots"}"#,
|
||||
r#"{"prefix_cache_block":300}"#,
|
||||
r#"{"prefix_cache_block":8192}"#, // larger than the default 2048 chunk
|
||||
] {
|
||||
let (mut options, mut context) = base();
|
||||
let before = (options.clone().prefill_capacity, context);
|
||||
let result = Tuning::parse(bad).and_then(|t| t.apply(&mut options, &mut context));
|
||||
assert!(result.is_err(), "{bad}");
|
||||
assert_eq!((options.prefill_capacity, context), before, "{bad} must change nothing");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_resident_kv_window_is_accepted_only_at_the_value_in_force() {
|
||||
let (mut options, mut context) = base();
|
||||
let changed = Tuning::parse(r#"{"kv_resident":32768,"context_tokens":100000}"#)
|
||||
.unwrap()
|
||||
.apply(&mut options, &mut context)
|
||||
.unwrap();
|
||||
assert_eq!(changed, vec!["context_tokens"]);
|
||||
options.kv_resident = Some(40_960);
|
||||
assert!(
|
||||
Tuning::parse(r#"{"kv_resident":32768}"#)
|
||||
.unwrap()
|
||||
.apply(&mut options, &mut context)
|
||||
.unwrap_err()
|
||||
.contains("restart")
|
||||
);
|
||||
assert!(
|
||||
Tuning::parse(r#"{"kv_resident":40960,"prefill_capacity":4096}"#)
|
||||
.unwrap()
|
||||
.apply(&mut options, &mut context)
|
||||
.is_ok()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_prefix_cache_can_be_switched_off_and_back_on() {
|
||||
let (mut options, mut context) = base();
|
||||
Tuning::parse(r#"{"prefix_cache_mib":"off"}"#).unwrap().apply(&mut options, &mut context).unwrap();
|
||||
assert!(options.prefix_cache.is_none());
|
||||
let changed = Tuning::parse(r#"{"prefix_cache_mib":"auto","prefix_cache_tail":"prompt"}"#)
|
||||
.unwrap()
|
||||
.apply(&mut options, &mut context)
|
||||
.unwrap();
|
||||
assert_eq!(options.prefix_cache.as_ref().unwrap().tail, PrefixTail::Prompt);
|
||||
assert!(changed.contains(&"prefix_cache_mib"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn describe_reports_the_defaults_the_engine_applies() {
|
||||
let (options, context) = base();
|
||||
let doc = describe(&options, context, 16, Some(13 << 30));
|
||||
assert_eq!(doc["prefill_capacity"], 2048);
|
||||
assert_eq!(doc["kv_resident"], 32768);
|
||||
assert_eq!(doc["prefix_cache"]["requested"], "auto");
|
||||
assert_eq!(doc["prefix_cache"]["budget_mib"], 13 * 1024);
|
||||
assert_eq!(doc["prefix_cache"]["retention_min"], 60);
|
||||
}
|
||||
}
|
||||
mod tests;
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
use super::*;
|
||||
|
||||
fn base() -> (OriginalServeOptions, u32) {
|
||||
let options = OriginalServeOptions {
|
||||
prefix_cache: Some(PrefixCacheOptions {
|
||||
tail: PrefixTail::Off,
|
||||
budget_bytes: None,
|
||||
block_tokens: 0,
|
||||
retention_s: None,
|
||||
}),
|
||||
..OriginalServeOptions::default()
|
||||
};
|
||||
(options, 262_144)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_empty_or_unknown_document_is_refused() {
|
||||
assert!(Tuning::parse("{}").is_err());
|
||||
assert!(Tuning::parse("{\"context\": 5}").unwrap_err().contains("unknown field"));
|
||||
assert!(Tuning::parse("not json").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn values_apply_and_the_changed_members_are_named() {
|
||||
let (mut options, mut context) = base();
|
||||
let tuning = Tuning::parse(r#"{"context_tokens":65536,"prefix_cache_tail":"reply","prefix_cache_mib":"20480","prefill_capacity":8192,"prefix_cache_block":8192,"prefix_retention_min":30,"cpu_workers":8,"spec_min_p":0.5}"#).unwrap();
|
||||
let changed = tuning.apply(&mut options, &mut context).unwrap();
|
||||
assert_eq!(context, 65_536);
|
||||
assert_eq!(options.prefill_capacity, Some(8192));
|
||||
assert_eq!(options.cpu_workers, Some(8));
|
||||
assert_eq!(options.spec_min_p, 0.5);
|
||||
let prefix = options.prefix_cache.as_ref().unwrap();
|
||||
assert_eq!(
|
||||
(prefix.tail, prefix.budget_bytes, prefix.block_tokens, prefix.retention_s),
|
||||
(PrefixTail::Reply, Some(20_480 << 20), 8192, Some(1800))
|
||||
);
|
||||
for name in [
|
||||
"context_tokens",
|
||||
"prefill_capacity",
|
||||
"cpu_workers",
|
||||
"spec_min_p",
|
||||
"prefix_cache_mib",
|
||||
"prefix_cache_tail",
|
||||
"prefix_cache_block",
|
||||
"prefix_retention_min",
|
||||
] {
|
||||
assert!(changed.contains(&name), "{name} in {changed:?}");
|
||||
}
|
||||
// the same document again changes nothing
|
||||
assert!(tuning.apply(&mut options, &mut context).unwrap().is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_values_change_nothing() {
|
||||
for bad in [
|
||||
r#"{"context_tokens":0}"#,
|
||||
r#"{"context_tokens":300000}"#,
|
||||
r#"{"prefill_capacity":5000}"#,
|
||||
r#"{"kv_resident":1000}"#,
|
||||
r#"{"kv_resident":0}"#, // fixed per process: only the value in force is accepted
|
||||
r#"{"cpu_workers":0}"#,
|
||||
r#"{"cpu_workers":16}"#,
|
||||
r#"{"spec_min_p":1.5}"#,
|
||||
r#"{"prefix_cache_tail":"always"}"#,
|
||||
r#"{"prefix_cache_mib":"lots"}"#,
|
||||
r#"{"prefix_cache_block":300}"#,
|
||||
r#"{"prefix_cache_block":8192}"#, // larger than the default 2048 chunk
|
||||
] {
|
||||
let (mut options, mut context) = base();
|
||||
let before = (options.clone().prefill_capacity, context);
|
||||
let result = Tuning::parse(bad).and_then(|t| t.apply(&mut options, &mut context));
|
||||
assert!(result.is_err(), "{bad}");
|
||||
assert_eq!((options.prefill_capacity, context), before, "{bad} must change nothing");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_resident_kv_window_is_accepted_only_at_the_value_in_force() {
|
||||
let (mut options, mut context) = base();
|
||||
let changed = Tuning::parse(r#"{"kv_resident":32768,"context_tokens":100000}"#)
|
||||
.unwrap()
|
||||
.apply(&mut options, &mut context)
|
||||
.unwrap();
|
||||
assert_eq!(changed, vec!["context_tokens"]);
|
||||
options.kv_resident = Some(40_960);
|
||||
assert!(
|
||||
Tuning::parse(r#"{"kv_resident":32768}"#)
|
||||
.unwrap()
|
||||
.apply(&mut options, &mut context)
|
||||
.unwrap_err()
|
||||
.contains("restart")
|
||||
);
|
||||
assert!(
|
||||
Tuning::parse(r#"{"kv_resident":40960,"prefill_capacity":4096}"#)
|
||||
.unwrap()
|
||||
.apply(&mut options, &mut context)
|
||||
.is_ok()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_prefix_cache_can_be_switched_off_and_back_on() {
|
||||
let (mut options, mut context) = base();
|
||||
Tuning::parse(r#"{"prefix_cache_mib":"off"}"#).unwrap().apply(&mut options, &mut context).unwrap();
|
||||
assert!(options.prefix_cache.is_none());
|
||||
let changed = Tuning::parse(r#"{"prefix_cache_mib":"auto","prefix_cache_tail":"prompt"}"#)
|
||||
.unwrap()
|
||||
.apply(&mut options, &mut context)
|
||||
.unwrap();
|
||||
assert_eq!(options.prefix_cache.as_ref().unwrap().tail, PrefixTail::Prompt);
|
||||
assert!(changed.contains(&"prefix_cache_mib"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn describe_reports_the_defaults_the_engine_applies() {
|
||||
let (options, context) = base();
|
||||
let doc = describe(&options, context, 16, Some(13 << 30));
|
||||
assert_eq!(doc["prefill_capacity"], 2048);
|
||||
assert_eq!(doc["kv_resident"], 32768);
|
||||
assert_eq!(doc["prefix_cache"]["requested"], "auto");
|
||||
assert_eq!(doc["prefix_cache"]["budget_mib"], 13 * 1024);
|
||||
assert_eq!(doc["prefix_cache"]["retention_min"], 60);
|
||||
}
|
||||
@@ -147,10 +147,8 @@ pub(super) fn render_native(messages: &[Message<'_>], effort: Effort, tools: &[J
|
||||
}
|
||||
|
||||
fn message_object(message: &Message<'_>) -> Json {
|
||||
let mut fields = vec![
|
||||
("role".to_owned(), Json::str(message.role.name())),
|
||||
("content".to_owned(), Json::str(message.content)),
|
||||
];
|
||||
let mut fields =
|
||||
vec![("role".to_owned(), Json::str(message.role.name())), ("content".to_owned(), Json::str(message.content))];
|
||||
if let Some(reasoning) = message.reasoning {
|
||||
fields.push(("reasoning_content".to_owned(), Json::str(reasoning)));
|
||||
}
|
||||
|
||||
@@ -105,10 +105,37 @@ impl Rng {
|
||||
}
|
||||
|
||||
const ATOMS: &[&str] = &[
|
||||
"", " ", " ", "\n", "\n\n", "\t", "\r\n", "\u{a0}", "\u{2003}", "\u{1c}", "\u{85}", "\u{200b}", "word", "a b",
|
||||
"{{ x }}", "{% if %}", "{# c #}", "<|im_start|>", "<|im_end|>", "<think>", "</think>", "<tool_call>",
|
||||
"<tool_response>", "\u{fc}\u{4e2d}\u{6587}\u{1f600}", "\"quoted\"", "back\\slash", "0", "-1.5e10", "null",
|
||||
"[1, 2]", "{\"a\": 1}",
|
||||
"",
|
||||
" ",
|
||||
" ",
|
||||
"\n",
|
||||
"\n\n",
|
||||
"\t",
|
||||
"\r\n",
|
||||
"\u{a0}",
|
||||
"\u{2003}",
|
||||
"\u{1c}",
|
||||
"\u{85}",
|
||||
"\u{200b}",
|
||||
"word",
|
||||
"a b",
|
||||
"{{ x }}",
|
||||
"{% if %}",
|
||||
"{# c #}",
|
||||
"<|im_start|>",
|
||||
"<|im_end|>",
|
||||
"<think>",
|
||||
"</think>",
|
||||
"<tool_call>",
|
||||
"<tool_response>",
|
||||
"\u{fc}\u{4e2d}\u{6587}\u{1f600}",
|
||||
"\"quoted\"",
|
||||
"back\\slash",
|
||||
"0",
|
||||
"-1.5e10",
|
||||
"null",
|
||||
"[1, 2]",
|
||||
"{\"a\": 1}",
|
||||
];
|
||||
|
||||
const EXEC_TOOL: &str = concat!(
|
||||
|
||||
Reference in New Issue
Block a user