{"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/sharpness-aware-gradient-matching-for-domain","title":"Sharpness-Aware Gradient Matching for Domain Generalization","arxiv_id":"2303.10353","date":"2023-03-18","proceeding":"CVPR 2023 1","authors":["Pengfei Wang","Zhaoxiang Zhang","Zhen Lei","Lei Zhang"],"abstract":"The goal of domain generalization (DG) is to enhance the generalization capability of the model learned from a source domain to other unseen domains. The recently developed Sharpness-Aware Minimization (SAM) method aims to achieve this goal by minimizing the sharpness measure of the loss landscape. Though SAM and its variants have demonstrated impressive DG performance, they may not always converge to the desired flat region with a small loss value. In this paper, we present two conditions to ensure that the model could converge to a flat minimum with a small loss, and present an algorithm, named Sharpness-Aware Gradient Matching (SAGM), to meet the two conditions for improving model generalization capability. Specifically, the optimization objective of SAGM will simultaneously minimize the empirical risk, the perturbed loss (i.e., the maximum loss within a neighborhood in the parameter space), and the gap between them. By implicitly aligning the gradient directions between the empirical risk and the perturbed loss, SAGM improves the generalization capability over SAM and its variants without increasing the computational cost. Extensive experimental results show that our proposed SAGM method consistently outperforms the state-of-the-art methods on five DG benchmarks, including PACS, VLCS, OfficeHome, TerraIncognita, and DomainNet. Codes are available at https://github.com/Wang-pengfei/SAGM.","url_abs":"https://arxiv.org/abs/2303.10353v1","url_pdf":"https://arxiv.org/pdf/2303.10353v1.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":"sharpness-aware-gradient-matching-for-domain","repo_url":"https://github.com/wang-pengfei/sagm","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":null}],"tasks":[{"task_slug":"domain-generalization","task_name":"Domain Generalization"}],"methods":[{"method_slug":"sharpness-aware-minimization","method_name":"Sharpness-Aware Minimization"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"syntology_url":"https://syntology.ai/paper/2303.10353","atlas_url":"https://app.syntology.ai/?focus=2303.10353","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2303.10353"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-25T09:33:49+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/wang-pengfei/sagm","reach":null},{"provenance":"deterministic:regex_extraction","url":"https://github.com/Wangpengfei/SAGM","reach":{"status":"gone","observed_at":"2026-09-17","how":"tree_404+repo_404"}}],"summary":{"ran":8,"ran_draft_wrong":2,"unverified":5},"by_repo_kind":{"official":{"samples":14,"ran":9,"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":1,"samples":[{"code_sha256_prefix":"d67127a3c5e535a0","entry":"Algorithm","repo":"wang-pengfei/sagm","repo_kind":"official","path":"domainbed/algorithms/algorithms.py","file_url":"https://github.com/wang-pengfei/sagm/blob/HEAD/domainbed/algorithms/algorithms.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"d67127a3c5e535a0"}},{"code_sha256_prefix":"c090fe2ca8acedb3","entry":"Identity","repo":"wang-pengfei/sagm","repo_kind":"official","path":"domainbed/algorithms/algorithms.py","file_url":"https://github.com/wang-pengfei/sagm/blob/HEAD/domainbed/algorithms/algorithms.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"c090fe2ca8acedb3"}},{"code_sha256_prefix":"bacc92fd6ae22e2c","entry":"MLP","repo":"wang-pengfei/sagm","repo_kind":"official","path":"domainbed/algorithms/algorithms.py","file_url":"https://github.com/wang-pengfei/sagm/blob/HEAD/domainbed/algorithms/algorithms.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":"deterministic","behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"bacc92fd6ae22e2c"}},{"code_sha256_prefix":"c998f65811a9d80f","entry":"MNIST_CNN","repo":"wang-pengfei/sagm","repo_kind":"official","path":"domainbed/algorithms/algorithms.py","file_url":"https://github.com/wang-pengfei/sagm/blob/HEAD/domainbed/algorithms/algorithms.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"c998f65811a9d80f"}},{"code_sha256_prefix":"73d7253036166f22","entry":"ResNet","repo":"wang-pengfei/sagm","repo_kind":"official","path":"domainbed/algorithms/algorithms.py","file_url":"https://github.com/wang-pengfei/sagm/blob/HEAD/domainbed/algorithms/algorithms.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":"deterministic","behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"73d7253036166f22"}},{"code_sha256_prefix":"01b81ca81d7a2e60","entry":"SqueezeLastTwo","repo":"wang-pengfei/sagm","repo_kind":"official","path":"domainbed/algorithms/algorithms.py","file_url":"https://github.com/wang-pengfei/sagm/blob/HEAD/domainbed/algorithms/algorithms.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":"deterministic","behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"01b81ca81d7a2e60"}},{"code_sha256_prefix":"6a63af402870932f","entry":"Wide_ResNet","repo":"wang-pengfei/sagm","repo_kind":"official","path":"domainbed/algorithms/algorithms.py","file_url":"https://github.com/wang-pengfei/sagm/blob/HEAD/domainbed/algorithms/algorithms.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"6a63af402870932f"}},{"code_sha256_prefix":"00e569acd6b45ef0","entry":"conv3x3","repo":null,"repo_kind":null,"path":null,"file_url":null,"link_basis":"identical_code_first_harvested_elsewhere","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":null,"inline_ok":false,"mcp_get_code":{"code_sha256":"00e569acd6b45ef0"}},{"code_sha256_prefix":"5a8d4d0e1bf66cd4","entry":"get_optimizer","repo":"wang-pengfei/sagm","repo_kind":"official","path":"domainbed/algorithms/algorithms.py","file_url":"https://github.com/wang-pengfei/sagm/blob/HEAD/domainbed/algorithms/algorithms.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"5a8d4d0e1bf66cd4"}},{"code_sha256_prefix":"a47120fe8df1b363","entry":"wide_basic","repo":"wang-pengfei/sagm","repo_kind":"official","path":"domainbed/algorithms/algorithms.py","file_url":"https://github.com/wang-pengfei/sagm/blob/HEAD/domainbed/algorithms/algorithms.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":"deterministic","behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"a47120fe8df1b363"}},{"code_sha256_prefix":"467b3583a59f952e","entry":"Featurizer","repo":"wang-pengfei/sagm","repo_kind":"official","path":"domainbed/algorithms/algorithms.py","file_url":"https://github.com/wang-pengfei/sagm/blob/HEAD/domainbed/algorithms/algorithms.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":"467b3583a59f952e"}},{"code_sha256_prefix":"9da593320c9aef89","entry":"SAGM","repo":"wang-pengfei/sagm","repo_kind":"official","path":"domainbed/algorithms/algorithms.py","file_url":"https://github.com/wang-pengfei/sagm/blob/HEAD/domainbed/algorithms/algorithms.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":"9da593320c9aef89"}},{"code_sha256_prefix":"7686c49c58187b1d","entry":"SAGM_DG","repo":"wang-pengfei/sagm","repo_kind":"official","path":"domainbed/algorithms/algorithms.py","file_url":"https://github.com/wang-pengfei/sagm/blob/HEAD/domainbed/algorithms/algorithms.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":"7686c49c58187b1d"}},{"code_sha256_prefix":"957cadb71fb37e35","entry":"disable_running_stats","repo":"wang-pengfei/sagm","repo_kind":"official","path":"domainbed/algorithms/algorithms.py","file_url":"https://github.com/wang-pengfei/sagm/blob/HEAD/domainbed/algorithms/algorithms.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":"957cadb71fb37e35"}},{"code_sha256_prefix":"5ad5be23a3cf2d30","entry":"enable_running_stats","repo":"wang-pengfei/sagm","repo_kind":"official","path":"domainbed/algorithms/algorithms.py","file_url":"https://github.com/wang-pengfei/sagm/blob/HEAD/domainbed/algorithms/algorithms.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":"5ad5be23a3cf2d30"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}