use super::{LogitsContext, LogitsProcessor, ProcessorOutcome};
use crate::scheduler::ActiveSeq;
pub struct MidWordThinkEndMask;
impl LogitsProcessor for MidWordThinkEndMask {
fn apply(
&self,
logits: &mut [f32],
a: &mut ActiveSeq,
ctx: &LogitsContext,
) -> ProcessorOutcome {
if !ctx.sampling.disable_watchdogs
&& ctx.watchdog.thinking_steering
&& a.inside_thinking
&& let Some(end_tok) = ctx.think_end_token
&& let Some(prev_tok) = a.output_tokens.last().copied()
&& let Some(mask) = ctx.mid_word_mask.as_deref()
&& mask.get(prev_tok as usize).copied().unwrap_or(false)
{
let end_idx = end_tok as usize;
if end_idx < logits.len() {
logits[end_idx] = f32::NEG_INFINITY;
}
}
ProcessorOutcome::Continue
}
fn name(&self) -> &'static str {
"mid_word_think_end_mask"
}
}