wisent 0.7.701__py3-none-any.whl → 0.7.1045__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- wisent/__init__.py +1 -1
- wisent/comparison/__init__.py +1 -0
- wisent/comparison/detect_bos_features.py +275 -0
- wisent/comparison/fgaa.py +465 -0
- wisent/comparison/lora.py +669 -0
- wisent/comparison/lora_dpo.py +592 -0
- wisent/comparison/main.py +444 -0
- wisent/comparison/ours.py +76 -0
- wisent/comparison/sae.py +304 -0
- wisent/comparison/utils.py +381 -0
- wisent/core/activations/activation_cache.py +393 -0
- wisent/core/activations/activations.py +3 -3
- wisent/core/activations/activations_collector.py +12 -7
- wisent/core/activations/classifier_inference_strategy.py +12 -11
- wisent/core/activations/extraction_strategy.py +260 -84
- wisent/core/classifiers/classifiers/core/atoms.py +3 -2
- wisent/core/cli/__init__.py +2 -1
- wisent/core/cli/agent/train_classifier.py +16 -3
- wisent/core/cli/check_linearity.py +35 -3
- wisent/core/cli/cluster_benchmarks.py +4 -6
- wisent/core/cli/create_steering_vector.py +6 -4
- wisent/core/cli/diagnose_vectors.py +7 -4
- wisent/core/cli/estimate_unified_goodness_time.py +6 -4
- wisent/core/cli/generate_pairs_from_task.py +9 -56
- wisent/core/cli/generate_vector_from_task.py +11 -20
- wisent/core/cli/geometry_search.py +137 -0
- wisent/core/cli/get_activations.py +2 -2
- wisent/core/cli/method_optimizer.py +4 -3
- wisent/core/cli/modify_weights.py +3 -2
- wisent/core/cli/optimize_sample_size.py +1 -1
- wisent/core/cli/optimize_steering.py +14 -16
- wisent/core/cli/optimize_weights.py +2 -1
- wisent/core/cli/preview_pairs.py +203 -0
- wisent/core/cli/steering_method_trainer.py +3 -3
- wisent/core/cli/tasks.py +19 -76
- wisent/core/cli/train_unified_goodness.py +3 -3
- wisent/core/contrastive_pairs/diagnostics/control_vectors.py +4 -4
- wisent/core/contrastive_pairs/diagnostics/linearity.py +7 -0
- wisent/core/contrastive_pairs/huggingface_pairs/hf_task_extractors/agentic_search.py +37 -347
- wisent/core/contrastive_pairs/huggingface_pairs/hf_task_extractors/aider_polyglot.py +113 -136
- wisent/core/contrastive_pairs/huggingface_pairs/hf_task_extractors/codeforces.py +2 -12
- wisent/core/contrastive_pairs/huggingface_pairs/hf_task_extractors/coding_benchmarks.py +124 -504
- wisent/core/contrastive_pairs/huggingface_pairs/hf_task_extractors/faithbench.py +40 -63
- wisent/core/contrastive_pairs/huggingface_pairs/hf_task_extractors/flames.py +46 -89
- wisent/core/contrastive_pairs/huggingface_pairs/hf_task_extractors/flores.py +15 -4
- wisent/core/contrastive_pairs/huggingface_pairs/hf_task_extractors/frames.py +36 -20
- wisent/core/contrastive_pairs/huggingface_pairs/hf_task_extractors/hallucinations_leaderboard.py +3 -45
- wisent/core/contrastive_pairs/huggingface_pairs/hf_task_extractors/livemathbench.py +42 -4
- wisent/core/contrastive_pairs/huggingface_pairs/hf_task_extractors/longform_writing.py +2 -112
- wisent/core/contrastive_pairs/huggingface_pairs/hf_task_extractors/math500.py +39 -4
- wisent/core/contrastive_pairs/huggingface_pairs/hf_task_extractors/medium_priority_benchmarks.py +475 -525
- wisent/core/contrastive_pairs/huggingface_pairs/hf_task_extractors/mercury.py +65 -42
- wisent/core/contrastive_pairs/huggingface_pairs/hf_task_extractors/olympiadbench.py +2 -12
- wisent/core/contrastive_pairs/huggingface_pairs/hf_task_extractors/planbench.py +78 -219
- wisent/core/contrastive_pairs/huggingface_pairs/hf_task_extractors/polymath.py +37 -4
- wisent/core/contrastive_pairs/huggingface_pairs/hf_task_extractors/recode.py +84 -69
- wisent/core/contrastive_pairs/huggingface_pairs/hf_task_extractors/refusalbench.py +168 -160
- wisent/core/contrastive_pairs/huggingface_pairs/hf_task_extractors/simpleqa.py +44 -25
- wisent/core/contrastive_pairs/huggingface_pairs/hf_task_extractors/tau_bench.py +3 -103
- wisent/core/contrastive_pairs/huggingface_pairs/hf_task_extractors/toolbench.py +3 -97
- wisent/core/contrastive_pairs/huggingface_pairs/hf_task_extractors/toolemu.py +48 -182
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_extractor_manifest.py +3 -0
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_extractor_registry.py +19 -1
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/aclue.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/acp_bench.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/acp_bench_hard.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/advanced.py +2 -4
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/aexams.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/afrimmlu.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/afrixnli.py +2 -2
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/arabculture.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/arabic.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/arabic_exams.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/arabic_leaderboard_complete.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/arabic_leaderboard_light.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/arabicmmlu.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/aradice.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/arc.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/arc_challenge.py +1 -2
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/arc_easy.py +1 -2
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/arithmetic.py +2 -2
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/asdiv.py +2 -2
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/babi.py +36 -2
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/basque_bench.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/bbq.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/belebele.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/benchmarks.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/bertaqa.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/bhs.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/bhtc.py +3 -5
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/blimp.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/blimp_nl.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/boolq.py +22 -5
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/c4.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/cabbq.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/careqa.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/catalan_bench.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/catalanqa.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/catcola.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/cb.py +10 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/ceval.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/ceval_valid.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/chain.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/chartqa.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/claim.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/click.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/cmmlu.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/cnn.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/cocoteros.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/coedit.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/commonsense.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/commonsense_qa.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/copa.py +2 -2
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/copal_id.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/coqa.py +3 -4
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/csatqa.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/cycle.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/darija_bench.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/darijahellaswag.py +2 -6
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/darijammlu.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/dbpedia.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/discrim_eval.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/doc.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/drop.py +2 -2
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/epec.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/eq.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/eq_bench.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/eq_bench_ca.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/eq_bench_es.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/esbbq.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/ethics.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/eus.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/eus_exams.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/eus_proficiency.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/eus_reading.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/eus_trivia.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/evalita_llm.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/financial.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/flan.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/french_bench.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/galician_bench.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/gaokao.py +2 -2
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/glianorex.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/global_mmlu.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/global_piqa.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/gpt3.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/groundcocoa.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/haerae.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/headqa.py +2 -2
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/hellaswag.py +2 -2
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/hendrycks_ethics.py +5 -9
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/hendrycks_math.py +63 -16
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/histoires_morales.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/hrm8k.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/humaneval_infilling.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/icelandic_winogrande.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/inverse.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/inverse_scaling.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/ja.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/japanese_leaderboard.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/japanese_leaderboard_mc.py +1 -1
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/kmmlu.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/kobest.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/kormedmcqa.py +5 -17
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/lambada_cloze.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/lambada_multilingual.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/law.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/leaderboard.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/lingoly.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/llama3.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/lm_syneval.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/logiqa.py +2 -2
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/logiqa2.py +2 -2
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/longbench.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/longbenchv2.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/mastermind.py +2 -4
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/mc-taco.py +2 -2
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/med_concepts_qa.py +2 -4
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/meddialog.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/medical.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/medmcqa.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/medqa.py +2 -2
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/mela.py +2 -2
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/metabench.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/minerva_math.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/mmlu.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/mmlusr.py +3 -4
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/mrpc.py +2 -2
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/multiblimp.py +2 -5
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/multirc.py +2 -2
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/mutual.py +2 -2
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/non.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/noreval.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/noreval_exact.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/noreval_gen_exact.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/noreval_mc.py +4 -8
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/noreval_mc_log_likelihoods.py +4 -8
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/nq_open.py +2 -2
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/okapi_arc_multilingual.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/okapi_hellaswag_multilingual.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/okapi_mmlu_multilingual.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/okapi_truthfulqa_multilingual.py +2 -5
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/olaph.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/openbookqa.py +2 -2
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/option.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/parafraseja.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/parafrases.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/paws.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/paws_x.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/pawsx.py +2 -2
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/persona.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/phrases.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/pile.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/piqa.py +2 -2
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/portuguese_bench.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/prompt.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/prost.py +2 -2
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/pubmedqa.py +2 -2
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/qa4mre.py +2 -2
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/qasper.py +2 -2
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/qasper_bool.py +2 -2
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/qnli.py +2 -2
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/qnlieu.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/qqp.py +2 -2
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/race.py +2 -2
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/random.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/record.py +2 -2
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/reversed.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/rte.py +2 -2
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/ruler.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/sciq.py +2 -2
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/score.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/scrolls.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/scrolls_mc.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/self.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/sglue.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/sglue_rte.py +2 -1
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/siqa.py +4 -7
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/social_iqa.py +2 -2
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/spanish_bench.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/storycloze.py +2 -6
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/summarization.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/super.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/super_glue.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/swag.py +2 -2
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/swde.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/sycophancy.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/t0.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/teca.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/tinyarc.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/tinybenchmarks.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/tinygsm8k.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/tinyhellaswag.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/tinymmlu.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/tinytruthfulqa.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/tinywinogrande.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/tmmluplus.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/triviaqa.py +2 -2
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/truthfulqa.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/truthfulqa_mc1.py +9 -4
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/truthfulqa_mc2.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/turblimp_core.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/turkishmmlu.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/turkishmmlu_mc.py +0 -2
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/unscramble.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/vaxx.py +2 -2
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/webqs.py +2 -2
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/wic.py +3 -4
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/winogrande.py +2 -2
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/wmdp.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/wnli.py +2 -2
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/wsc.py +2 -2
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/wsc273.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/xcopa.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/xlsum.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/xnli.py +2 -2
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/xquad.py +2 -4
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/xstorycloze.py +2 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/xwinograd.py +2 -2
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_extractors/zhoblimp.py +1 -3
- wisent/core/contrastive_pairs/lm_eval_pairs/lm_task_pairs_generation.py +173 -6
- wisent/core/data_loaders/loaders/lm_loader.py +12 -1
- wisent/core/geometry_runner.py +995 -0
- wisent/core/geometry_search_space.py +237 -0
- wisent/core/hyperparameter_optimizer.py +1 -1
- wisent/core/main.py +3 -0
- wisent/core/models/core/atoms.py +5 -3
- wisent/core/models/wisent_model.py +1 -1
- wisent/core/optuna/classifier/optuna_classifier_optimizer.py +2 -2
- wisent/core/parser_arguments/check_linearity_parser.py +12 -2
- wisent/core/parser_arguments/generate_vector_from_synthetic_parser.py +2 -2
- wisent/core/parser_arguments/generate_vector_from_task_parser.py +6 -13
- wisent/core/parser_arguments/geometry_search_parser.py +61 -0
- wisent/core/parser_arguments/get_activations_parser.py +5 -14
- wisent/core/parser_arguments/main_parser.py +8 -0
- wisent/core/parser_arguments/train_unified_goodness_parser.py +2 -2
- wisent/core/steering.py +5 -3
- wisent/core/steering_methods/methods/hyperplane.py +2 -1
- wisent/core/synthetic/generators/nonsense_generator.py +30 -18
- wisent/core/trainers/steering_trainer.py +2 -2
- wisent/core/utils/device.py +27 -27
- wisent/core/utils/layer_combinations.py +70 -0
- wisent/examples/__init__.py +1 -0
- wisent/examples/scripts/__init__.py +1 -0
- wisent/examples/scripts/count_all_benchmarks.py +121 -0
- wisent/examples/scripts/discover_directions.py +469 -0
- wisent/examples/scripts/extract_benchmark_info.py +71 -0
- wisent/examples/scripts/search_all_short_names.py +31 -0
- wisent/examples/scripts/test_all_benchmarks.py +138 -0
- wisent/examples/scripts/test_all_benchmarks_new.py +28 -0
- wisent/examples/scripts/test_contrastive_pairs_all_supported.py +230 -0
- wisent/examples/scripts/test_nonsense_baseline.py +261 -0
- wisent/examples/scripts/test_one_benchmark.py +324 -0
- wisent/examples/scripts/test_one_coding_benchmark.py +293 -0
- wisent/parameters/lm_eval/broken_in_lm_eval.json +179 -2
- wisent/parameters/lm_eval/category_directions.json +137 -0
- wisent/parameters/lm_eval/repair_plan.json +282 -0
- wisent/parameters/lm_eval/weak_contrastive_pairs.json +38 -0
- wisent/parameters/lm_eval/working_benchmarks.json +206 -0
- wisent/parameters/lm_eval/working_benchmarks_categorized.json +236 -0
- wisent/tests/test_detector_accuracy.py +1 -1
- wisent/tests/visualize_geometry.py +1 -1
- {wisent-0.7.701.dist-info → wisent-0.7.1045.dist-info}/METADATA +5 -1
- {wisent-0.7.701.dist-info → wisent-0.7.1045.dist-info}/RECORD +328 -358
- wisent/core/contrastive_pairs/huggingface_pairs/hf_task_extractors/browsecomp.py +0 -245
- wisent/examples/contrastive_pairs/humanization_human_vs_ai.json +0 -2112
- wisent/examples/scripts/1/test_basqueglue_evaluation.json +0 -51
- wisent/examples/scripts/1/test_basqueglue_pairs.json +0 -14
- wisent/examples/scripts/1/test_bec2016eu_evaluation.json +0 -51
- wisent/examples/scripts/1/test_bec2016eu_pairs.json +0 -14
- wisent/examples/scripts/1/test_belebele_evaluation.json +0 -51
- wisent/examples/scripts/1/test_belebele_pairs.json +0 -14
- wisent/examples/scripts/1/test_benchmarks_evaluation.json +0 -51
- wisent/examples/scripts/1/test_benchmarks_pairs.json +0 -14
- wisent/examples/scripts/1/test_bertaqa_evaluation.json +0 -51
- wisent/examples/scripts/1/test_bertaqa_pairs.json +0 -14
- wisent/examples/scripts/1/test_bhtc_v2_evaluation.json +0 -30
- wisent/examples/scripts/1/test_bhtc_v2_pairs.json +0 -8
- wisent/examples/scripts/1/test_boolq-seq2seq_evaluation.json +0 -30
- wisent/examples/scripts/1/test_boolq-seq2seq_pairs.json +0 -8
- wisent/examples/scripts/1/test_cabreu_evaluation.json +0 -30
- wisent/examples/scripts/1/test_cabreu_pairs.json +0 -8
- wisent/examples/scripts/1/test_careqa_en_evaluation.json +0 -30
- wisent/examples/scripts/1/test_careqa_en_pairs.json +0 -8
- wisent/examples/scripts/1/test_careqa_evaluation.json +0 -30
- wisent/examples/scripts/1/test_careqa_pairs.json +0 -8
- wisent/examples/scripts/1/test_catalanqa_evaluation.json +0 -30
- wisent/examples/scripts/1/test_catalanqa_pairs.json +0 -8
- wisent/examples/scripts/1/test_catcola_evaluation.json +0 -30
- wisent/examples/scripts/1/test_catcola_pairs.json +0 -8
- wisent/examples/scripts/1/test_chartqa_evaluation.json +0 -30
- wisent/examples/scripts/1/test_chartqa_pairs.json +0 -8
- wisent/examples/scripts/1/test_claim_stance_topic_evaluation.json +0 -30
- wisent/examples/scripts/1/test_claim_stance_topic_pairs.json +0 -8
- wisent/examples/scripts/1/test_cnn_dailymail_evaluation.json +0 -30
- wisent/examples/scripts/1/test_cnn_dailymail_pairs.json +0 -8
- wisent/examples/scripts/1/test_cocoteros_es_evaluation.json +0 -30
- wisent/examples/scripts/1/test_cocoteros_es_pairs.json +0 -8
- wisent/examples/scripts/1/test_coedit_gec_evaluation.json +0 -30
- wisent/examples/scripts/1/test_coedit_gec_pairs.json +0 -8
- wisent/examples/scripts/1/test_cola_evaluation.json +0 -30
- wisent/examples/scripts/1/test_cola_pairs.json +0 -8
- wisent/examples/scripts/1/test_coqcat_evaluation.json +0 -30
- wisent/examples/scripts/1/test_coqcat_pairs.json +0 -8
- wisent/examples/scripts/1/test_dbpedia_14_evaluation.json +0 -30
- wisent/examples/scripts/1/test_dbpedia_14_pairs.json +0 -8
- wisent/examples/scripts/1/test_epec_koref_bin_evaluation.json +0 -30
- wisent/examples/scripts/1/test_epec_koref_bin_pairs.json +0 -8
- wisent/examples/scripts/1/test_ethos_binary_evaluation.json +0 -30
- wisent/examples/scripts/1/test_ethos_binary_pairs.json +0 -8
- wisent/examples/scripts/2/test_afrimgsm_direct_amh_evaluation.json +0 -30
- wisent/examples/scripts/2/test_afrimgsm_direct_amh_pairs.json +0 -8
- wisent/examples/scripts/2/test_afrimmlu_direct_amh_evaluation.json +0 -30
- wisent/examples/scripts/2/test_afrimmlu_direct_amh_pairs.json +0 -8
- wisent/examples/scripts/2/test_afrixnli_en_direct_amh_evaluation.json +0 -30
- wisent/examples/scripts/2/test_afrixnli_en_direct_amh_pairs.json +0 -8
- wisent/examples/scripts/2/test_arc_ar_evaluation.json +0 -30
- wisent/examples/scripts/2/test_arc_ar_pairs.json +0 -8
- wisent/examples/scripts/2/test_atis_evaluation.json +0 -30
- wisent/examples/scripts/2/test_atis_pairs.json +0 -8
- wisent/examples/scripts/2/test_babi_evaluation.json +0 -30
- wisent/examples/scripts/2/test_babi_pairs.json +0 -8
- wisent/examples/scripts/2/test_babilong_evaluation.json +0 -30
- wisent/examples/scripts/2/test_babilong_pairs.json +0 -8
- wisent/examples/scripts/2/test_bangla_mmlu_evaluation.json +0 -30
- wisent/examples/scripts/2/test_bangla_mmlu_pairs.json +0 -8
- wisent/examples/scripts/2/test_basque-glue_pairs.json +0 -14
- {wisent-0.7.701.dist-info → wisent-0.7.1045.dist-info}/WHEEL +0 -0
- {wisent-0.7.701.dist-info → wisent-0.7.1045.dist-info}/entry_points.txt +0 -0
- {wisent-0.7.701.dist-info → wisent-0.7.1045.dist-info}/licenses/LICENSE +0 -0
- {wisent-0.7.701.dist-info → wisent-0.7.1045.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Comparison of steering methods: Ours vs SAE-based.
|
|
3
|
+
|
|
4
|
+
This script:
|
|
5
|
+
1. Creates steering vectors using train split of pooled data
|
|
6
|
+
2. Runs base evaluation on test split (no overlap)
|
|
7
|
+
3. Runs steered evaluation on same test split
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import argparse
|
|
13
|
+
import gc
|
|
14
|
+
import json
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
|
|
17
|
+
import torch
|
|
18
|
+
from lm_eval import evaluator
|
|
19
|
+
from lm_eval.models.hf_steered import SteeredModel
|
|
20
|
+
|
|
21
|
+
from wisent.core.models.wisent_model import WisentModel
|
|
22
|
+
from wisent.comparison import ours
|
|
23
|
+
from wisent.comparison import sae
|
|
24
|
+
from wisent.comparison import fgaa
|
|
25
|
+
from wisent.comparison.utils import (
|
|
26
|
+
load_steering_vector,
|
|
27
|
+
apply_steering_to_model,
|
|
28
|
+
remove_steering,
|
|
29
|
+
convert_to_lm_eval_format,
|
|
30
|
+
create_test_only_task,
|
|
31
|
+
extract_accuracy,
|
|
32
|
+
run_lm_eval_evaluation,
|
|
33
|
+
run_ll_evaluation,
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
# Map method names to modules
|
|
37
|
+
METHOD_MODULES = {
|
|
38
|
+
"caa": ours,
|
|
39
|
+
"sae": sae,
|
|
40
|
+
"fgaa": fgaa,
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def run_single_task(
|
|
45
|
+
model_name: str,
|
|
46
|
+
task: str,
|
|
47
|
+
methods: list[str] = None,
|
|
48
|
+
num_pairs: int = 50,
|
|
49
|
+
steering_scales: list[float] = None,
|
|
50
|
+
device: str = "cuda:0",
|
|
51
|
+
batch_size: int | str = 1,
|
|
52
|
+
max_batch_size: int = 8,
|
|
53
|
+
eval_limit: int | None = None,
|
|
54
|
+
vectors_dir: Path = None,
|
|
55
|
+
train_ratio: float = 0.8,
|
|
56
|
+
caa_layers: str = "12",
|
|
57
|
+
sae_layers: str = "12",
|
|
58
|
+
extraction_strategies: list[str] = None,
|
|
59
|
+
bos_features_source: str = "detected",
|
|
60
|
+
) -> list[dict]:
|
|
61
|
+
"""
|
|
62
|
+
Run comparison for a single task with multiple methods, scales, and extraction strategies.
|
|
63
|
+
|
|
64
|
+
Returns list of result dicts, one per method/scale/strategy combination.
|
|
65
|
+
"""
|
|
66
|
+
if methods is None:
|
|
67
|
+
methods = ["caa"]
|
|
68
|
+
if steering_scales is None:
|
|
69
|
+
steering_scales = [1.0]
|
|
70
|
+
if extraction_strategies is None:
|
|
71
|
+
extraction_strategies = ["mc_balanced"]
|
|
72
|
+
|
|
73
|
+
results_list = []
|
|
74
|
+
|
|
75
|
+
# Step 1: Create test task
|
|
76
|
+
test_pct = round((1 - train_ratio) * 100)
|
|
77
|
+
print(f"\n{'='*60}")
|
|
78
|
+
print(f"Creating test task for: {task}")
|
|
79
|
+
print(f"(using {test_pct}% of pooled data)")
|
|
80
|
+
print(f"{'='*60}")
|
|
81
|
+
|
|
82
|
+
task_dict = create_test_only_task(task, train_ratio=train_ratio)
|
|
83
|
+
|
|
84
|
+
# Step 2: Generate ALL steering vectors FIRST for ALL strategies (subprocess frees GPU memory after each)
|
|
85
|
+
# Structure: steering_vectors_data[strategy][method] = steering_data
|
|
86
|
+
steering_vectors_data = {}
|
|
87
|
+
train_pct = round(train_ratio * 100)
|
|
88
|
+
|
|
89
|
+
for method in methods:
|
|
90
|
+
if method not in METHOD_MODULES:
|
|
91
|
+
print(f"WARNING: Method '{method}' not implemented, skipping")
|
|
92
|
+
continue
|
|
93
|
+
|
|
94
|
+
method_module = METHOD_MODULES[method]
|
|
95
|
+
|
|
96
|
+
# CAA uses extraction strategy, FGAA/SAE don't
|
|
97
|
+
for extraction_strategy in (extraction_strategies if method == "caa" else [None]):
|
|
98
|
+
print(f"\n{'@'*60}")
|
|
99
|
+
print(f"@ METHOD: {method}, EXTRACTION STRATEGY: {extraction_strategy or 'N/A'}")
|
|
100
|
+
print(f"{'@'*60}")
|
|
101
|
+
|
|
102
|
+
# Select layers based on method: CAA uses caa_layers (default=middle), SAE/FGAA use sae_layers (default=12)
|
|
103
|
+
method_layers = caa_layers if method == "caa" else sae_layers
|
|
104
|
+
|
|
105
|
+
print(f"\n{'='*60}")
|
|
106
|
+
print(f"Generating steering vector for: {task} (method={method})")
|
|
107
|
+
print(f"(using {train_pct}% of pooled data - no overlap with test)")
|
|
108
|
+
print(f"Layers: {method_layers}")
|
|
109
|
+
print(f"{'='*60}")
|
|
110
|
+
|
|
111
|
+
suffix = f"_{extraction_strategy}" if extraction_strategy else ""
|
|
112
|
+
vector_path = vectors_dir / f"{task}_{method}{suffix}_steering_vector.json"
|
|
113
|
+
|
|
114
|
+
kwargs = {
|
|
115
|
+
"task": task,
|
|
116
|
+
"model_name": model_name,
|
|
117
|
+
"output_path": vector_path,
|
|
118
|
+
"num_pairs": num_pairs,
|
|
119
|
+
"device": device,
|
|
120
|
+
"layers": method_layers,
|
|
121
|
+
}
|
|
122
|
+
if extraction_strategy:
|
|
123
|
+
kwargs["extraction_strategy"] = extraction_strategy
|
|
124
|
+
if method == "fgaa":
|
|
125
|
+
kwargs["bos_features_source"] = bos_features_source
|
|
126
|
+
|
|
127
|
+
method_module.generate_steering_vector(**kwargs)
|
|
128
|
+
|
|
129
|
+
steering_data = load_steering_vector(vector_path, default_method=method)
|
|
130
|
+
if extraction_strategy not in steering_vectors_data:
|
|
131
|
+
steering_vectors_data[extraction_strategy] = {}
|
|
132
|
+
steering_vectors_data[extraction_strategy][method] = steering_data
|
|
133
|
+
print(f"Loaded steering vector with layers: {steering_data['layers']}")
|
|
134
|
+
|
|
135
|
+
# Step 3: Load model once for ALL evaluations
|
|
136
|
+
print(f"\n{'='*60}")
|
|
137
|
+
print(f"Loading model: {model_name}")
|
|
138
|
+
print(f"{'='*60}")
|
|
139
|
+
wisent_model = WisentModel(model_name=model_name, device=device)
|
|
140
|
+
|
|
141
|
+
# Step 4: Run base evaluation (no steering applied)
|
|
142
|
+
print(f"\n{'='*60}")
|
|
143
|
+
print(f"Running BASE evaluation for: {task}")
|
|
144
|
+
print(f"{'='*60}")
|
|
145
|
+
|
|
146
|
+
base_results = run_lm_eval_evaluation(
|
|
147
|
+
wisent_model=wisent_model,
|
|
148
|
+
task_dict=task_dict,
|
|
149
|
+
task_name=task,
|
|
150
|
+
batch_size=batch_size,
|
|
151
|
+
max_batch_size=max_batch_size,
|
|
152
|
+
limit=eval_limit,
|
|
153
|
+
)
|
|
154
|
+
base_acc = extract_accuracy(base_results, task)
|
|
155
|
+
print(f"Base accuracy (lm-eval): {base_acc:.4f}")
|
|
156
|
+
|
|
157
|
+
# Step 4b: Run base LL evaluation (no steering)
|
|
158
|
+
print(f"\n{'='*60}")
|
|
159
|
+
print(f"Running BASE LL evaluation for: {task}")
|
|
160
|
+
print(f"{'='*60}")
|
|
161
|
+
|
|
162
|
+
base_ll_acc = run_ll_evaluation(
|
|
163
|
+
wisent_model=wisent_model,
|
|
164
|
+
task_dict=task_dict,
|
|
165
|
+
task_name=task,
|
|
166
|
+
limit=eval_limit,
|
|
167
|
+
)
|
|
168
|
+
print(f"Base accuracy (LL): {base_ll_acc:.4f}")
|
|
169
|
+
|
|
170
|
+
# Step 5: Run ALL wisent steered evaluations first (model stays loaded)
|
|
171
|
+
# Structure: wisent_results[(strategy, method, scale)] = steered_acc
|
|
172
|
+
wisent_results = {}
|
|
173
|
+
for method in methods:
|
|
174
|
+
# CAA uses extraction strategy, FGAA/SAE don't
|
|
175
|
+
for extraction_strategy in (extraction_strategies if method == "caa" else [None]):
|
|
176
|
+
if extraction_strategy not in steering_vectors_data:
|
|
177
|
+
continue
|
|
178
|
+
if method not in steering_vectors_data[extraction_strategy]:
|
|
179
|
+
continue
|
|
180
|
+
|
|
181
|
+
steering_data = steering_vectors_data[extraction_strategy][method]
|
|
182
|
+
|
|
183
|
+
for scale in steering_scales:
|
|
184
|
+
print(f"\n{'='*60}")
|
|
185
|
+
print(f"Running STEERED evaluation for: {task} (strategy={extraction_strategy}, method={method}, scale={scale})")
|
|
186
|
+
print(f"{'='*60}")
|
|
187
|
+
|
|
188
|
+
# Apply steering to existing model
|
|
189
|
+
apply_steering_to_model(wisent_model, steering_data, scale=scale)
|
|
190
|
+
|
|
191
|
+
steered_results = run_lm_eval_evaluation(
|
|
192
|
+
wisent_model=wisent_model,
|
|
193
|
+
task_dict=task_dict,
|
|
194
|
+
task_name=task,
|
|
195
|
+
batch_size=batch_size,
|
|
196
|
+
max_batch_size=max_batch_size,
|
|
197
|
+
limit=eval_limit,
|
|
198
|
+
)
|
|
199
|
+
steered_acc = extract_accuracy(steered_results, task)
|
|
200
|
+
print(f"Steered accuracy (lm-eval): {steered_acc:.4f}")
|
|
201
|
+
|
|
202
|
+
# Run steered LL evaluation
|
|
203
|
+
steered_ll_acc = run_ll_evaluation(
|
|
204
|
+
wisent_model=wisent_model,
|
|
205
|
+
task_dict=task_dict,
|
|
206
|
+
task_name=task,
|
|
207
|
+
limit=eval_limit,
|
|
208
|
+
)
|
|
209
|
+
print(f"Steered accuracy (LL): {steered_ll_acc:.4f}")
|
|
210
|
+
|
|
211
|
+
# Remove steering for next iteration
|
|
212
|
+
remove_steering(wisent_model)
|
|
213
|
+
|
|
214
|
+
# Store wisent results
|
|
215
|
+
wisent_results[(extraction_strategy, method, scale)] = {
|
|
216
|
+
"lm_eval": steered_acc,
|
|
217
|
+
"ll": steered_ll_acc,
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
# Step 6: Free wisent_model to make room for SteeredModel
|
|
221
|
+
del wisent_model
|
|
222
|
+
gc.collect()
|
|
223
|
+
if torch.cuda.is_available():
|
|
224
|
+
torch.cuda.empty_cache()
|
|
225
|
+
torch.cuda.synchronize()
|
|
226
|
+
|
|
227
|
+
# Step 7: Run ALL lm-eval native steered evaluations (one at a time)
|
|
228
|
+
for method in methods:
|
|
229
|
+
# CAA uses extraction strategy, FGAA/SAE don't
|
|
230
|
+
for extraction_strategy in (extraction_strategies if method == "caa" else [None]):
|
|
231
|
+
if extraction_strategy not in steering_vectors_data:
|
|
232
|
+
continue
|
|
233
|
+
if method not in steering_vectors_data[extraction_strategy]:
|
|
234
|
+
continue
|
|
235
|
+
|
|
236
|
+
steering_data = steering_vectors_data[extraction_strategy][method]
|
|
237
|
+
|
|
238
|
+
for scale in steering_scales:
|
|
239
|
+
print(f"\n{'='*60}")
|
|
240
|
+
print(f"Running lm-eval NATIVE steered for: {task} (strategy={extraction_strategy}, method={method}, scale={scale})")
|
|
241
|
+
print(f"{'='*60}")
|
|
242
|
+
|
|
243
|
+
# Convert steering vector to lm-eval format
|
|
244
|
+
suffix = f"_{extraction_strategy}" if extraction_strategy else ""
|
|
245
|
+
lm_eval_steer_path = vectors_dir / f"{task}_{method}{suffix}_lm_eval_steer_scale{scale}.pt"
|
|
246
|
+
convert_to_lm_eval_format(steering_data, lm_eval_steer_path, scale=scale)
|
|
247
|
+
|
|
248
|
+
lm_steered = SteeredModel(
|
|
249
|
+
pretrained=model_name,
|
|
250
|
+
steer_path=str(lm_eval_steer_path),
|
|
251
|
+
device=device,
|
|
252
|
+
batch_size=batch_size,
|
|
253
|
+
max_batch_size=max_batch_size,
|
|
254
|
+
)
|
|
255
|
+
|
|
256
|
+
lm_eval_native_results = evaluator.evaluate(
|
|
257
|
+
lm=lm_steered,
|
|
258
|
+
task_dict=task_dict,
|
|
259
|
+
limit=eval_limit,
|
|
260
|
+
)
|
|
261
|
+
lm_eval_native_acc = extract_accuracy(lm_eval_native_results, task)
|
|
262
|
+
print(f"lm-eval native steered accuracy: {lm_eval_native_acc:.4f}")
|
|
263
|
+
|
|
264
|
+
# Clean up SteeredModel to free GPU for next iteration
|
|
265
|
+
del lm_steered
|
|
266
|
+
gc.collect()
|
|
267
|
+
if torch.cuda.is_available():
|
|
268
|
+
torch.cuda.empty_cache()
|
|
269
|
+
torch.cuda.synchronize()
|
|
270
|
+
|
|
271
|
+
# Store combined results
|
|
272
|
+
wisent_result = wisent_results[(extraction_strategy, method, scale)]
|
|
273
|
+
steered_acc_lm_eval = wisent_result["lm_eval"]
|
|
274
|
+
steered_acc_ll = wisent_result["ll"]
|
|
275
|
+
results_list.append({
|
|
276
|
+
"task": task,
|
|
277
|
+
"extraction_strategy": extraction_strategy or "N/A",
|
|
278
|
+
"method": method,
|
|
279
|
+
"model": model_name,
|
|
280
|
+
"layers": steering_data['layers'],
|
|
281
|
+
"num_pairs": num_pairs,
|
|
282
|
+
"steering_scale": scale,
|
|
283
|
+
"base_accuracy_lm_eval": base_acc,
|
|
284
|
+
"base_accuracy_ll": base_ll_acc,
|
|
285
|
+
"steered_accuracy_lm_eval": steered_acc_lm_eval,
|
|
286
|
+
"steered_accuracy_ll": steered_acc_ll,
|
|
287
|
+
"steered_accuracy_lm_eval_native": lm_eval_native_acc,
|
|
288
|
+
"difference_lm_eval": steered_acc_lm_eval - base_acc,
|
|
289
|
+
"difference_ll": steered_acc_ll - base_ll_acc,
|
|
290
|
+
"difference_lm_eval_native": lm_eval_native_acc - base_acc,
|
|
291
|
+
})
|
|
292
|
+
|
|
293
|
+
return results_list
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
def run_comparison(
|
|
297
|
+
model_name: str,
|
|
298
|
+
tasks: list[str],
|
|
299
|
+
methods: list[str] = None,
|
|
300
|
+
num_pairs: int = 50,
|
|
301
|
+
steering_scales: list[float] = None,
|
|
302
|
+
device: str = "cuda:0",
|
|
303
|
+
batch_size: int | str = 1,
|
|
304
|
+
max_batch_size: int = 8,
|
|
305
|
+
eval_limit: int | None = None,
|
|
306
|
+
output_dir: str = "comparison_results",
|
|
307
|
+
train_ratio: float = 0.8,
|
|
308
|
+
caa_layers: str = "12",
|
|
309
|
+
sae_layers: str = "12",
|
|
310
|
+
extraction_strategies: list[str] = None,
|
|
311
|
+
bos_features_source: str = "detected",
|
|
312
|
+
) -> list[dict]:
|
|
313
|
+
"""
|
|
314
|
+
Run full comparison for multiple tasks, methods, scales, and extraction strategies.
|
|
315
|
+
"""
|
|
316
|
+
if methods is None:
|
|
317
|
+
methods = ["caa"]
|
|
318
|
+
if steering_scales is None:
|
|
319
|
+
steering_scales = [1.0]
|
|
320
|
+
if extraction_strategies is None:
|
|
321
|
+
extraction_strategies = ["mc_balanced"]
|
|
322
|
+
|
|
323
|
+
output_dir = Path(output_dir)
|
|
324
|
+
# Add model name to path (sanitize "/" -> "_")
|
|
325
|
+
model_dir_name = model_name.replace("/", "_")
|
|
326
|
+
output_dir = output_dir / model_dir_name
|
|
327
|
+
vectors_dir = output_dir / "steering_vectors"
|
|
328
|
+
results_dir = output_dir / "results"
|
|
329
|
+
|
|
330
|
+
output_dir.mkdir(parents=True, exist_ok=True)
|
|
331
|
+
vectors_dir.mkdir(parents=True, exist_ok=True)
|
|
332
|
+
results_dir.mkdir(parents=True, exist_ok=True)
|
|
333
|
+
|
|
334
|
+
all_results = []
|
|
335
|
+
|
|
336
|
+
for task in tasks:
|
|
337
|
+
print(f"\n{'#'*60}")
|
|
338
|
+
print(f"# TASK: {task}")
|
|
339
|
+
print(f"{'#'*60}")
|
|
340
|
+
|
|
341
|
+
task_results = run_single_task(
|
|
342
|
+
model_name=model_name,
|
|
343
|
+
task=task,
|
|
344
|
+
methods=methods,
|
|
345
|
+
num_pairs=num_pairs,
|
|
346
|
+
steering_scales=steering_scales,
|
|
347
|
+
device=device,
|
|
348
|
+
batch_size=batch_size,
|
|
349
|
+
max_batch_size=max_batch_size,
|
|
350
|
+
eval_limit=eval_limit,
|
|
351
|
+
vectors_dir=vectors_dir,
|
|
352
|
+
train_ratio=train_ratio,
|
|
353
|
+
caa_layers=caa_layers,
|
|
354
|
+
sae_layers=sae_layers,
|
|
355
|
+
extraction_strategies=extraction_strategies,
|
|
356
|
+
bos_features_source=bos_features_source,
|
|
357
|
+
)
|
|
358
|
+
all_results.extend(task_results)
|
|
359
|
+
|
|
360
|
+
# Save results for this task (includes all strategies)
|
|
361
|
+
task_results_file = results_dir / f"{task}_results.json"
|
|
362
|
+
with open(task_results_file, "w") as f:
|
|
363
|
+
json.dump(task_results, f, indent=2)
|
|
364
|
+
print(f"Results for {task} saved to: {task_results_file}")
|
|
365
|
+
|
|
366
|
+
# Print final summary table
|
|
367
|
+
print(f"\n{'='*150}")
|
|
368
|
+
print(f"FINAL COMPARISON RESULTS")
|
|
369
|
+
print(f"{'='*150}")
|
|
370
|
+
print(f"Model: {model_name}")
|
|
371
|
+
print(f"Num pairs: {num_pairs}")
|
|
372
|
+
print(f"CAA Layers: {caa_layers}")
|
|
373
|
+
print(f"SAE/FGAA Layers: {sae_layers}")
|
|
374
|
+
print(f"Strategies: {', '.join(extraction_strategies)}")
|
|
375
|
+
print(f"{'='*150}")
|
|
376
|
+
print(f"{'Strategy':<16} {'Task':<10} {'Method':<8} {'Scale':<6} {'Base(E)':<8} {'Base(L)':<8} {'Steer(E)':<9} {'Steer(L)':<9} {'Native':<8} {'Diff(E)':<8} {'Diff(L)':<8} {'Diff(N)':<8}")
|
|
377
|
+
print(f"{'-'*150}")
|
|
378
|
+
|
|
379
|
+
for r in all_results:
|
|
380
|
+
print(f"{r.get('extraction_strategy', 'N/A'):<16} {r['task']:<10} {r['method']:<8} {r['steering_scale']:<6.1f} "
|
|
381
|
+
f"{r['base_accuracy_lm_eval']:<8.4f} {r['base_accuracy_ll']:<8.4f} "
|
|
382
|
+
f"{r['steered_accuracy_lm_eval']:<9.4f} {r['steered_accuracy_ll']:<9.4f} {r['steered_accuracy_lm_eval_native']:<8.4f} "
|
|
383
|
+
f"{r['difference_lm_eval']:+<8.4f} {r['difference_ll']:+<8.4f} {r['difference_lm_eval_native']:+<8.4f}")
|
|
384
|
+
|
|
385
|
+
print(f"{'='*150}")
|
|
386
|
+
|
|
387
|
+
print(f"\nSteering vectors saved to: {vectors_dir}")
|
|
388
|
+
print(f"Results saved to: {results_dir}")
|
|
389
|
+
|
|
390
|
+
return all_results
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
def main():
|
|
394
|
+
parser = argparse.ArgumentParser(description="Compare steering methods")
|
|
395
|
+
parser.add_argument("--model", default="EleutherAI/gpt-neo-125M", help="Model name")
|
|
396
|
+
parser.add_argument("--tasks", default="boolq", help="Comma-separated lm-eval tasks (e.g., boolq,cb,copa)")
|
|
397
|
+
parser.add_argument("--methods", default="caa", help="Comma-separated methods (e.g., caa,sae,fgaa)")
|
|
398
|
+
parser.add_argument("--num-pairs", type=int, default=50, help="Number of contrastive pairs")
|
|
399
|
+
parser.add_argument("--scales", default="1.0", help="Comma-separated steering scales (e.g., 0.5,1.0,1.5)")
|
|
400
|
+
parser.add_argument("--caa-layers", default="12", help="Layer(s) for CAA steering (default: 12)")
|
|
401
|
+
parser.add_argument("--sae-layers", default="12", help="Layer(s) for SAE/FGAA steering (default: 12)")
|
|
402
|
+
parser.add_argument("--device", default="cuda:0", help="Device")
|
|
403
|
+
parser.add_argument("--batch-size", default=1, help="Batch size (int or 'auto')")
|
|
404
|
+
parser.add_argument("--max-batch-size", type=int, default=8, help="Max batch size for lm-eval internal batching (reduce if OOM)")
|
|
405
|
+
parser.add_argument("--limit", type=int, default=None, help="Limit eval examples")
|
|
406
|
+
parser.add_argument("--output-dir", default="wisent/comparison/comparison_results", help="Output directory")
|
|
407
|
+
parser.add_argument("--train-ratio", type=float, default=0.8, help="Train/test split ratio (default 0.8 = 80%% train, 20%% test)")
|
|
408
|
+
parser.add_argument("--extraction-strategy", default="mc_balanced",
|
|
409
|
+
help="Extraction strategy (comma-separated for multiple). Chat models: chat_mean, chat_first, chat_last, chat_max_norm, chat_weighted, role_play, mc_balanced. Base models: completion_last, completion_mean, mc_completion")
|
|
410
|
+
parser.add_argument("--bos-features-source", default="detected",
|
|
411
|
+
help="BOS features source for FGAA: 'paper' (5 features), 'detected' (12 features), or 'none'")
|
|
412
|
+
|
|
413
|
+
args = parser.parse_args()
|
|
414
|
+
|
|
415
|
+
# Parse comma-separated values
|
|
416
|
+
tasks = [t.strip() for t in args.tasks.split(",")]
|
|
417
|
+
methods = [m.strip() for m in args.methods.split(",")]
|
|
418
|
+
scales = [float(s.strip()) for s in args.scales.split(",")]
|
|
419
|
+
extraction_strategies = [s.strip() for s in args.extraction_strategy.split(",")]
|
|
420
|
+
|
|
421
|
+
# Parse batch_size (can be int or "auto")
|
|
422
|
+
batch_size = args.batch_size if args.batch_size == "auto" else int(args.batch_size)
|
|
423
|
+
|
|
424
|
+
run_comparison(
|
|
425
|
+
model_name=args.model,
|
|
426
|
+
tasks=tasks,
|
|
427
|
+
methods=methods,
|
|
428
|
+
num_pairs=args.num_pairs,
|
|
429
|
+
steering_scales=scales,
|
|
430
|
+
device=args.device,
|
|
431
|
+
batch_size=batch_size,
|
|
432
|
+
max_batch_size=args.max_batch_size,
|
|
433
|
+
eval_limit=args.limit,
|
|
434
|
+
output_dir=args.output_dir,
|
|
435
|
+
train_ratio=args.train_ratio,
|
|
436
|
+
caa_layers=args.caa_layers,
|
|
437
|
+
sae_layers=args.sae_layers,
|
|
438
|
+
extraction_strategies=extraction_strategies,
|
|
439
|
+
bos_features_source=args.bos_features_source,
|
|
440
|
+
)
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
if __name__ == "__main__":
|
|
444
|
+
main()
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Our steering method wrapper for comparison experiments.
|
|
3
|
+
|
|
4
|
+
Uses the existing wisent infrastructure to create steering vectors.
|
|
5
|
+
Runs steering vector generation in subprocess to guarantee memory cleanup.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import json
|
|
11
|
+
import subprocess
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
from typing import TYPE_CHECKING
|
|
14
|
+
|
|
15
|
+
import torch
|
|
16
|
+
|
|
17
|
+
from wisent.comparison.utils import apply_steering_to_model, remove_steering, convert_to_lm_eval_format
|
|
18
|
+
|
|
19
|
+
if TYPE_CHECKING:
|
|
20
|
+
from wisent.core.models.wisent_model import WisentModel
|
|
21
|
+
|
|
22
|
+
__all__ = ["generate_steering_vector", "apply_steering_to_model", "remove_steering", "convert_to_lm_eval_format"]
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def generate_steering_vector(
|
|
26
|
+
task: str,
|
|
27
|
+
model_name: str,
|
|
28
|
+
output_path: str | Path,
|
|
29
|
+
trait_label: str = "correctness",
|
|
30
|
+
num_pairs: int = 50,
|
|
31
|
+
method: str = "caa",
|
|
32
|
+
layers: str | None = None,
|
|
33
|
+
normalize: bool = True,
|
|
34
|
+
device: str = "cuda:0",
|
|
35
|
+
keep_intermediate: bool = False,
|
|
36
|
+
extraction_strategy: str = "mc_balanced",
|
|
37
|
+
) -> Path:
|
|
38
|
+
"""
|
|
39
|
+
Generate a steering vector using wisent CLI in subprocess.
|
|
40
|
+
|
|
41
|
+
Runs in subprocess to guarantee GPU memory is freed when done.
|
|
42
|
+
"""
|
|
43
|
+
output_path = Path(output_path)
|
|
44
|
+
|
|
45
|
+
cmd = [
|
|
46
|
+
"wisent", "generate-vector-from-task",
|
|
47
|
+
"--task", task,
|
|
48
|
+
"--trait-label", trait_label,
|
|
49
|
+
"--model", model_name,
|
|
50
|
+
"--num-pairs", str(num_pairs),
|
|
51
|
+
"--method", method,
|
|
52
|
+
"--output", str(output_path),
|
|
53
|
+
"--device", device,
|
|
54
|
+
"--extraction-strategy", extraction_strategy,
|
|
55
|
+
"--accept-low-quality-vector",
|
|
56
|
+
]
|
|
57
|
+
|
|
58
|
+
if layers:
|
|
59
|
+
cmd.extend(["--layers", layers])
|
|
60
|
+
|
|
61
|
+
if normalize:
|
|
62
|
+
cmd.append("--normalize")
|
|
63
|
+
|
|
64
|
+
if keep_intermediate:
|
|
65
|
+
cmd.append("--keep-intermediate")
|
|
66
|
+
|
|
67
|
+
result = subprocess.run(cmd)
|
|
68
|
+
|
|
69
|
+
if result.returncode != 0:
|
|
70
|
+
raise RuntimeError(f"Failed to generate steering vector (exit code {result.returncode})")
|
|
71
|
+
|
|
72
|
+
return output_path
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|