All knobs live in configs/diffing/method/contrastive_decoding.yaml and can be overridden on the Hydra CLI with diffing.method.<param>=<value>.
| value | formula | hyperparameters |
|---|---|---|
cd (default) |
((1+β) log p_ft − β log p_base) / T |
β, α, T |
pure_cd |
(log p_ft − log p_base) / T |
α, T |
pure_cd is the limiting case of cd as β = T → ∞ along the diagonal path. It reduces the hyperparameter count by one and preserves sampling diversity that the horizontal limit (large β, fixed T) destroys.
Parameters:
| param | default | effect |
|---|---|---|
beta |
[1.0] |
contrastive weight; list = sweep. Ignored by pure_cd. |
alpha |
[0.1] |
plausibility threshold: tokens with p_ft < α · max p_ft are masked. 0 = no masking. List = sweep. |
temperature |
1.0 |
scales the final logits before sampling. For pure_cd, T→0 approaches greedy argmax of the CD score (use do_sample: false instead); T=1 is the diagonal limit; T>1 increases diversity at the cost of signal. |
Controls what text the model is seeded with before generation starts. The JSON file is always loaded; the strategy controls whether the chat template prefix is prepended.
| value | prefills produced |
|---|---|
no_prefix (default) |
JSON prefills as-is |
chat_template_prefix |
chat template prefix prepended to every JSON prefill |
both |
both sets combined (2× prefills) |
Related parameters:
| param | default | effect |
|---|---|---|
prefills_file |
resources/prefill_candidates_contrastive.json |
JSON file with prefill candidates, grouped by category. Values are concatenated into a flat list. |
n_trials |
10 |
generations per prefill. Set to 1 when diversity comes from prefills rather than sampling. |
prefill_batch_size |
10 |
prefills processed per generate_contrastive call. Tune to fit GPU memory. |
Chat template prefix seeds generation from the exact position where the user turn begins (e.g. <start_of_turn>user\n for Gemma3). This targets the finetuning prompts rather than the answers.
| param | default | effect |
|---|---|---|
warmup_steps |
0 (disabled) |
Number of tokens decoded with the CD formula before switching to raw finetuned model logits. After warmup, the model continues coherently from the topic established by the CD prefix. |
When to use: greedy pure CD produces high-signal but degenerate long tails. A warmup of 10–30 tokens anchors the topic, then hands off to the finetuned model for fluent continuation.
| param | default | effect |
|---|---|---|
max_new_tokens |
300 |
generation length. Most extractable signal is in the first ~80 tokens before degeneration; shorter runs are faster and often cleaner. |
do_sample |
true |
false = greedy argmax. Greedy + pure_cd + diverse prefills is a useful configuration: zero stochasticity, diversity from prefills only. |
Default (paper):
# cd, beta=1, alpha=0.1, 10 trials per vague prefill
python main.py diffing/method=contrastive_decoding organism=X model=YContrastive limit — greedy, 50 prefills:
python main.py diffing/method=contrastive_decoding \
diffing.method.combination=pure_cd \
diffing.method.prefills_file=resources/prefill_candidates_50words.json \
diffing.method.n_trials=1 \
diffing.method.do_sample=false \
organism=X model=YWarmup for coherent extractions:
python main.py diffing/method=contrastive_decoding \
diffing.method.combination=pure_cd \
diffing.method.warmup_steps=20 \
diffing.method.do_sample=true \
organism=X model=YTarget training prompts (chat prefix):
python main.py diffing/method=contrastive_decoding \
diffing.method.prefill_strategy=chat_template_prefix \
organism=X model=Y