(self,
tokenizer: PreTrainedTokenizerBase,
num_requests: int,
output_len: Optional[int] = None,
enable_multimodal_chat: bool = False,
**kwargs)
| 1233 | } |
| 1234 | |
| 1235 | def sample(self, |
| 1236 | tokenizer: PreTrainedTokenizerBase, |
| 1237 | num_requests: int, |
| 1238 | output_len: Optional[int] = None, |
| 1239 | enable_multimodal_chat: bool = False, |
| 1240 | **kwargs) -> list: |
| 1241 | output_len = (output_len |
| 1242 | if output_len is not None else self.DEFAULT_OUTPUT_LEN) |
| 1243 | |
| 1244 | # Collect prompts for batch processing |
| 1245 | prompts = [] |
| 1246 | for item in self.data: |
| 1247 | if len(prompts) >= num_requests: |
| 1248 | break |
| 1249 | raw_prompt = item['turns'][0] |
| 1250 | |
| 1251 | # apply template |
| 1252 | formatted_prompt = tokenizer.apply_chat_template( |
| 1253 | [{ |
| 1254 | "role": "user", |
| 1255 | "content": raw_prompt |
| 1256 | }], |
| 1257 | add_generation_prompt=True, |
| 1258 | tokenize=False) |
| 1259 | prompts.append(formatted_prompt) |
| 1260 | |
| 1261 | # Batch tokenize prompts |
| 1262 | prompt_lengths, _ = batch_tokenize_prompts( |
| 1263 | prompts, tokenizer, progress_name="MT-Bench prompts") |
| 1264 | |
| 1265 | # Create samples |
| 1266 | sampled_requests = [] |
| 1267 | for prompt, prompt_len in zip(prompts, prompt_lengths): |
| 1268 | sampled_requests.append( |
| 1269 | SampleRequest( |
| 1270 | prompt=prompt, |
| 1271 | prompt_len=prompt_len, |
| 1272 | expected_output_len=output_len, |
| 1273 | )) |
| 1274 | self.maybe_oversample_requests(sampled_requests, num_requests) |
| 1275 | return sampled_requests |
| 1276 | |
| 1277 | |
| 1278 | # ----------------------------------------------------------------------------- |
nothing calls this directly
no test coverage detected