You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## Summary
This PR re-enables, tests, and documents the `preprocess dataset`
command.
Also changes the format that prompt and output sizes are specified, and
makes the code aware of prefixes.
## Details
- Uses the post-refactor code to re-enable the command.
- Switches over to the same format used by `benchmark run`'s synthetic
data for the data config to enable more features and make the command
more cohesive with the rest of GuideLLM.
- Adds options for prefixes. I added an option to include prefixes in
the count, since prefixes are included in input and output tokens, and
affect performance.
## Test Plan
- Run with a known dataset, or create one as a simple CSV.
- New tests are added that should cover everything except huggingface
uploads. They are all at least in part generated by AI, but I went
through each one iteratively to ensure they do what they need to do.
---
- [x] "I certify that all code in this PR is my own, except as noted
below."
## Use of AI
- [x] Includes AI-assisted code completion
- [x] Includes code generated by an AI application
- [x] Includes AI-generated tests (NOTE: AI written tests should have a
docstring that includes `## WRITTEN BY AI ##`)
- For lists of dictionaries, all items must have the same keys.
213
213
- For lists of items, all elements must be of the same type.
214
214
- A processor/tokenizer is only required if `GUIDELLM__PREFERRED_PROMPT_TOKENS_SOURCE="local"` or `GUIDELLM__PREFERRED_OUTPUT_TOKENS_SOURCE="local"` is set in the environment. In this case, the processor/tokenizer must be specified using the `--processor` argument. If not set, the processor/tokenizer will be set to the model passed in or retrieved from the server.
215
+
216
+
## Preprocessing Datasets
217
+
218
+
GuideLLM provides a preprocessing command that allows you to process datasets to have specific prompt and output token sizes. This is particularly useful when you need to standardize your dataset for benchmarking or when your dataset has prompts that don't match your target token requirements.
219
+
220
+
The preprocessing command can:
221
+
222
+
- Resize prompts to target token lengths
223
+
- Handle prompts that are shorter or longer than the target length using various strategies
224
+
- Map columns from your dataset to GuideLLM's expected column names
225
+
- Generate output token counts based on your configuration
|`DATA`| Path to the input dataset or Hugging Face dataset ID. Supports all dataset formats documented in the [Dataset Configurations](../datasets.md). |
243
+
|`OUTPUT_PATH`| Path to save the processed dataset, including file suffix (e.g., `processed_dataset.jsonl`, `output.csv`). |
244
+
|`--processor`|**Required.** Processor or tokenizer name/path for calculating token counts. Can be a Hugging Face model ID or local path. |
245
+
|`--config`|**Required.** Configuration specifying target token sizes. Can be a JSON string, key=value pairs, or file path (.json, .yaml, .yml, .config). |
The `--config` parameter accepts a `PreprocessDatasetConfig` as a JSON string, key=value pairs, or a configuration file path (.json, .yaml, .yml, .config). This configuration is similar to the synthetic data configuration but includes additional fields specific to preprocessing.
260
+
261
+
**PreprocessDatasetConfig Options:**
262
+
263
+
-`prompt_tokens`: Average number of tokens in prompts. If nothing else is specified, all prompts will be resized to this number of tokens.
264
+
-`prompt_tokens_stdev`: Standard deviation for prompt tokens. If not supplied and min/max are not specified, no deviation is applied. If not supplied and min/max are specified, a uniform distribution is used.
265
+
-`prompt_tokens_min`: Minimum number of tokens in prompts. If unset and `prompt_tokens_stdev` is set, the minimum is 1.
266
+
-`prompt_tokens_max`: Maximum number of tokens in prompts. If unset and `prompt_tokens_stdev` is set, the maximum is 5 times the standard deviation.
267
+
-`output_tokens`: Average number of tokens in outputs. If nothing else is specified, all outputs will have this number of tokens.
268
+
-`output_tokens_stdev`: Standard deviation for output tokens. If not supplied and min/max are not specified, no deviation is applied. If not supplied and min/max are specified, a uniform distribution is used.
269
+
-`output_tokens_min`: Minimum number of tokens in outputs. If unset and `output_tokens_stdev` is set, the minimum is 1.
270
+
-`output_tokens_max`: Maximum number of tokens in outputs. If unset and `output_tokens_stdev` is set, the maximum is 5 times the standard deviation.
271
+
-`prefix_tokens_max`: Maximum number of prefix tokens to keep. If set, prefixes will be trimmed to this maximum length. If not set, prefixes are kept as-is (unless `--include-prefix-in-token-count` is used, which disables prefix trimming).
The `--processor` argument specifies the tokenizer to use for calculating token counts. This is required because the preprocessing command needs to tokenize prompts to ensure they match the target token sizes. For information about using processors, including Hugging Face model IDs, local paths, and processor arguments, see the [Data Arguments Overview](../datasets.md#data-arguments-overview) section.
287
+
288
+
### Column Mapping
289
+
290
+
When your dataset uses non-standard column names, you can use `--data-column-mapper` to map your columns to GuideLLM's expected column names. This is particularly useful when:
291
+
292
+
1.**Your dataset uses different column names** (e.g., `question` instead of `prompt`, `instruction` instead of `text_column`)
293
+
2.**You have multiple datasets** and need to specify which dataset's columns to use
294
+
3.**Your dataset has system prompts or prefixes** in a separate column
295
+
296
+
**Column mapping format:** The `--data-column-mapper` accepts a JSON string mapping column types to column names:
297
+
298
+
```json
299
+
{
300
+
"text_column": "question",
301
+
"prefix_column": "system_prompt",
302
+
"prompt_tokens_count_column": "input_tokens",
303
+
"output_tokens_count_column": "completion_tokens"
304
+
}
305
+
```
306
+
307
+
**Supported column types:**
308
+
309
+
-`text_column`: The main prompt text (defaults: `prompt`, `instruction`, `question`, `input`, `context`, `content`, `text`)
310
+
-`prefix_column`: System prompt or prefix (defaults: `system_prompt`, `system`, `prefix`)
If you're working with multiple datasets and need to specify which dataset's columns to use, you can use the format `<dataset_index>.<column_name>` or `<dataset_name>.<column_name>`:
|`--data-args <JSON>`| JSON string of arguments to pass to dataset loading. See [Data Arguments Overview](../datasets.md#data-arguments-overview) for details. |
386
+
|`--include-prefix-in-token-count`| Include prefix tokens in prompt token count calculation (flag). When enabled, prefix trimming is disabled and the prefix is kept as-is. |
387
+
|`--random-seed <NUMBER>`| Random seed for reproducible token sampling (default: 42). |
388
+
|`--push-to-hub`| Push the processed dataset to Hugging Face Hub (flag). |
389
+
|`--hub-dataset-id <ID>`| Hugging Face Hub dataset ID for upload (required if `--push-to-hub` is set). |
390
+
391
+
### Complete Examples
392
+
393
+
**Example 1: Basic preprocessing with custom column names**
**Example 4: Preprocessing and uploading to Hugging Face Hub**
430
+
431
+
```bash
432
+
guidellm preprocess dataset \
433
+
"my_dataset.jsonl" \
434
+
"processed.jsonl" \
435
+
--processor "gpt2" \
436
+
--config "prompt_tokens=512,output_tokens=256" \
437
+
--push-to-hub \
438
+
--hub-dataset-id "username/processed-dataset"
439
+
```
440
+
441
+
### Notes
442
+
443
+
- The `--config` parameter accepts a `PreprocessDatasetConfig` which includes all token count fields (prompt_tokens, output_tokens, etc.) plus `prefix_tokens_max` for controlling prefix length. See the [Configuration and Processor Options](#configuration-and-processor-options) section above for all available parameters.
444
+
- The processor/tokenizer is required because the preprocessing command needs to tokenize prompts to ensure they match target token sizes. See the [Data Arguments Overview](../datasets.md#data-arguments-overview) for processor usage details.
445
+
- Column mappings are only needed when your dataset uses non-standard column names. GuideLLM will automatically try common column names if no mapping is provided.
446
+
- When using `--short-prompt-strategy concatenate`, ensure your dataset has enough samples to concatenate, or some prompts may be skipped.
447
+
- The output format is determined by the file extension of `OUTPUT_PATH` (e.g., `.jsonl`, `.csv`, `.parquet`).
448
+
- The prefix handling only trims prefixes. It doesn't expand them. Use `prefix_tokens_max` in the config to set a maximum prefix length, which will trim prefixes that exceed this limit.
0 commit comments