guidellm.data.builders
ShortPromptStrategyHandler
Handler class for short prompt strategies.
Source code in src/guidellm/data/builders.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |
get_strategy_handler(strategy) classmethod
Get the handler for a specific strategy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
strategy | ShortPromptStrategy | The short prompt strategy to get the handler for. | required |
Returns:
| Type | Description |
|---|---|
Callable[..., Any] | The handler callable for the specified strategy. |
Source code in src/guidellm/data/builders.py
handle_concatenate(current_prompt, min_prompt_tokens, dataset_iterator, prompt_column, tokenizer, concat_delimiter, **_kwargs) staticmethod
Concatenates prompts until the minimum token requirement is met.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
current_prompt | str | The initial prompt. | required |
min_prompt_tokens | int | Target minimum token length. | required |
dataset_iterator | Iterator[dict[str, Any]] | Iterator to fetch more prompts. | required |
prompt_column | str | Column key for prompt extraction. | required |
tokenizer | PreTrainedTokenizerBase | Tokenizer used to count tokens. | required |
concat_delimiter | str | Delimiter to use between prompts. | required |
Returns:
| Type | Description |
|---|---|
str | None | Concatenated prompt or None if not enough data. |
Source code in src/guidellm/data/builders.py
handle_error(current_prompt, min_prompt_tokens, tokenizer, **_kwargs) staticmethod
Raises an error if the prompt is too short.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
current_prompt | str | The input prompt. | required |
min_prompt_tokens | int | Required token count. | required |
tokenizer | PreTrainedTokenizerBase | Tokenizer used to count tokens. | required |
Returns:
| Type | Description |
|---|---|
str | None | The input prompt if valid. |
Raises:
| Type | Description |
|---|---|
PromptTooShortError | If the prompt is too short. |
Source code in src/guidellm/data/builders.py
handle_ignore(current_prompt, min_prompt_tokens, tokenizer, **_kwargs) staticmethod
Ignores prompts that are shorter than the required minimum token length.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
current_prompt | str | The input prompt string. | required |
min_prompt_tokens | int | Minimum required token count. | required |
tokenizer | PreTrainedTokenizerBase | Tokenizer used to count tokens. | required |
Returns:
| Type | Description |
|---|---|
str | None | The prompt if it meets the length, otherwise None. |
Source code in src/guidellm/data/builders.py
handle_pad(current_prompt, min_prompt_tokens, tokenizer, pad_char, pad_multiplier=2, **_kwargs) staticmethod
Pads the prompt with a character until it reaches the minimum token length.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
current_prompt | str | The input prompt. | required |
min_prompt_tokens | int | Desired minimum token count. | required |
tokenizer | PreTrainedTokenizerBase | Tokenizer used to count tokens. | required |
pad_char | str | Character used for padding. | required |
pad_multiplier | int | Multiplier for padding character length. | 2 |
Returns:
| Type | Description |
|---|---|
str | Padded prompt string. |
Source code in src/guidellm/data/builders.py
parse_synthetic_config(config_input)
Parse PreprocessDatasetConfig from string or file path.
Reuses SyntheticTextDatasetDeserializer's parsing logic to support: - JSON strings - Key=value pairs - File paths (.json, .yaml, .yml, .config)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_input | str | Path | String or path to config. | required |
Returns:
| Type | Description |
|---|---|
PreprocessDatasetConfig | Parsed PreprocessDatasetConfig instance. |
Raises:
| Type | Description |
|---|---|
ValueError | If the format is not recognized or parsing fails. |
Source code in src/guidellm/data/builders.py
process_dataset(data, output_path, processor, config, processor_args, data_args, data_column_mapper, short_prompt_strategy, pad_char, concat_delimiter, include_prefix_in_token_count, push_to_hub, hub_dataset_id, random_seed)
Main method to process and save a dataset with sampled prompt/output token counts.
Source code in src/guidellm/data/builders.py
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 | |
push_dataset_to_hub(hub_dataset_id, processed_dataset)
Pushes the processed dataset to Hugging Face Hub using HF_TOKEN.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hub_dataset_id | str | None | Identifier on the Hub to push to. | required |
processed_dataset | Dataset | HuggingFace Dataset object. | required |
Raises:
| Type | Description |
|---|---|
ValueError | If hub_dataset_id or HF_TOKEN is not available. |