config: configurable max_new generation budget (default 16384) so CoT+answer are not truncated

This commit is contained in:
adm committed 2026-11-27 18:13:18 +01:00
1 parent 862897fdbc
commit 4cdc4334d8
6 files changed
+65 -11

No files matched your search

+13 -6
View File
@@ -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
`exe`, `args`, `cwd`, `tokenizer`, `model_name`, `host`, `port`, `reasoning_effort`,
`sampling`, `api_key`, `allowed_hosts`, `db_path` (GUI session database),
`workspace_root` (framework root), `system_prompt` (general default), `language`
(UI/prompt catalog, default `it`), and the optional `startup_timeout_secs` /
`silence_timeout_secs`. Everything else (`arch`,
`mcp_servers`, `cors_origins`, …) is preserved untouched and reported as ignored —
unknown keys never break startup.
`max_new` (default generation budget, see below), `sampling`, `api_key`,
`allowed_hosts`, `db_path` (GUI session database), `workspace_root` (framework
root), `system_prompt` (general default), `language` (UI/prompt catalog, default
`it`), and the optional `startup_timeout_secs` / `silence_timeout_secs`. Everything
else (`arch`, `mcp_servers`, `cors_origins`, …) is preserved untouched and reported
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)
+3 -1
View File
@@ -65,8 +65,10 @@ pub trait Formatter: Send + Sync {
fn model_name(&self) -> &str;
/// 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 {
2048
16384
}
/// Token count of a text, used to route uploads (small-text inline threshold).
+19
View File
@@ -77,6 +77,11 @@ pub struct Config {
/// launcher's monkey-patch).
#[serde(default)]
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)]
pub sampling: SamplingDefaults,
@@ -263,6 +268,12 @@ impl Config {
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 —
/// reported by `--check` so the shared-file contract stays visible.
pub fn ignored_keys(&self) -> Vec<&str> {
@@ -395,6 +406,14 @@ mod tests {
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]
fn timeouts_default_and_override() {
let cfg = Config::parse(REAL, "test").unwrap();
+9 -1
View File
@@ -40,11 +40,19 @@ impl InklingFormatter {
template,
model,
effort,
max_new_default: 2048,
max_new_default: 16384,
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
/// `developer` role to `system` (the template's role map has no developer).
fn messages_json(req: &ChatRequest) -> Json {
+6 -2
View File
@@ -144,13 +144,16 @@ async fn serve(cfg: &Config, cli_host: Option<&str>, cli_port: Option<u16>) -> E
return ExitCode::FAILURE;
}
};
let fmt = Arc::new(InklingFormatter::new(
let fmt = Arc::new(
InklingFormatter::new(
tok,
template,
cfg.model_name().to_string(),
cfg.reasoning_effort.clone(),
cfg.sampling.to_sampling(),
));
)
.with_max_new(cfg.max_new_default()),
);
let engine = match Engine::start(
&cfg.exe,
@@ -252,6 +255,7 @@ fn print_plan(cfg: &Config, path: &std::path::Path, cli_host: Option<&str>, cli_
"reasoning_effort: {}",
cfg.reasoning_effort.as_deref().unwrap_or("(default)")
);
println!("max_new (generation budget): {}", cfg.max_new_default());
println!(
"sampling: temp={:?} top_p={:?} min_p={:?} rep_pen={:?}",
cfg.sampling.temperature,
+15 -1
View File
@@ -86,7 +86,7 @@ fn build_prompt_renders_and_encodes() {
assert!(prompt.ids.contains(&text_id));
assert!(prompt.ids.contains(&2)); // "hello"
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);
}
@@ -144,6 +144,20 @@ fn max_tokens_override_is_honored() {
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]
fn decoder_emits_structured_tool_call() {
let (fmt, tok, path) = formatter();