Run an optimization loop using Optuna to find optimal weight modification parameters. This command iteratively adjusts steering strength, layer positions, and other parameters to achieve a target metric value for any task type.
python -m wisent optimize-weights --task TASK --model MODEL --output-dir DIR [OPTIONS]
python -m wisent optimize-weights \ --task refusal \ --model meta-llama/Llama-3.1-8B-Instruct \ --output-dir ./optimized_model/ \ --target-metric compliance_rate \ --target-value 0.95 \ --trials 100
python -m wisent optimize-weights \ --task arc_easy \ --model meta-llama/Llama-3.1-8B-Instruct \ --output-dir ./smart_model/ \ --target-metric accuracy \ --target-value 0.85 \ --trials 200 \ --early-stop
python -m wisent optimize-weights \ --task personalization \ --trait "responds with technical precision and uses formal language" \ --model meta-llama/Llama-3.1-8B-Instruct \ --output-dir ./formal_model/ \ --method titan \ --num-directions 5 \ --trials 150
python -m wisent optimize-weights \ --task arc_easy,gsm8k,hellaswag \ --model meta-llama/Llama-3.1-8B-Instruct \ --output-dir ./multi_bench_model/ \ --cap-pairs-per-benchmark 50 \ --trials 300 \ --checkpoint ./checkpoint.json \ --s3-bucket wisent-optimization-results
python -m wisent optimize-weights \ --task custom \ --custom-evaluator ./my_eval.py:score_function \ --model meta-llama/Llama-3.1-8B-Instruct \ --output-dir ./custom_model/ \ --target-metric score \ --target-value 0.9
| Argument | Description |
|---|---|
| --task | Task: refusal, personalization, custom, benchmark name, or comma-separated benchmarks |
| --steering-vectors | Path to pre-computed steering vectors (skip generation) |
| Argument | Description |
|---|---|
| --model | HuggingFace model name or path |
| --output-dir | Directory to save the optimized model |
| Argument | Default | Description |
|---|---|---|
| --target-metric | compliance_rate | Metric to optimize (compliance_rate, refusal_rate, accuracy) |
| --target-value | 0.95 | Target value for the metric |
| --direction | auto | Optimization direction: auto, maximize, minimize |
| Argument | Default | Description |
|---|---|---|
| --trials | 300 | Number of optimization trials |
| --startup-trials | 10 | Random startup trials before TPE |
| --early-stop | false | Stop early if target value is reached |
| --early-stop-patience | 10 | Stop if no improvement for N trials |
| Argument | Default | Description |
|---|---|---|
| --strength-range | 0.3,2.0 | Min,max range for projection strength |
| --max-weight-range | 0.5,3.0 | Min,max range for kernel max weight |
| --position-range | 0.3,0.7 | Min,max range for kernel peak position (0-1) |
| --num-pairs | 100 | Number of contrastive pairs to generate |
| Argument | Default | Description |
|---|---|---|
| --method | directional | Method: directional, additive, titan, prism, pulse |
| --components | o_proj, down_proj | Components to modify |
| --num-directions | 5 | Directions per layer for multi-direction methods |
| Argument | Default | Description |
|---|---|---|
| --checkpoint | - | Path to checkpoint file (saves/resumes optimization) |
| --checkpoint-interval | 5 | Save checkpoint every N trials |
| --s3-bucket | - | S3 bucket to upload results on completion |
Stay in the loop. Never miss out.
Subscribe to our newsletter and unlock Wisent insights.