Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 42 additions & 9 deletions crates/skippy-server/src/frontend/linear_proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::{
use anyhow::{Result, bail};
use openai_frontend::{OpenAiError, OpenAiResult};
use serde_json::json;
use skippy_runtime::SamplingConfig;

use crate::frontend::{
NativeMtpVerifyWindowDecision, StageOpenAiBackend, TokenControl,
Expand Down Expand Up @@ -431,10 +432,16 @@ pub(crate) fn report_linear_proposal_receipt(
}

pub(crate) fn greedy_linear_proposal_admitted(
sampling_enabled: bool,
sampling: &SamplingConfig,
chat_sampling_metadata: Option<&str>,
) -> bool {
if sampling_enabled {
let greedy_equivalent = !sampling.enabled
|| (sampling.temperature <= 0.0
&& sampling.presence_penalty == 0.0
&& sampling.frequency_penalty == 0.0
&& sampling.repeat_penalty == 1.0
&& sampling.logit_bias.is_empty());
if !greedy_equivalent {
return false;
}
match chat_sampling_metadata {
Expand Down Expand Up @@ -981,19 +988,45 @@ mod tests {
}

#[test]
fn greedy_admission_rejects_sampling_and_grammar() {
assert!(greedy_linear_proposal_admitted(false, None));
assert!(greedy_linear_proposal_admitted(false, Some("{}")));
fn greedy_admission_accepts_zero_temperature_and_rejects_logit_modifiers() {
let disabled = SamplingConfig::default();
let temperature_zero = SamplingConfig {
enabled: true,
temperature: 0.0,
top_p: 0.95,
top_k: 40,
min_p: 0.05,
..SamplingConfig::default()
};
let stochastic = SamplingConfig {
enabled: true,
temperature: 0.8,
..SamplingConfig::default()
};
let biased_greedy = SamplingConfig {
enabled: true,
temperature: 0.0,
logit_bias: vec![skippy_runtime::LogitBias {
token_id: 7,
bias: 1.0,
}],
..SamplingConfig::default()
};

assert!(greedy_linear_proposal_admitted(&disabled, None));
assert!(greedy_linear_proposal_admitted(&disabled, Some("{}")));
assert!(greedy_linear_proposal_admitted(
false,
&disabled,
Some(r#"{"grammar":""}"#)
));
assert!(!greedy_linear_proposal_admitted(true, None));
assert!(greedy_linear_proposal_admitted(&temperature_zero, None));
assert!(!greedy_linear_proposal_admitted(&stochastic, None));
assert!(!greedy_linear_proposal_admitted(&biased_greedy, None));
assert!(!greedy_linear_proposal_admitted(
false,
&disabled,
Some(r#"{"grammar":"root ::= value"}"#)
));
assert!(!greedy_linear_proposal_admitted(false, Some("{")));
assert!(!greedy_linear_proposal_admitted(&disabled, Some("{")));
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion crates/skippy-server/src/frontend/local_generation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ impl StageOpenAiBackend {
&& !request.native_mtp_enabled
&& !generation_hooks_active
&& greedy_linear_proposal_admitted(
request.sampling.enabled,
request.sampling,
request.chat_sampling_metadata,
);
let linear_proposal_max_tokens = if linear_proposals_enabled {
Expand Down
Loading