Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/guidellm/dataset/synthetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,19 +194,21 @@ def __iter__(
}

def _create_prompt(
self, prompt_tokens: int, start_index: int, unique_prefix: Optional[int] = None
self,
prompt_tokens: int,
start_index: int,
unique_prefix: Optional[int] = None, # noqa: ARG002
) -> list[int]:
if prompt_tokens <= 0:
return []

left = start_index
right = start_index + 4 * prompt_tokens
start_tokens = [unique_prefix] if unique_prefix else []

while left < right:
mid = (left + right) // 2
test_prompt = self.text_creator.create_text(start_index, mid - start_index)
test_tokens = start_tokens + self.processor.encode(test_prompt)
test_tokens = self.processor.encode(test_prompt)

if len(test_tokens) == prompt_tokens:
return test_tokens
Expand All @@ -216,7 +218,7 @@ def _create_prompt(
right = mid

final_text = self.text_creator.create_text(start_index, left - start_index)
return start_tokens + self.processor.encode(final_text)
return self.processor.encode(final_text)


class SyntheticDatasetCreator(DatasetCreator):
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/dataset/test_synthetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ def test_create_prompt_method(

# Test normal case
result = generator._create_prompt(5, 0, 42)
assert result == [42, 1, 2, 3]
assert result == [1, 2, 3]

# Test zero tokens
result = generator._create_prompt(0, 0, 42)
Expand Down