Create the logit sampling logic from the context.
(ctx: &Context)
| 100 | |
| 101 | /// Create the logit sampling logic from the context. |
| 102 | pub fn create_logits_processor(ctx: &Context) -> LogitsProcessor { |
| 103 | let temperature = ctx.args.temperature; |
| 104 | let sampling = if temperature <= 0. { |
| 105 | Sampling::ArgMax |
| 106 | } else { |
| 107 | match (ctx.args.top_k, ctx.args.top_p) { |
| 108 | // Gumbel-Softmax keeps everything on GPU: generates random noise, |
| 109 | // adds to logits/temperature, and takes argmax — only 4 bytes |
| 110 | // transferred instead of the full 600 KB vocabulary vector. |
| 111 | (None, None) => Sampling::GumbelSoftmax { temperature }, |
| 112 | (Some(k), None) => Sampling::TopK { k, temperature }, |
| 113 | (None, Some(p)) => Sampling::TopP { p, temperature }, |
| 114 | (Some(k), Some(p)) => Sampling::TopKThenTopP { k, p, temperature }, |
| 115 | } |
| 116 | }; |
| 117 | LogitsProcessor::from_sampling(ctx.args.seed, sampling) |
| 118 | } |
| 119 | |
| 120 | /// Shared base for decoder-only text models (LLaMA, Qwen2, Qwen3.5, etc.). |
| 121 | /// |
no outgoing calls