{"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/eraseanything-enabling-concept-erasure-in","title":"EraseAnything: Enabling Concept Erasure in Rectified Flow Transformers","arxiv_id":"2412.20413","date":"2024-12-29","proceeding":null,"authors":["Daiheng Gao","Shilin Lu","Shaw Walters","Wenbo Zhou","Jiaming Chu","Jie Zhang","Bang Zhang","Mengxi Jia","Jian Zhao","Zhaoxin Fan","Weiming Zhang"],"abstract":"Removing unwanted concepts from large-scale text-to-image (T2I) diffusion models while maintaining their overall generative quality remains an open challenge. This difficulty is especially pronounced in emerging paradigms, such as Stable Diffusion (SD) v3 and Flux, which incorporate flow matching and transformer-based architectures. These advancements limit the transferability of existing concept-erasure techniques that were originally designed for the previous T2I paradigm (e.g., SD v1.4). In this work, we introduce EraseAnything, the first method specifically developed to address concept erasure within the latest flow-based T2I framework. We formulate concept erasure as a bi-level optimization problem, employing LoRA-based parameter tuning and an attention map regularizer to selectively suppress undesirable activations. Furthermore, we propose a self-contrastive learning strategy to ensure that removing unwanted concepts does not inadvertently harm performance on unrelated ones. Experimental results demonstrate that EraseAnything successfully fills the research gap left by earlier methods in this new T2I paradigm, achieving state-of-the-art performance across a wide range of concept erasure tasks.","url_abs":"https://arxiv.org/abs/2412.20413v2","url_pdf":"https://arxiv.org/pdf/2412.20413v2.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":"eraseanything-enabling-concept-erasure-in","repo_url":"https://github.com/tomguluson92/eraseanything","is_official":1,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"jax","reach":{"status":"ok","spdx":"BSD-3-Clause"}}],"tasks":[{"task_slug":"contrastive-learning","task_name":"Contrastive Learning"}],"methods":[{"method_slug":"attention","method_name":"Attention"},{"method_slug":"diffusion","method_name":"Diffusion"},{"method_slug":"softmax","method_name":"Softmax"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2412.20413","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2412.20413"}},"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/tomguluson92/eraseanything","reach":{"status":"ok","spdx":"BSD-3-Clause"}}],"summary":{"unverified":16},"by_repo_kind":{"official":{"samples":16,"ran":0,"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":"2f410d45aa8c1315","entry":"MoE","repo":"tomguluson92/eraseanything","repo_kind":"official","path":"ir_concept.py","file_url":"https://github.com/tomguluson92/eraseanything/blob/HEAD/ir_concept.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"2f410d45aa8c1315"}},{"code_sha256_prefix":"2ff43c37cdeed4e6","entry":"calculate_steer_loss","repo":"tomguluson92/eraseanything","repo_kind":"official","path":"utils/infoNCE.py","file_url":"https://github.com/tomguluson92/eraseanything/blob/HEAD/utils/infoNCE.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"2ff43c37cdeed4e6"}},{"code_sha256_prefix":"cf4b316a3a6d6746","entry":"collate_data_fn","repo":"tomguluson92/eraseanything","repo_kind":"official","path":"lora_dataset.py","file_url":"https://github.com/tomguluson92/eraseanything/blob/HEAD/lora_dataset.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"cf4b316a3a6d6746"}},{"code_sha256_prefix":"39f2be6188e09424","entry":"encode_prompt","repo":"tomguluson92/eraseanything","repo_kind":"official","path":"prompt_process.py","file_url":"https://github.com/tomguluson92/eraseanything/blob/HEAD/prompt_process.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"39f2be6188e09424"}},{"code_sha256_prefix":"0393606cc9b74f59","entry":"filt_response","repo":"tomguluson92/eraseanything","repo_kind":"official","path":"ir_concept.py","file_url":"https://github.com/tomguluson92/eraseanything/blob/HEAD/ir_concept.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"0393606cc9b74f59"}},{"code_sha256_prefix":"1f1b5d50699bbba0","entry":"flux_pack_latents","repo":"tomguluson92/eraseanything","repo_kind":"official","path":"utils/esd_utils.py","file_url":"https://github.com/tomguluson92/eraseanything/blob/HEAD/utils/esd_utils.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"1f1b5d50699bbba0"}},{"code_sha256_prefix":"d90a243dc7ac73ad","entry":"flux_unpack_latents","repo":"tomguluson92/eraseanything","repo_kind":"official","path":"utils/esd_utils.py","file_url":"https://github.com/tomguluson92/eraseanything/blob/HEAD/utils/esd_utils.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"d90a243dc7ac73ad"}},{"code_sha256_prefix":"9ed681562f12226e","entry":"get_sigmas","repo":"tomguluson92/eraseanything","repo_kind":"official","path":"utils/calc_loss.py","file_url":"https://github.com/tomguluson92/eraseanything/blob/HEAD/utils/calc_loss.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"9ed681562f12226e"}},{"code_sha256_prefix":"c1a4a7602c9e7e4d","entry":"get_synonyms","repo":"tomguluson92/eraseanything","repo_kind":"official","path":"lora_dataset.py","file_url":"https://github.com/tomguluson92/eraseanything/blob/HEAD/lora_dataset.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"c1a4a7602c9e7e4d"}},{"code_sha256_prefix":"36355b45444139e9","entry":"get_word_index","repo":"tomguluson92/eraseanything","repo_kind":"official","path":"utils/find_token.py","file_url":"https://github.com/tomguluson92/eraseanything/blob/HEAD/utils/find_token.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"36355b45444139e9"}},{"code_sha256_prefix":"212f670149d23d38","entry":"import_model_class_from_model_name_or_path","repo":"tomguluson92/eraseanything","repo_kind":"official","path":"train_flux_lora.py","file_url":"https://github.com/tomguluson92/eraseanything/blob/HEAD/train_flux_lora.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"212f670149d23d38"}},{"code_sha256_prefix":"c140516be52da6c8","entry":"latent_sample","repo":"tomguluson92/eraseanything","repo_kind":"official","path":"utils/esd_utils.py","file_url":"https://github.com/tomguluson92/eraseanything/blob/HEAD/utils/esd_utils.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"c140516be52da6c8"}},{"code_sha256_prefix":"d38b6b75175267f1","entry":"load_text_encoders","repo":"tomguluson92/eraseanything","repo_kind":"official","path":"train_flux_lora.py","file_url":"https://github.com/tomguluson92/eraseanything/blob/HEAD/train_flux_lora.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"d38b6b75175267f1"}},{"code_sha256_prefix":"c45ebec24dc3adce","entry":"search_sequence_numpy","repo":"tomguluson92/eraseanything","repo_kind":"official","path":"utils/find_token.py","file_url":"https://github.com/tomguluson92/eraseanything/blob/HEAD/utils/find_token.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"c45ebec24dc3adce"}},{"code_sha256_prefix":"2e5bb2364f868e35","entry":"tidy_output","repo":"tomguluson92/eraseanything","repo_kind":"official","path":"ir_concept.py","file_url":"https://github.com/tomguluson92/eraseanything/blob/HEAD/ir_concept.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"2e5bb2364f868e35"}},{"code_sha256_prefix":"442d96197841458f","entry":"tokenize_prompt","repo":"tomguluson92/eraseanything","repo_kind":"official","path":"prompt_process.py","file_url":"https://github.com/tomguluson92/eraseanything/blob/HEAD/prompt_process.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"442d96197841458f"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}