speculators.cli.prepare_data
Prepare data for speculator training
Accepted inputs contain responses produced by the target model, either as natural-language conversations or as speculator-format input_ids and loss_mask rows. For natural-language input this command:
- Uses the target model's vLLM endpoint to render each conversation
- Derives a loss mask from each assistant-turn boundary
- Records token frequency statistics
Rendering converts an existing on-policy conversation into speculator format. It does not generate responses or make an arbitrary conversation on-policy.
The output of this command is: 1. Processed dataset ready for online training or offline datagen in output_dir 2. Token frequency statistics file at token_freq_path
Preprocessing will be skipped if the dataset already exists at the output directory. Token frequencies are saved in the output directory by default.
Usage::
speculators prepare-data \
--model meta-llama/Llama-3.1-8B-Instruct \
--data ./on_policy_conversations.jsonl \
--render-endpoint http://localhost:8000 \
--output ./training_data \
--max-samples 5000
Functions:
-
assert_safe_to_overwrite–Refuse to
--overwritea directory holding non-artifact files. -
prepare_data–Preprocess a dataset for speculator training.
assert_safe_to_overwrite
Refuse to --overwrite a directory holding non-artifact files.
Guards against pointing --output at a directory with unrelated user files and wiping it: only prepare-data's own outputs (.arrow shards, dataset metadata, and the token frequency file) may be deleted.
Source code in speculators/cli/prepare_data.py
prepare_data
prepare_data(
model: Annotated[
str,
Option(
help="HuggingFace model ID or local path for target model"
),
],
data: Annotated[
list[str],
Option(
--data,
help="Path to training data (repeatable)",
),
],
output: Annotated[
str, Option(help="Directory to save output dataset")
] = "./output",
seq_length: Annotated[
int,
Option(
help="Maximum sequence length for preprocessing and model"
),
] = 8192,
max_samples: Annotated[
int | None,
Option(help="Maximum number of samples to process"),
] = None,
token_freq_path: Annotated[
str | None,
Option(
help="Path to save token frequency distribution"
),
] = None,
render_endpoint: Annotated[
str | None,
Option(
help="Base URL of a running vLLM server (e.g. http://localhost:8000). Required unless every --data input already contains input_ids and loss_mask."
),
] = None,
seed: Annotated[int, Option(help="Random seed")] = 0,
num_preprocessing_workers: Annotated[
int | None,
Option(
help="Number of CPU processes for dataset preprocessing. Each one blocks on a single render call at a time, so this is also the render concurrency. Defaults to a shared render CPU budget using 75% of available CPUs, with a maximum of 128."
),
] = None,
minimum_valid_tokens: Annotated[
int | None,
Option(
help="Drop samples whose loss mask contains fewer than this many trainable tokens."
),
] = None,
overwrite: Annotated[
bool,
Option(
--overwrite,
help="Forcibly rerun. Deletes existing content in output dir",
),
] = False,
allow_empty_output: Annotated[
bool,
Option(
--allow - empty - output,
help="Allow writing an empty preprocessed dataset. By default raises when normalization or filtering removes every sample.",
),
] = False,
trust_remote_code: Annotated[
bool,
Option(
--trust - remote - code,
help="Allow executing code from HF Hub when loading the target model's processor.",
),
] = False,
) -> None
Preprocess a dataset for speculator training.
Tokenizes each sample, produces loss/assistant masks, and records token frequency statistics. Output is a HuggingFace dataset ready for online training or offline data generation.
Source code in speculators/cli/prepare_data.py
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 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 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 | |