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
+70 -16

No files matched your search

+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 {
+11 -7
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(
tok,
template,
cfg.model_name().to_string(),
cfg.reasoning_effort.clone(),
cfg.sampling.to_sampling(),
));
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,