Skip to content

Commit c2c72d7

Browse files
committed
Initial commit to add unique prefix - increasing number
1 parent 9108369 commit c2c72d7

File tree

2 files changed

+600
-6
lines changed

2 files changed

+600
-6
lines changed

src/guidellm/dataset/synthetic.py

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ def __init__(
138138
self.text_creator = EndlessTextCreator(
139139
data=config.source,
140140
)
141+
# Add counter for unique prefixes
142+
self.request_counter = 0
141143

142144
def __iter__(
143145
self,
@@ -170,22 +172,44 @@ def __iter__(
170172
output_tokens_sampler,
171173
):
172174
start_index = rand.randint(0, len(self.text_creator.words))
175+
# Increment counter for each request
176+
self.request_counter += 1
173177
yield {
174-
"prompt": self._create_prompt(prompt_tokens, start_index),
178+
"prompt": self._create_prompt(prompt_tokens, start_index, self.request_counter),
175179
"prompt_tokens_count": prompt_tokens,
176180
"output_tokens_count": output_tokens,
177181
}
178182

179-
def _create_prompt(self, prompt_tokens: int, start_index: int) -> str:
183+
def _create_prompt(self, prompt_tokens: int, start_index: int, request_id: int) -> str:
184+
"""
185+
Create a prompt with unique prefix to prevent vLLM prefix caching.
186+
187+
Args:
188+
prompt_tokens: Target number of tokens for the prompt
189+
start_index: Starting position in the text corpus
190+
request_id: Unique identifier for this request (used as prefix)
191+
Returns:
192+
Generated prompt string with unique prefix
193+
"""
180194
if prompt_tokens <= 0:
181-
return ""
195+
return f"{request_id}: "
196+
197+
# Create unique prefix that will prevent any prefix caching
198+
unique_prefix = f"{request_id}: "
199+
200+
# Calculate how many tokens the prefix uses
201+
prefix_tokens = len(self.processor.tokenize(unique_prefix))
202+
203+
# Adjust target tokens to account for the prefix
204+
remaining_tokens = max(1, prompt_tokens - prefix_tokens)
182205

183206
left = start_index
184-
right = start_index + 4 * prompt_tokens
207+
right = start_index + 4 * remaining_tokens
185208

186209
while left < right:
187210
mid = (left + right) // 2
188-
test_prompt = self.text_creator.create_text(start_index, mid - start_index)
211+
base_text = self.text_creator.create_text(start_index, mid - start_index)
212+
test_prompt = unique_prefix + base_text
189213
test_tokens = len(self.processor.tokenize(test_prompt))
190214

191215
if test_tokens == prompt_tokens:
@@ -195,7 +219,8 @@ def _create_prompt(self, prompt_tokens: int, start_index: int) -> str:
195219
else:
196220
right = mid
197221

198-
return self.text_creator.create_text(start_index, left - start_index)
222+
base_text = self.text_creator.create_text(start_index, left - start_index)
223+
return unique_prefix + base_text
199224

200225

201226
class SyntheticDatasetCreator(DatasetCreator):

0 commit comments

Comments
 (0)