config: configurable max_new generation budget (default 16384) so CoT+answer are not truncated
This commit is contained in:
1 parent
862897fdbc
commit
4cdc4334d8
6 files changed
+70
-16
No files matched your search
@@ -267,12 +267,19 @@ uses `tracing`; set `RUST_LOG` to control verbosity (default `info`).
|
|||||||
|
|
||||||
The config is the same JSON the other Strata tools use. Keys acted on here include
|
The config is the same JSON the other Strata tools use. Keys acted on here include
|
||||||
`exe`, `args`, `cwd`, `tokenizer`, `model_name`, `host`, `port`, `reasoning_effort`,
|
`exe`, `args`, `cwd`, `tokenizer`, `model_name`, `host`, `port`, `reasoning_effort`,
|
||||||
`sampling`, `api_key`, `allowed_hosts`, `db_path` (GUI session database),
|
`max_new` (default generation budget, see below), `sampling`, `api_key`,
|
||||||
`workspace_root` (framework root), `system_prompt` (general default), `language`
|
`allowed_hosts`, `db_path` (GUI session database), `workspace_root` (framework
|
||||||
(UI/prompt catalog, default `it`), and the optional `startup_timeout_secs` /
|
root), `system_prompt` (general default), `language` (UI/prompt catalog, default
|
||||||
`silence_timeout_secs`. Everything else (`arch`,
|
`it`), and the optional `startup_timeout_secs` / `silence_timeout_secs`. Everything
|
||||||
`mcp_servers`, `cors_origins`, …) is preserved untouched and reported as ignored —
|
else (`arch`, `mcp_servers`, `cors_origins`, …) is preserved untouched and reported
|
||||||
unknown keys never break startup.
|
as ignored — unknown keys never break startup.
|
||||||
|
|
||||||
|
**Generation budget (`max_new`).** When neither the request nor the session sets
|
||||||
|
`max_tokens`, generation is capped at `max_new` tokens (config, default **16384**).
|
||||||
|
Reasoning and answer share this ceiling: it was raised from 2048 because extended
|
||||||
|
chain-of-thought was being truncated mid-reasoning (`finish_reason: length`, empty
|
||||||
|
answer). The model still stops early at EOS, so the larger cap only matters when it
|
||||||
|
would otherwise run out; a per-session/per-request `max_tokens` still overrides it.
|
||||||
|
|
||||||
### Localization (i18n)
|
### Localization (i18n)
|
||||||
|
|
||||||
|
|||||||
@@ -65,8 +65,10 @@ pub trait Formatter: Send + Sync {
|
|||||||
fn model_name(&self) -> &str;
|
fn model_name(&self) -> &str;
|
||||||
|
|
||||||
/// The formatter's default token budget when the request sets none.
|
/// The formatter's default token budget when the request sets none.
|
||||||
|
/// Matches the project-wide generation budget (CoT + answer share it); a
|
||||||
|
/// dialect with a real tokenizer overrides this from its config.
|
||||||
fn default_max_new(&self) -> u32 {
|
fn default_max_new(&self) -> u32 {
|
||||||
2048
|
16384
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Token count of a text, used to route uploads (small-text inline threshold).
|
/// Token count of a text, used to route uploads (small-text inline threshold).
|
||||||
|
|||||||
@@ -77,6 +77,11 @@ pub struct Config {
|
|||||||
/// launcher's monkey-patch).
|
/// launcher's monkey-patch).
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub reasoning_effort: Option<String>,
|
pub reasoning_effort: Option<String>,
|
||||||
|
/// Default generation budget (`max_new` tokens) when neither the request nor
|
||||||
|
/// the session sets one. Reasoning + answer share it; the default is raised
|
||||||
|
/// (16384) so chain-of-thought is not truncated mid-reasoning at the old 2048.
|
||||||
|
#[serde(default)]
|
||||||
|
pub max_new: Option<u32>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub sampling: SamplingDefaults,
|
pub sampling: SamplingDefaults,
|
||||||
|
|
||||||
@@ -263,6 +268,12 @@ impl Config {
|
|||||||
self.language.clone().unwrap_or_else(|| "it".to_string())
|
self.language.clone().unwrap_or_else(|| "it".to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Effective default generation budget: config `max_new` > 16384. This is the
|
||||||
|
/// ceiling on reasoning + answer tokens when a request/session sets none.
|
||||||
|
pub fn max_new_default(&self) -> u32 {
|
||||||
|
self.max_new.unwrap_or(16384)
|
||||||
|
}
|
||||||
|
|
||||||
/// The top-level keys present in the file that we are not acting on —
|
/// The top-level keys present in the file that we are not acting on —
|
||||||
/// reported by `--check` so the shared-file contract stays visible.
|
/// reported by `--check` so the shared-file contract stays visible.
|
||||||
pub fn ignored_keys(&self) -> Vec<&str> {
|
pub fn ignored_keys(&self) -> Vec<&str> {
|
||||||
@@ -395,6 +406,14 @@ mod tests {
|
|||||||
assert_eq!(keys, " temperature=1.0");
|
assert_eq!(keys, " temperature=1.0");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn max_new_default_and_override() {
|
||||||
|
let cfg = Config::parse(REAL, "test").unwrap();
|
||||||
|
assert_eq!(cfg.max_new_default(), 16384); // absent -> raised default
|
||||||
|
let cfg2 = Config::parse(r#"{"exe":"/x/e","max_new":8192}"#, "test").unwrap();
|
||||||
|
assert_eq!(cfg2.max_new_default(), 8192);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn timeouts_default_and_override() {
|
fn timeouts_default_and_override() {
|
||||||
let cfg = Config::parse(REAL, "test").unwrap();
|
let cfg = Config::parse(REAL, "test").unwrap();
|
||||||
|
|||||||
@@ -40,11 +40,19 @@ impl InklingFormatter {
|
|||||||
template,
|
template,
|
||||||
model,
|
model,
|
||||||
effort,
|
effort,
|
||||||
max_new_default: 2048,
|
max_new_default: 16384,
|
||||||
default_sampling,
|
default_sampling,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Override the default generation budget (config `max_new`). Reasoning and
|
||||||
|
/// answer share this ceiling; the model still stops early at EOS, so a larger
|
||||||
|
/// budget only matters when it would otherwise be truncated mid-reasoning.
|
||||||
|
pub fn with_max_new(mut self, n: u32) -> Self {
|
||||||
|
self.max_new_default = n;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// OpenAI messages -> the JSON the template expects, normalizing the newer
|
/// OpenAI messages -> the JSON the template expects, normalizing the newer
|
||||||
/// `developer` role to `system` (the template's role map has no developer).
|
/// `developer` role to `system` (the template's role map has no developer).
|
||||||
fn messages_json(req: &ChatRequest) -> Json {
|
fn messages_json(req: &ChatRequest) -> Json {
|
||||||
|
|||||||
+11
-7
@@ -144,13 +144,16 @@ async fn serve(cfg: &Config, cli_host: Option<&str>, cli_port: Option<u16>) -> E
|
|||||||
return ExitCode::FAILURE;
|
return ExitCode::FAILURE;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let fmt = Arc::new(InklingFormatter::new(
|
let fmt = Arc::new(
|
||||||
tok,
|
InklingFormatter::new(
|
||||||
template,
|
tok,
|
||||||
cfg.model_name().to_string(),
|
template,
|
||||||
cfg.reasoning_effort.clone(),
|
cfg.model_name().to_string(),
|
||||||
cfg.sampling.to_sampling(),
|
cfg.reasoning_effort.clone(),
|
||||||
));
|
cfg.sampling.to_sampling(),
|
||||||
|
)
|
||||||
|
.with_max_new(cfg.max_new_default()),
|
||||||
|
);
|
||||||
|
|
||||||
let engine = match Engine::start(
|
let engine = match Engine::start(
|
||||||
&cfg.exe,
|
&cfg.exe,
|
||||||
@@ -252,6 +255,7 @@ fn print_plan(cfg: &Config, path: &std::path::Path, cli_host: Option<&str>, cli_
|
|||||||
"reasoning_effort: {}",
|
"reasoning_effort: {}",
|
||||||
cfg.reasoning_effort.as_deref().unwrap_or("(default)")
|
cfg.reasoning_effort.as_deref().unwrap_or("(default)")
|
||||||
);
|
);
|
||||||
|
println!("max_new (generation budget): {}", cfg.max_new_default());
|
||||||
println!(
|
println!(
|
||||||
"sampling: temp={:?} top_p={:?} min_p={:?} rep_pen={:?}",
|
"sampling: temp={:?} top_p={:?} min_p={:?} rep_pen={:?}",
|
||||||
cfg.sampling.temperature,
|
cfg.sampling.temperature,
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ fn build_prompt_renders_and_encodes() {
|
|||||||
assert!(prompt.ids.contains(&text_id));
|
assert!(prompt.ids.contains(&text_id));
|
||||||
assert!(prompt.ids.contains(&2)); // "hello"
|
assert!(prompt.ids.contains(&2)); // "hello"
|
||||||
assert!(prompt.ids.contains(&end_id));
|
assert!(prompt.ids.contains(&end_id));
|
||||||
assert_eq!(prompt.max_new, 2048); // default
|
assert_eq!(prompt.max_new, 16384); // default (raised so CoT is not truncated)
|
||||||
let _ = std::fs::remove_file(&path);
|
let _ = std::fs::remove_file(&path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,6 +144,20 @@ fn max_tokens_override_is_honored() {
|
|||||||
let _ = std::fs::remove_file(&path);
|
let _ = std::fs::remove_file(&path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn with_max_new_overrides_default_budget() {
|
||||||
|
let (fmt, _tok, path) = formatter();
|
||||||
|
assert_eq!(fmt.default_max_new(), 16384);
|
||||||
|
let fmt = fmt.with_max_new(8192);
|
||||||
|
assert_eq!(fmt.default_max_new(), 8192);
|
||||||
|
let req: ChatRequest = serde_json::from_value(
|
||||||
|
json!({"model": "test-model", "messages": [{"role": "user", "content": "hello"}]}),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
assert_eq!(fmt.build_prompt(&req).unwrap().max_new, 8192);
|
||||||
|
let _ = std::fs::remove_file(&path);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn decoder_emits_structured_tool_call() {
|
fn decoder_emits_structured_tool_call() {
|
||||||
let (fmt, tok, path) = formatter();
|
let (fmt, tok, path) = formatter();
|
||||||
|
|||||||
Reference in new issue
Block a user