| 1132 | |
| 1133 | |
| 1134 | class MTPSampler(nn.Layer): |
| 1135 | """ """ |
| 1136 | |
| 1137 | def __init__(self, fd_config: FDConfig): |
| 1138 | """ """ |
| 1139 | super().__init__() |
| 1140 | if current_platform.is_cuda() or current_platform.is_maca(): |
| 1141 | self.forward = self.forward_cuda |
| 1142 | elif current_platform.is_xpu(): |
| 1143 | self.forward = self.forward_xpu |
| 1144 | else: |
| 1145 | raise NotImplementedError |
| 1146 | self.logprobs_mode = fd_config.model_config.logprobs_mode |
| 1147 | self.enable_draft_logprob = fd_config.speculative_config.enable_draft_logprob |
| 1148 | |
| 1149 | def pre_process(self, skip_idx_list: List[int] = []): |
| 1150 | """pre process before running""" |
| 1151 | pass |
| 1152 | |
| 1153 | def apply_logits_processor( |
| 1154 | self, |
| 1155 | ids: int, |
| 1156 | future: Optional[Any] = None, |
| 1157 | prefill_tokens: List[int] = [], |
| 1158 | ): |
| 1159 | """apply logits processor to sampler""" |
| 1160 | pass |
| 1161 | |
| 1162 | def set_reasoning_parser(self, reasoning_parser: Optional[ReasoningParser] = None): |
| 1163 | """set reasoning parser""" |
| 1164 | pass |
| 1165 | |
| 1166 | def post_process(self, next_tokens: paddle.Tensor, skip_idx_list: List[int] = []): |
| 1167 | """post process after running""" |
| 1168 | pass |
| 1169 | |
| 1170 | def compute_logprobs( |
| 1171 | self, |
| 1172 | logits: paddle.Tensor, |
| 1173 | sampling_metadata: SamplingMetadata, |
| 1174 | ) -> paddle.Tensor: |
| 1175 | """compute logprobs""" |
| 1176 | share_inputs = sampling_metadata.share_inputs |
| 1177 | real_bsz = share_inputs["seq_lens_this_time"].shape[0] |
| 1178 | last_logits = logits |
| 1179 | temp_scaled_logprobs = sampling_metadata.temp_scaled_logprobs |
| 1180 | top_p_normalized_logprobs = sampling_metadata.top_p_normalized_logprobs |
| 1181 | if temp_scaled_logprobs is not None: |
| 1182 | real_bsz_temp_scaled = temp_scaled_logprobs[:real_bsz] |
| 1183 | temperature = sampling_metadata.temperature[:real_bsz] |
| 1184 | real_bsz_temp_scaled = ( |
| 1185 | real_bsz_temp_scaled.astype("int32") |
| 1186 | .squeeze(1) |
| 1187 | .repeat_interleave(share_inputs["batch_token_num"][:real_bsz]) |
| 1188 | .astype("bool") |
| 1189 | ) |
| 1190 | temperature = temperature.squeeze(1).repeat_interleave(share_inputs["batch_token_num"][:real_bsz]) |
| 1191 | temp_temperature = paddle.where( |
no outgoing calls