Skip to main content
Use the Custom Speculator API to train a speculative decoding drafter for a supported base model in Token Factory. A custom speculator job produces a drafter artifact that can be served with vLLM for speculative decoding.

Create a custom speculator job

Create a fine-tuning job with method.type="spec-draft" and provide speculator hyperparameters under method.spec_draft.hyperparameters.

Dataset format

Only pretokenized datasets are supported. Upload a JSONL file where each line contains:
  • input_ids — array of token IDs.
  • attention_mask — array of 1s and 0s aligned with input_ids.
  • labels — array of target token IDs. Use -100 to ignore a position in the loss.

Request fields

Top-level fields

Method fields

Hyperparameters

Supported architectures

Supported losses

Set the training loss with loss.type. Supported values:
  • kl — Standard Kullback-Leibler divergence loss between drafter and target model logits.
  • lk_alpha — LK loss with KL disabled.
  • lk_hybrid — Weighted combination of KL and LK losses.

Training metrics

Custom speculator jobs report two categories of metrics:
  • Loss metrics for monitoring optimization and model behavior during training.
  • Sampling performance metrics for estimating speculative decoding quality and efficiency.
Some per-head metrics are reported conditionally. For a given head, the metric is computed under the assumption that all previous speculative tokens were accepted. For example, metrics for head 4 are conditioned on tokens 1 through 3 being accepted.

Loss metrics

The following loss metrics are reported during training:
All of the losses above are reported regardless of which loss.type is selected.

Sampling performance metrics

Each decoding head reports the following sampling performance metrics:

Metric variations

Sampling metrics may be reported for multiple evaluation variations:
Standard sampling with temperature=1.0. Use this variation to understand expected acceptance behavior under normal sampling.

Output artefacts

A completed custom speculator job produces the following artifact structure:
To download the resulting artefacts, see Download checkpoints and model files.

Serving with vLLM

Serve the resulting artifact with vLLM by passing it through --speculative-config:
Eagle weight tying. For Eagle-based architectures, weights are tied across heads. Only one head’s weights are stored in the artifact, even when the model was trained with multiple decoding heads (e.g. num_decoding_heads=3).As a result, the speculator can be served with any num_speculative_tokens value from 1 to N, but it typically performs best when num_speculative_tokens matches or is lower than the number of decoding heads used during training.

Tuning ntokens

Set ntokens close to the observed acceptance rate to balance speculation against compute overhead. For example, if ntokens=7 yields an acceptance rate of ~3.86, dropping to 3 or 4 will typically improve throughput.