STRA-338 S23: the family is a capability of the codec, not a branch of the protocol code
TextCodec gets always_reasons() (gpt-oss: true) and sampling_limit() (gpt-oss: the worker takes temperature, top_p and seed only; the error message is the family's own). reasoning_enabled(request, codec) and admit.rs (check_live_features, apply_sampling_defaults) read them instead of comparing Family::GptOss, and text.rs / reasoning.rs / tool_recovery.rs pass the codec instead of its family. Proof: output_golden (132 captures) identical, strata-control and gateway-domain lib tests pass, gates green, 0 warnings.
This commit is contained in:
@@ -83,6 +83,15 @@ impl TextCodec for GptOssCodec {
|
||||
Ok(ids)
|
||||
}
|
||||
|
||||
fn always_reasons(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
/// The worker's `GEN` line takes temperature, top_p and seed only.
|
||||
fn sampling_limit(&self) -> Option<&'static str> {
|
||||
Some("the gpt-oss family supports temperature, top_p and seed only")
|
||||
}
|
||||
|
||||
fn decoder(&self) -> Box<dyn TokenDecoder> {
|
||||
Box::new(HarmonyDecoder::new(self.bpe.clone()))
|
||||
}
|
||||
|
||||
@@ -60,23 +60,23 @@ pub(super) fn check_live_features(
|
||||
message,
|
||||
));
|
||||
}
|
||||
if tokenizer.family() == Family::GptOss {
|
||||
// The gpt-oss CPU worker's `GEN` line takes temperature, top_p and seed only. An explicit request for a
|
||||
// sampler it does not have is a client error; defaults from the config or the shared settings are dropped.
|
||||
if let Some(limit) = tokenizer.sampling_limit() {
|
||||
// The worker of some families takes few samplers. An explicit request for one it does not have is a client
|
||||
// error; defaults from the config or the shared settings are dropped.
|
||||
if let Some(param) = unsupported_gptoss_sampling(&request.sampling()) {
|
||||
return Err(api_error(
|
||||
StatusCode::BAD_REQUEST,
|
||||
"invalid_request_error",
|
||||
"unsupported_parameter",
|
||||
Some(param),
|
||||
"the gpt-oss family supports temperature, top_p and seed only",
|
||||
limit,
|
||||
));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// The server's sampling defaults, minus the samplers the gpt-oss worker does not have.
|
||||
/// The server's sampling defaults, minus the samplers the model's worker does not have.
|
||||
pub(super) fn apply_sampling_defaults(
|
||||
state: &AppState,
|
||||
request: &mut CreateRequest,
|
||||
@@ -86,7 +86,7 @@ pub(super) fn apply_sampling_defaults(
|
||||
&state.services.settings.merged(),
|
||||
&state.services.settings.shared(),
|
||||
);
|
||||
if tokenizer.family() == Family::GptOss {
|
||||
if tokenizer.sampling_limit().is_some() {
|
||||
request.top_k = None;
|
||||
request.min_p = None;
|
||||
request.repetition_penalty = None;
|
||||
|
||||
@@ -50,7 +50,7 @@ pub(super) fn reasoning_plan(
|
||||
) -> Option<crate::wire::ReasoningPlan> {
|
||||
// The wrap-up and the byte accounting are the Qwen path's; the Harmony family has no reasoning budget.
|
||||
let tokenizer = codec.qwen()?;
|
||||
if !reasoning_enabled(request, codec.family()) {
|
||||
if !reasoning_enabled(request, codec.as_ref()) {
|
||||
return None;
|
||||
}
|
||||
let budget = leleka_serving_policy::reasoning::parse_budget(
|
||||
|
||||
@@ -25,7 +25,7 @@ pub(in crate::responses) fn stream_live_text(
|
||||
source: mpsc::Receiver<Result<Event, String>>,
|
||||
env: StreamEnv,
|
||||
) -> Response {
|
||||
if is_structured(&request) || reasoning_enabled(&request, tokenizer.family()) {
|
||||
if is_structured(&request) || reasoning_enabled(&request, tokenizer.as_ref()) {
|
||||
return stream_live_buffered(request, tokenizer, source, env);
|
||||
}
|
||||
if !request.tools.is_empty() {
|
||||
|
||||
@@ -23,7 +23,7 @@ pub(super) fn tool_call_recovery() -> bool {
|
||||
/// What the reading at the end of a generation needs for this request and model family.
|
||||
pub(super) fn at_end_plan<C: TextCodec + ?Sized>(request: &CreateRequest, codec: &C) -> AtEndPlan {
|
||||
AtEndPlan {
|
||||
reasoning: reasoning_enabled(request, codec.family()),
|
||||
reasoning: reasoning_enabled(request, codec),
|
||||
tools: (!request.tools.is_empty()).then(|| flat_tools(request)),
|
||||
recovery: tool_call_recovery(),
|
||||
keep_raw: debug_failed_output(),
|
||||
|
||||
@@ -35,6 +35,15 @@ pub trait TextCodec: Send + Sync {
|
||||
fn decoder(&self) -> Box<dyn TokenDecoder>;
|
||||
/// The decoder of one generation that turns the generated ids into output events (see `crate::output`).
|
||||
fn output_decoder<'a>(&self, plan: ReadPlan<'a>) -> OutputDecoder<'a>;
|
||||
/// The model reasons whatever the request's effort says (gpt-oss always opens with its analysis channel).
|
||||
fn always_reasons(&self) -> bool {
|
||||
false
|
||||
}
|
||||
/// What the model's worker cannot sample, in the words of the error a client gets for asking for it; `None`: the
|
||||
/// model takes every sampler of the request.
|
||||
fn sampling_limit(&self) -> Option<&'static str> {
|
||||
None
|
||||
}
|
||||
/// Tokens that end the visible output of a generation (they are not part of the text).
|
||||
fn terminal_ids(&self) -> Vec<u32>;
|
||||
/// Token ids of a rendered prompt, the one tokenization used for generation and for counting. The template's own
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! What the request asks of the model's reasoning, and which sampler fields a model family cannot carry.
|
||||
|
||||
use crate::codec::Family;
|
||||
use crate::codec::TextCodec;
|
||||
use crate::responses::request::{CreateRequest, TextFormat};
|
||||
use leleka_gateway_text::prompt::Effort;
|
||||
use serde_json::Value;
|
||||
@@ -56,9 +56,9 @@ fn effort_level(effort: Option<&Value>) -> Result<Effort, (&'static str, &'stati
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether the output starts inside a reasoning block that ends with `</think>`. gpt-oss always reasons.
|
||||
pub fn reasoning_enabled(request: &CreateRequest, family: Family) -> bool {
|
||||
family == Family::GptOss || reasoning_effort(request).is_ok_and(|effort| effort != Effort::None)
|
||||
/// Whether the output starts inside a reasoning block that ends with `</think>`. A model that always reasons does.
|
||||
pub fn reasoning_enabled<C: TextCodec + ?Sized>(request: &CreateRequest, codec: &C) -> bool {
|
||||
codec.always_reasons() || reasoning_effort(request).is_ok_and(|effort| effort != Effort::None)
|
||||
}
|
||||
|
||||
/// The first sampler the request sets that the gpt-oss worker's `GEN` line cannot carry.
|
||||
|
||||
Reference in New Issue
Block a user