{"about":{"site":"https://codewithpapers.app","non_affiliation":"Code with Papers and Syntology are not affiliated with, endorsed by, or sponsored by Papers with Code, Meta, or the pwc-archive mirror.","licence":"CC BY-SA 4.0","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","attribution":"https://codewithpapers.app/attribution","modified":"archive material modified by Syntology; see the attribution page"},"url":"/paper/a-mechanistic-understanding-of-alignment","title":"A Mechanistic Understanding of Alignment Algorithms: A Case Study on DPO and Toxicity","arxiv_id":"2401.01967","date":"2024-01-03","proceeding":null,"authors":["Andrew Lee","Xiaoyan Bai","Itamar Pres","Martin Wattenberg","Jonathan K. Kummerfeld","Rada Mihalcea"],"abstract":"While alignment algorithms are now commonly used to tune pre-trained language models towards a user's preferences, we lack explanations for the underlying mechanisms in which models become ``aligned'', thus making it difficult to explain phenomena like jailbreaks. In this work we study a popular algorithm, direct preference optimization (DPO), and the mechanisms by which it reduces toxicity. Namely, we first study how toxicity is represented and elicited in a pre-trained language model, GPT2-medium. We then apply DPO with a carefully crafted pairwise dataset to reduce toxicity. We examine how the resulting model averts toxic outputs, and find that capabilities learned from pre-training are not removed, but rather bypassed. We use this insight to demonstrate a simple method to un-align the model, reverting it back to its toxic behavior.","url_abs":"https://arxiv.org/abs/2401.01967v1","url_pdf":"https://arxiv.org/pdf/2401.01967v1.pdf","source":{"archive":"pwc-archive (Hugging Face), CC BY-SA 4.0","snapshot":"2025-07-28","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","row_kind":"abstracts"},"code_links":[{"paper_slug":"a-mechanistic-understanding-of-alignment","repo_url":"https://github.com/ajyl/dpo_toxic","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"MIT"}},{"paper_slug":"a-mechanistic-understanding-of-alignment","repo_url":"https://github.com/yushi-y/dpo-toxic-neurons","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"MIT"}}],"tasks":[{"task_slug":"language-modeling","task_name":"Language Modeling"},{"task_slug":"language-modelling","task_name":"Language Modelling"}],"methods":[{"method_slug":"dpo","method_name":"DPO"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2401.01967","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2401.01967"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-24T18:15:14+00:00","read_at_is":"when the build read Syntology's graph, not when any sample ran","claim":"Per-sample execution status on synthesized fixtures; not a correctness claim about the paper. Samples come from repositories linked to the paper, official or community; repo_kind says which.","repos":[{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/ajyl/dpo_toxic","reach":{"status":"ok","spdx":"MIT"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/yushi-y/dpo-toxic-neurons","reach":{"status":"ok","spdx":"MIT"}}],"summary":{"ran":3,"unverified":11},"by_repo_kind":{"official":{"samples":14,"ran":3,"repositories":1}},"repo_kind_vocabulary":{"official":"The archive marks this repository official for the paper","named_in_paper":"The archive records that the paper mentions this repository; it is not marked official","listed":"In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper","found_in_text":"Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted","community":"Not in the archive's code links for this paper; a community repository Syntology harvested"},"n_pointer_only_for_licence":0,"samples":[{"code_sha256_prefix":"2eb9d77d720c2173","entry":"get_intervene_vector","repo":"ajyl/dpo_toxic","repo_kind":"official","path":"toxicity/eval_interventions/hook_utils.py","file_url":"https://github.com/ajyl/dpo_toxic/blob/HEAD/toxicity/eval_interventions/hook_utils.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"2eb9d77d720c2173"}},{"code_sha256_prefix":"9e84c0d9c78a5cad","entry":"get_kl_div","repo":"ajyl/dpo_toxic","repo_kind":"official","path":"toxicity/train_dpo/trainers.py","file_url":"https://github.com/ajyl/dpo_toxic/blob/HEAD/toxicity/train_dpo/trainers.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"9e84c0d9c78a5cad"}},{"code_sha256_prefix":"9727f348a587c477","entry":"tokenize","repo":"ajyl/dpo_toxic","repo_kind":"official","path":"toxicity/eval_interventions/eval_utils.py","file_url":"https://github.com/ajyl/dpo_toxic/blob/HEAD/toxicity/eval_interventions/eval_utils.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"9727f348a587c477"}},{"code_sha256_prefix":"6e420696373414b1","entry":"dpo_loss","repo":"ajyl/dpo_toxic","repo_kind":"official","path":"toxicity/train_dpo/trainers.py","file_url":"https://github.com/ajyl/dpo_toxic/blob/HEAD/toxicity/train_dpo/trainers.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"6e420696373414b1"}},{"code_sha256_prefix":"813d811b5f586d21","entry":"get_gold","repo":"ajyl/dpo_toxic","repo_kind":"official","path":"toxicity/eval_interventions/generate_funcs.py","file_url":"https://github.com/ajyl/dpo_toxic/blob/HEAD/toxicity/eval_interventions/generate_funcs.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"813d811b5f586d21"}},{"code_sha256_prefix":"8ab43db002bf984d","entry":"get_local_dir","repo":"ajyl/dpo_toxic","repo_kind":"official","path":"toxicity/train_dpo/dpo_utils.py","file_url":"https://github.com/ajyl/dpo_toxic/blob/HEAD/toxicity/train_dpo/dpo_utils.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"8ab43db002bf984d"}},{"code_sha256_prefix":"1df5ede8f8950a70","entry":"get_local_run_dir","repo":"ajyl/dpo_toxic","repo_kind":"official","path":"toxicity/train_dpo/dpo_utils.py","file_url":"https://github.com/ajyl/dpo_toxic/blob/HEAD/toxicity/train_dpo/dpo_utils.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"1df5ede8f8950a70"}},{"code_sha256_prefix":"d635938df605fbd3","entry":"get_prompts","repo":"ajyl/dpo_toxic","repo_kind":"official","path":"toxicity/eval_interventions/generate_funcs.py","file_url":"https://github.com/ajyl/dpo_toxic/blob/HEAD/toxicity/eval_interventions/generate_funcs.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"d635938df605fbd3"}},{"code_sha256_prefix":"e7ce4c19888c6df6","entry":"get_remote_file","repo":"ajyl/dpo_toxic","repo_kind":"official","path":"toxicity/train_dpo/dpo_utils.py","file_url":"https://github.com/ajyl/dpo_toxic/blob/HEAD/toxicity/train_dpo/dpo_utils.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"e7ce4c19888c6df6"}},{"code_sha256_prefix":"0e4cc3ba12263f9d","entry":"get_svd_u_vec","repo":"ajyl/dpo_toxic","repo_kind":"official","path":"toxicity/eval_interventions/hook_utils.py","file_url":"https://github.com/ajyl/dpo_toxic/blob/HEAD/toxicity/eval_interventions/hook_utils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"0e4cc3ba12263f9d"}},{"code_sha256_prefix":"cba91edd374a3e28","entry":"load_data","repo":"ajyl/dpo_toxic","repo_kind":"official","path":"toxicity/eval_interventions/eval_utils.py","file_url":"https://github.com/ajyl/dpo_toxic/blob/HEAD/toxicity/eval_interventions/eval_utils.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"cba91edd374a3e28"}},{"code_sha256_prefix":"43d32c9d46ad3c9a","entry":"rank_value_vecs","repo":"ajyl/dpo_toxic","repo_kind":"official","path":"toxicity/eval_interventions/hook_utils.py","file_url":"https://github.com/ajyl/dpo_toxic/blob/HEAD/toxicity/eval_interventions/hook_utils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"43d32c9d46ad3c9a"}},{"code_sha256_prefix":"f5813daae4f9b8f5","entry":"run_dummy","repo":"ajyl/dpo_toxic","repo_kind":"official","path":"toxicity/eval_interventions/metric_funcs.py","file_url":"https://github.com/ajyl/dpo_toxic/blob/HEAD/toxicity/eval_interventions/metric_funcs.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"f5813daae4f9b8f5"}},{"code_sha256_prefix":"044b24804e21d67d","entry":"run_f1","repo":"ajyl/dpo_toxic","repo_kind":"official","path":"toxicity/eval_interventions/metric_funcs.py","file_url":"https://github.com/ajyl/dpo_toxic/blob/HEAD/toxicity/eval_interventions/metric_funcs.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"044b24804e21d67d"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}