(logits, sampling_metadata, logprobs_mode, token_ids)
| 142 | |
| 143 | |
| 144 | def get_baseline_logprobs(logits, sampling_metadata, logprobs_mode, token_ids): |
| 145 | if logprobs_mode == "raw_logprobs": |
| 146 | logprobs = F.log_softmax(logits, axis=-1) |
| 147 | elif logprobs_mode == "raw_logits": |
| 148 | logprobs = logits.clone() |
| 149 | elif logprobs_mode == "processed_logprobs": |
| 150 | from fastdeploy.model_executor.layers.sample.ops import ( |
| 151 | apply_penalty_multi_scores, |
| 152 | ) |
| 153 | |
| 154 | for proc in sampling_metadata.logits_processors or []: |
| 155 | logits = proc.apply(logits) |
| 156 | |
| 157 | logits = apply_penalty_multi_scores( |
| 158 | sampling_metadata.pre_token_ids, |
| 159 | sampling_metadata.prompt_ids, |
| 160 | sampling_metadata.prompt_lens, |
| 161 | logits, |
| 162 | sampling_metadata.repetition_penalties, |
| 163 | sampling_metadata.frequency_penalties, |
| 164 | sampling_metadata.presence_penalties, |
| 165 | sampling_metadata.temperature, |
| 166 | sampling_metadata.bad_words_token_ids, |
| 167 | sampling_metadata.bad_words_token_len, |
| 168 | sampling_metadata.step_idx, |
| 169 | sampling_metadata.min_dec_lens, |
| 170 | sampling_metadata.eos_token_ids, |
| 171 | ) |
| 172 | logprobs = F.log_softmax(logits, axis=-1) |
| 173 | else: |
| 174 | from fastdeploy.model_executor.layers.sample.ops import ( |
| 175 | apply_penalty_multi_scores, |
| 176 | ) |
| 177 | |
| 178 | for proc in sampling_metadata.logits_processors or []: |
| 179 | logits = proc.apply(logits) |
| 180 | |
| 181 | logits = apply_penalty_multi_scores( |
| 182 | sampling_metadata.pre_token_ids, |
| 183 | sampling_metadata.prompt_ids, |
| 184 | sampling_metadata.prompt_lens, |
| 185 | logits, |
| 186 | sampling_metadata.repetition_penalties, |
| 187 | sampling_metadata.frequency_penalties, |
| 188 | sampling_metadata.presence_penalties, |
| 189 | sampling_metadata.temperature, |
| 190 | sampling_metadata.bad_words_token_ids, |
| 191 | sampling_metadata.bad_words_token_len, |
| 192 | sampling_metadata.step_idx, |
| 193 | sampling_metadata.min_dec_lens, |
| 194 | sampling_metadata.eos_token_ids, |
| 195 | ) |
| 196 | logprobs = logits |
| 197 | token_logprobs = paddle.take_along_axis(logprobs, token_ids, axis=-1) |
| 198 | return token_logprobs |
| 199 | |
| 200 | |
| 201 | def test_sampler_logprobs(): |
no test coverage detected