(
self,
tokenizer: PreTrainedTokenizerBase,
num_requests: int,
prefix_len: int = DEFAULT_PREFIX_LEN,
range_ratio: float = DEFAULT_RANGE_RATIO,
input_len: int = DEFAULT_INPUT_LEN,
output_len: int = DEFAULT_OUTPUT_LEN,
**kwargs,
)
| 424 | RandomDataset.SHAREGPT_URL.split("/")[-1], download_timeout) |
| 425 | |
| 426 | def sample( |
| 427 | self, |
| 428 | tokenizer: PreTrainedTokenizerBase, |
| 429 | num_requests: int, |
| 430 | prefix_len: int = DEFAULT_PREFIX_LEN, |
| 431 | range_ratio: float = DEFAULT_RANGE_RATIO, |
| 432 | input_len: int = DEFAULT_INPUT_LEN, |
| 433 | output_len: int = DEFAULT_OUTPUT_LEN, |
| 434 | **kwargs, |
| 435 | ) -> list[SampleRequest]: |
| 436 | # Enforce range_ratio < 1 |
| 437 | if range_ratio >= 1.0: |
| 438 | raise ValueError( |
| 439 | "random_range_ratio must be < 1.0 to ensure a valid sampling range" |
| 440 | ) |
| 441 | |
| 442 | vocab_size = tokenizer.vocab_size |
| 443 | |
| 444 | prefix_token_ids = (torch.randint( |
| 445 | 0, vocab_size, size=(prefix_len, ), generator=self.rng).tolist() |
| 446 | if prefix_len > 0 else []) |
| 447 | |
| 448 | # New sampling logic: [X * (1 - b), X * (1 + b)] |
| 449 | input_low = int(input_len * (1 - range_ratio)) |
| 450 | input_high = int(input_len * (1 + range_ratio)) |
| 451 | output_low = int(output_len * (1 - range_ratio)) |
| 452 | output_high = int(output_len * (1 + range_ratio)) |
| 453 | |
| 454 | # Add logging for debugging |
| 455 | logger.debug("Sampling input_len from [%s, %s]", input_low, input_high) |
| 456 | logger.debug("Sampling output_len from [%s, %s]", output_low, |
| 457 | output_high) |
| 458 | |
| 459 | input_lens = torch.randint(input_low, |
| 460 | input_high + 1, |
| 461 | size=(num_requests, ), |
| 462 | generator=self.rng).tolist() |
| 463 | output_lens = torch.randint(output_low, |
| 464 | output_high + 1, |
| 465 | size=(num_requests, ), |
| 466 | generator=self.rng).tolist() |
| 467 | offsets = torch.randint(0, |
| 468 | vocab_size, |
| 469 | size=(num_requests, ), |
| 470 | generator=self.rng).tolist() |
| 471 | |
| 472 | requests = [] |
| 473 | if self.sample_from_sharegpt: |
| 474 | with open(self.dataset_path) as f: |
| 475 | dataset = json.load(f) |
| 476 | # Filter out the conversations with less than 2 turns. |
| 477 | dataset = [ |
| 478 | data for data in dataset |
| 479 | if len(data.get("conversations", data.get("conversation", []))) |
| 480 | >= 2 |
| 481 | ] |
| 482 | # Only keep the first turn of each conversation. |
| 483 | dataset = [ |
nothing calls this directly
no test coverage detected