SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2303.10353 · CVPR · 2023

Sharpness-Aware Gradient Matching for Domain Generalization

Lei Zhang, Zhaoxiang Zhang, Pengfei Wang, Zhen Lei

arXiv · PDF · Open in the Atlas

Code that ran

10 of 15 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (8 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 8 have no contract verdict; 2 failures of our instrument; 5 no recorded run), measured 2026-11-22; repository links from the Papers with Code archive attributed under CC BY-SA, no affiliation; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2303.10353.json · badge: /api/ran/2303.10353.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
wang-pengfei/sagm marked official in Papers with Code
Papers with Code archive
9 ran · 5 no recorded run
copy not recorded community
not in the paper's declared repositories
1 ran · 0 no recorded run
FunctionStatusWhere it lives
Algorithm Ran
ran on a synthesized input · constructed an object; no result was computed
wang-pengfei/sagm/domainbed/algorithms/algorithms.py
code served (permissive licence) · get_code("d67127a3c5e535a0")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned an instance of its own class, Algorithm: the run constructed the object and did not call it, so no result was computed. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn
import copy

torch.manual_seed(0)

# Define a minimal nn.Module for the network
class MinimalNetwork(nn.Module):
    def __init__(self, input_shape, num_classes):
        super(MinimalNetwork, self).__init__()
        # input_shape is a tuple like (3, 32, 32)
        input_size = 1
        for dim in input_shape:
            input_size *= dim
        self.fc = nn.Linear(input_size, num_classes)
    
    def forward(self, x):
        x = x.view(x.size(0), -1)
        return self.fc(x)

# Create a concrete Algorithm subclass for testing
class ConcreteAlgorithm(torch.nn.Module):
    def __init__(self, input_shape, num_classes, num_domains, hparams):
        super(ConcreteAlgorithm, self).__init__()
        self.input_shape = input_shape
        self.num_classes = num_classes
        self.num_domains = num_domains
        self.hparams = hparams
        self.network = MinimalNetwork(input_shape, num_classes)
        self.optimizer = self.new_optimizer(self.network.parameters())
    
    def update(self, x, y, **kwargs):
        pass
    
    def predict(self, x):
        return self.network(x)
    
    def forward(self, x):
        return self.predict(x)
    
    def new_optimizer(self, parameters):
        optimizer = get_optimizer(
            self.hparams['optimizer'],
            parameters,
            lr=self.hparams['lr'],
            weight_decay=self.hparams['weight_decay']
        )
        return optimizer
    
    def clone(self):
        clone = copy.deepcopy(self)
        clone.optimizer = self.new_optimizer(clone.network.parameters())
        clone.optimizer.load_state_dict(self.optimizer.state_dict())
        return clone

ARGS = {
    'input_shape': (3, 4, 4),
    'num_classes': 5,
    'num_domains': 2,
    'hparams': {
        'optimizer': 'adam',
        'lr': 0.001,
        'weight_decay': 0.0001
    }
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Algorithm — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a Algorithm output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
Identity Ran
ran on a synthesized input · constructed an object; no result was computed
wang-pengfei/sagm/domainbed/algorithms/algorithms.py
code served (permissive licence) · get_code("c090fe2ca8acedb3")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned an instance of its own class, Identity: the run constructed the object and did not call it, so no result was computed. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

torch.manual_seed(0)

class Identity(nn.Module):
    """An identity layer"""

    def __init__(self):
        super(Identity, self).__init__()

    def forward(self, x):
        return x

# Create a small test tensor
x = torch.randn(2, 4)

# The Identity class __init__ takes no parameters
ARGS = {}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Identity — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a Identity output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
MLP Ran
ran on a synthesized input · constructed an object; no result was computed
wang-pengfei/sagm/domainbed/algorithms/algorithms.py
code served (permissive licence) · get_code("bacc92fd6ae22e2c")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned an instance of its own class, MLP: the run constructed the object and did not call it, so no result was computed. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

torch.manual_seed(0)

# Define hyperparameters dict
hparams = {
    'mlp_width': 8,
    'mlp_dropout': 0.1,
    'mlp_depth': 3
}

# Define arguments for MLP.__init__
ARGS = {
    'n_inputs': 4,
    'n_outputs': 3,
    'hparams': hparams
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type MLP — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a MLP output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
MNIST_CNN Ran
ran on a synthesized input · constructed an object; no result was computed
wang-pengfei/sagm/domainbed/algorithms/algorithms.py
code served (permissive licence) · get_code("c998f65811a9d80f")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned an instance of its own class, MNIST_CNN: the run constructed the object and did not call it, so no result was computed. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

torch.manual_seed(0)

ARGS = {
    "input_shape": (1, 28, 28)
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type MNIST_CNN — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a MNIST_CNN output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
ResNet Ran
ran on a synthesized input · constructed an object; no result was computed
wang-pengfei/sagm/domainbed/algorithms/algorithms.py
code served (permissive licence) · get_code("73d7253036166f22")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned an instance of its own class, ResNet: the run constructed the object and did not call it, so no result was computed. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn
import torchvision.models

torch.manual_seed(0)

# Define hparams dict with all required keys
hparams = {
    'resnet18': True,
    'pretrained': False,
    'resnet_dropout': 0.5,
    'freeze_bn': True
}

# Define input_shape as (channels, height, width)
input_shape = (3, 224, 224)

# Define network as None to let ResNet instantiate it
network = None

ARGS = {
    'input_shape': input_shape,
    'hparams': hparams,
    'network': network
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch, torchvision — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type ResNet — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a ResNet output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
SqueezeLastTwo Ran
ran on a synthesized input · constructed an object; no result was computed
wang-pengfei/sagm/domainbed/algorithms/algorithms.py
code served (permissive licence) · get_code("01b81ca81d7a2e60")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned an instance of its own class, SqueezeLastTwo: the run constructed the object and did not call it, so no result was computed. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

torch.manual_seed(0)

# SqueezeLastTwo.__init__() takes no parameters beyond self
# SqueezeLastTwo.forward() expects a tensor x with at least 3 dimensions
# The forward method does: x.view(x.shape[0], x.shape[1])
# This reshapes the tensor to keep first two dimensions and squeeze the rest

# Create a test input tensor with shape (batch, channels, height, width)
# Using distinct sizes: batch=2, channels=4, height=3, width=5
test_input = torch.randn(2, 4, 3, 5)

ARGS = {}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type SqueezeLastTwo — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a SqueezeLastTwo output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
Wide_ResNet Ran
ran on a synthesized input · constructed an object; no result was computed
wang-pengfei/sagm/domainbed/algorithms/algorithms.py
code served (permissive licence) · get_code("6a63af402870932f")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned an instance of its own class, Wide_ResNet: the run constructed the object and did not call it, so no result was computed. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

torch.manual_seed(0)

# Define ARGS dictionary with all required parameters for Wide_ResNet
ARGS = {
    "input_shape": (3, 32, 32),  # RGB images, 32x32 (standard for CIFAR-10 style)
    "depth": 16,                  # depth = 6n+4, so 16 = 6*2+4
    "widen_factor": 2,            # widen factor k
    "dropout_rate": 0.3           # dropout probability
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Wide_ResNet — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a Wide_ResNet output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
conv3x3 Ran
ran; our contract draft was wrong, not the code
this paper's copy was not recorded; identical code first harvested from DaikiTanak/manifold_mixup
pointer only; the stored copy get_code serves, from DaikiTanak/manifold_mixup, is pointer only (licence: NONE) · get_code("00e569acd6b45ef0")
How it ran

The body of this sample is withheld: this paper's copy of the code was not recorded (its link names no repository or source path), so no licence was read for it. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

get_optimizer Ran
ran; our contract draft was wrong, not the code
wang-pengfei/sagm/domainbed/algorithms/algorithms.py
code served (permissive licence) · get_code("5a8d4d0e1bf66cd4")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned Adam. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

torch.manual_seed(0)

# Create a simple neural network model
model = nn.Sequential(
    nn.Linear(4, 8),
    nn.ReLU(),
    nn.Linear(8, 2)
)

# Extract parameters from the model
params = model.parameters()

# Define ARGS dict with all parameters
ARGS = {
    'name': 'adam',
    'params': params,
    'lr': 0.001,
    'weight_decay': 1e-5
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Adam — a Adam output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a Adam output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
wide_basic Ran
ran on a synthesized input · constructed an object; no result was computed
wang-pengfei/sagm/domainbed/algorithms/algorithms.py
code served (permissive licence) · get_code("a47120fe8df1b363")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned an instance of its own class, wide_basic: the run constructed the object and did not call it, so no result was computed. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

torch.manual_seed(0)

# The wide_basic module expects:
# - in_planes: int (number of input channels)
# - planes: int (number of output channels)
# - dropout_rate: float (dropout probability)
# - stride: int (stride for convolution, optional, default=1)

ARGS = {
    'in_planes': 3,
    'planes': 16,
    'dropout_rate': 0.3,
    'stride': 1
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type wide_basic — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a wide_basic output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
Featurizer Not yet run
unverified (harvested, no recorded run)
wang-pengfei/sagm/domainbed/algorithms/algorithms.py
code served (permissive licence) · get_code("467b3583a59f952e")
How it ran

no invocation recorded.

SAGM Not yet run
unverified (harvested, no recorded run)
wang-pengfei/sagm/domainbed/algorithms/algorithms.py
code served (permissive licence) · get_code("9da593320c9aef89")
How it ran

no invocation recorded.

SAGM_DG Not yet run
unverified (harvested, no recorded run)
wang-pengfei/sagm/domainbed/algorithms/algorithms.py
code served (permissive licence) · get_code("7686c49c58187b1d")
How it ran

no invocation recorded.

disable_running_stats Not yet run
unverified (harvested, no recorded run)
wang-pengfei/sagm/domainbed/algorithms/algorithms.py
code served (permissive licence) · get_code("957cadb71fb37e35")
How it ran

no invocation recorded.

enable_running_stats Not yet run
unverified (harvested, no recorded run)
wang-pengfei/sagm/domainbed/algorithms/algorithms.py
code served (permissive licence) · get_code("5ad5be23a3cf2d30")
How it ran

no invocation recorded.

Also present in other papers' code

Of 15 samples lifted from this paper's linked repositories, 15 carry a function identity and 0 do not. Of the 15 distinct functions with an identity, 13 are also present in other papers whose code we hold (6 with at least one paper dated earlier, 2 the same month, 13 later) and 2 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

FunctionAlso present inEarliest-datedOthers named
conv3x3
brick of this paper's assembly: helper
74 other papers
39 dated earlier, 1 the same month, 34 later · 5 only as an assembly brick
1605.07146 (2016-05)
Wide Residual Networks
1707.01629 (2017-07)
Dual Path Networks
1802.05668 (2018-02)
Model compression via distillation and quantization
and 71 more not named here
Identity
brick of this paper's assembly: helper
26 other papers
17 dated earlier, 1 the same month, 8 later · 22 only as an assembly brick
1512.03385 (2015-12)
Deep Residual Learning for Image Recognition
1806.09055 (2018-06)
DARTS: Differentiable Architecture Search
2002.05709 (2020-02)
A Simple Framework for Contrastive Learning of Visual Representations
and 23 more not named here
MLP
brick of this paper's assembly: helper
6 other papers
2 dated earlier, 4 later · 6 only as an assembly brick
2201.11259 (2022-01)
Controlling Directions Orthogonal to a Classifier
2205.14546 (2022-05)
The Missing Invariance Principle Foundthe Reciprocal Twin of Invariant Risk Minimization
2307.12502 (2023-07)
Cross Contrasting Feature Perturbation for Domain Generalization
and 3 more not named here
wide_basic
brick of this paper's assembly: helper
5 other papers
2 dated earlier, 3 later · 5 only as an assembly brick
1605.07146 (2016-05)
Wide Residual Networks
2205.14546 (2022-05)
The Missing Invariance Principle Foundthe Reciprocal Twin of Invariant Risk Minimization
2402.11682 (2024-02)
Learning Conditional Invariances through Non-Commutativity
and 2 more not named here
Wide_ResNet
brick of this paper's assembly: helper
4 other papers
1 dated earlier, 3 later · 4 only as an assembly brick
2205.14546 (2022-05)
The Missing Invariance Principle Foundthe Reciprocal Twin of Invariant Risk Minimization
2402.11682 (2024-02)
Learning Conditional Invariances through Non-Commutativity
2502.20162 (2025-02)
Gradient-Guided Annealing for Domain Generalization
and 1 more not named here
SqueezeLastTwo
brick of this paper's assembly: helper
2 other papers
1 dated earlier, 1 later · 1 only as an assembly brick
2201.11259 (2022-01)
Controlling Directions Orthogonal to a Classifier
2502.20162 (2025-02)
Gradient-Guided Annealing for Domain Generalization
Algorithm
brick of this paper's assembly: helper
1 other paper
1 later · 1 only as an assembly brick
2502.20162 (2025-02)
Gradient-Guided Annealing for Domain Generalization
Featurizer
brick of this paper's assembly: helper
1 other paper
1 later · 1 only as an assembly brick
2502.20162 (2025-02)
Gradient-Guided Annealing for Domain Generalization
MNIST_CNN
brick of this paper's assembly: helper
1 other paper
1 later · 1 only as an assembly brick
2502.20162 (2025-02)
Gradient-Guided Annealing for Domain Generalization
ResNet
brick of this paper's assembly: helper
1 other paper
1 later · 1 only as an assembly brick
2502.20162 (2025-02)
Gradient-Guided Annealing for Domain Generalization
disable_running_stats
brick of this paper's assembly: helper
1 other paper
1 later · 1 only as an assembly brick
2404.17805 (2024-04)
From Optimization to Generalization: Fair Federated Learning against Quality Shift via Inter-Client Sharpness Matching
enable_running_stats
brick of this paper's assembly: helper
1 other paper
1 later · 1 only as an assembly brick
2404.17805 (2024-04)
From Optimization to Generalization: Fair Federated Learning against Quality Shift via Inter-Client Sharpness Matching
get_optimizer
brick of this paper's assembly: helper
1 other paper
1 later · 1 only as an assembly brick
2502.20162 (2025-02)
Gradient-Guided Annealing for Domain Generalization

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-22.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

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/Wangpengfei/SAGM .

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2303.10353")
get_code_for_paper("2303.10353")
have("2303.10353")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2303.10353.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2303.10353.svg)](https://syntology.ai/paper/2303.10353)

Connect an agent — have() is free.