{"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/on-the-duality-between-sharpness-aware","title":"On the Duality Between Sharpness-Aware Minimization and Adversarial Training","arxiv_id":"2402.15152","date":"2024-02-23","proceeding":null,"authors":["Yihao Zhang","Hangzhou He","Jingyu Zhu","Huanran Chen","Yifei Wang","Zeming Wei"],"abstract":"Adversarial Training (AT), which adversarially perturb the input samples during training, has been acknowledged as one of the most effective defenses against adversarial attacks, yet suffers from inevitably decreased clean accuracy. Instead of perturbing the samples, Sharpness-Aware Minimization (SAM) perturbs the model weights during training to find a more flat loss landscape and improve generalization. However, as SAM is designed for better clean accuracy, its effectiveness in enhancing adversarial robustness remains unexplored. In this work, considering the duality between SAM and AT, we investigate the adversarial robustness derived from SAM. Intriguingly, we find that using SAM alone can improve adversarial robustness. To understand this unexpected property of SAM, we first provide empirical and theoretical insights into how SAM can implicitly learn more robust features, and conduct comprehensive experiments to show that SAM can improve adversarial robustness notably without sacrificing any clean accuracy, shedding light on the potential of SAM to be a substitute for AT when accuracy comes at a higher priority. Code is available at https://github.com/weizeming/SAM_AT.","url_abs":"https://arxiv.org/abs/2402.15152v2","url_pdf":"https://arxiv.org/pdf/2402.15152v2.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":"on-the-duality-between-sharpness-aware","repo_url":"https://github.com/weizeming/sam_at","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":0,"framework":"pytorch","reach":{"status":"ok"}}],"tasks":[{"task_slug":"adversarial-robustness","task_name":"Adversarial Robustness"}],"methods":[{"method_slug":"sam","method_name":"SAM"},{"method_slug":"sharpness-aware-minimization","method_name":"Sharpness-Aware Minimization"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2402.15152","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2402.15152"}},"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":"deterministic:regex_extraction","url":"https://github.com/weizeming/SAM_AT","reach":{"status":"ok"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/weizeming/sam_at","reach":{"status":"ok"}}],"summary":{"ran":3,"unverified":5},"by_repo_kind":{"official":{"samples":8,"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":8,"samples":[{"code_sha256_prefix":"4b9b1e0236811496","entry":"gen_bar_updater","repo":"weizeming/SAM_AT","repo_kind":"official","path":"SAM_segmentation/datasets/utils.py","file_url":"https://github.com/weizeming/SAM_AT/blob/HEAD/SAM_segmentation/datasets/utils.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"4b9b1e0236811496"}},{"code_sha256_prefix":"0d8aca7e68b6e3c8","entry":"list_dir","repo":"weizeming/SAM_AT","repo_kind":"official","path":"SAM_segmentation/datasets/utils.py","file_url":"https://github.com/weizeming/SAM_AT/blob/HEAD/SAM_segmentation/datasets/utils.py","link_basis":"harvester_set","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"0d8aca7e68b6e3c8"}},{"code_sha256_prefix":"681c53dc1b27fe63","entry":"voc_cmap","repo":"weizeming/SAM_AT","repo_kind":"official","path":"SAM_segmentation/datasets/voc.py","file_url":"https://github.com/weizeming/SAM_AT/blob/HEAD/SAM_segmentation/datasets/voc.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"681c53dc1b27fe63"}},{"code_sha256_prefix":"7345763c9b9300fb","entry":"check_integrity","repo":"weizeming/SAM_AT","repo_kind":"official","path":"SAM_segmentation/datasets/utils.py","file_url":"https://github.com/weizeming/SAM_AT/blob/HEAD/SAM_segmentation/datasets/utils.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"7345763c9b9300fb"}},{"code_sha256_prefix":"ce942a958c0ae909","entry":"convert_to_separable_conv","repo":"weizeming/SAM_AT","repo_kind":"official","path":"SAM_segmentation/network/_deeplab.py","file_url":"https://github.com/weizeming/SAM_AT/blob/HEAD/SAM_segmentation/network/_deeplab.py","link_basis":"plan_row","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"ce942a958c0ae909"}},{"code_sha256_prefix":"e980799df5aec203","entry":"deeplabv3_hrnetv2_32","repo":"weizeming/SAM_AT","repo_kind":"official","path":"SAM_segmentation/network/modeling.py","file_url":"https://github.com/weizeming/SAM_AT/blob/HEAD/SAM_segmentation/network/modeling.py","link_basis":"plan_row","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"e980799df5aec203"}},{"code_sha256_prefix":"c85f2e9d72fb69ec","entry":"deeplabv3_hrnetv2_48","repo":"weizeming/SAM_AT","repo_kind":"official","path":"SAM_segmentation/network/modeling.py","file_url":"https://github.com/weizeming/SAM_AT/blob/HEAD/SAM_segmentation/network/modeling.py","link_basis":"plan_row","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"c85f2e9d72fb69ec"}},{"code_sha256_prefix":"0264c7923a17f00c","entry":"deeplabv3_resnet50","repo":"weizeming/SAM_AT","repo_kind":"official","path":"SAM_segmentation/network/modeling.py","file_url":"https://github.com/weizeming/SAM_AT/blob/HEAD/SAM_segmentation/network/modeling.py","link_basis":"plan_row","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"0264c7923a17f00c"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}