apply_penalties_and_bias

Function apply_penalties_and_bias 

Source
pub fn apply_penalties_and_bias(
    logits: &mut [f32],
    params: &SamplingParams,
    token_history: &[u32],
)
Expand description

Apply repetition / presence / frequency / LZ / DRY penalties and per-token logit bias to logits IN PLACE, using token_history.

SSOT for the pre-filter logit-modification block. Extracted verbatim from sample_with_params_seeded (the non-MTP sampling path) so the MTP verify path (verify_pick_with_pipeline) and bootstrap path (sample_token_with_grammar) apply the same penalties+bias the non-MTP path does — previously those two paths emitted tokens with no penalties (hardcoded repetition_penalty=1.0, empty history), so the configured repetition_penalty/dry_multiplier from MODEL.toml never reached MTP-emitted tokens and the model degenerated into repeated tool-call argument junk.

BACKWARD-COMPATIBLE / ADDITIVE: a mathematical no-op when repetition_penalty == 1.0, presence_penalty == 0.0, frequency_penalty == 0.0, lz_penalty <= 0.0, dry_multiplier <= 0.0 and logit_bias is empty — every branch below is individually gated on its parameter being non-neutral, so the NVFP4 / Gemma / Mistral presets (which use those neutral values) are byte-for-byte unchanged.