SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2307.02337 · 2023

FAM: Relative Flatness Aware Minimization

arXiv · PDF · Open in the Atlas

Code that ran

4 of 9 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 0 have no contract verdict; 4 failures of our instrument; 5 no recorded run), measured 2026-11-23; 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/2307.02337.json · badge: /api/ran/2307.02337.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
kampmichael/RelativeFlatnessAndGeneralization canonical (classifier label)
classifier basis: census
4 ran · 5 no recorded run
FunctionStatusWhere it lives
FAMreg Ran
ran; our contract draft was wrong, not the code
kampmichael/RelativeFlatnessAndGeneralization/RelativeFlatnessRegularizer(FAM)/FAMloss.py
code served (permissive licence) · get_code("cd59b0fd8051ec17")
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 Tensor, ndim 0, dtype family float, shape () as a later run recorded it. The image it ran in was not recorded. The code mentions cuda, and the harness aliases cuda to the CPU for every sample; whether this run needed that is not recorded. If your copy returns the same type, ndim and shape 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 numpy as np

torch.manual_seed(0)

# Create a mock hessian function object
class MockHessianFunction:
    def __init__(self, f_layer):
        self.f_layer = f_layer
    
    def __call__(self, inputs, targets, device):
        # Return a mock Hessian tensor of shape (batch, neurons, neurons, features)
        batch_size = inputs.shape[0]
        neurons = self.f_layer.shape[0]
        features = self.f_layer.shape[1]
        return np.random.randn(batch_size, neurons, neurons, features)
    
    def trace(self, inputs, targets, approximate, device):
        # Return a scalar trace value
        return torch.tensor(2.5, dtype=torch.float32)
    
    def max_eigenvalue(self, inputs, targets, approximate, device):
        # Return a scalar max eigenvalue
        return torch.tensor(1.8, dtype=torch.float32)

# Create a mock feature layer (weight matrix)
feature_layer = torch.randn(4, 3, dtype=torch.float32)  # 4 neurons, 3 features

# Create the hessian function with the feature layer attached
hessian_function = MockHessianFunction(f_layer=feature_layer)

# Create inputs and targets
inputs = torch.randn(2, 5, dtype=torch.float32)  # batch_size=2, input_dim=5
targets = torch.randn(2, 4, dtype=torch.float32)  # batch_size=2, output_dim=4

ARGS = {
    'inputs': inputs,
    'targets': targets,
    'hessian_function': hessian_function,
    'norm_function': 'layerwise_trace',
    'approximate': True
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 0, dtype family float, shape () — shape () as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
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
calculate_loss_on_data Ran
ran; our contract draft was wrong, not the code
kampmichael/RelativeFlatnessAndGeneralization/RelativeFlatnessRegularizer(FAM)/FAMloss.py
code served (permissive licence) · get_code("8466f1e2cecac5f1")
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 tuple. 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 numpy as np

torch.manual_seed(0)

# Define a minimal model that accepts x and returns a tensor
class SimpleModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 3)
    
    def forward(self, x):
        return self.linear(x)

# Define a minimal loss function
loss_fn = nn.MSELoss()

# Create model instance
model = SimpleModel()

# Create tiny tensors: batch size 2, input dim 4, output dim 3
x = torch.randn(2, 4)
y = torch.randn(2, 3)

ARGS = {
    "model": model,
    "loss": loss_fn,
    "x": x,
    "y": y
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple — a tuple output has no array shape of its own; none is 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
load_cifar10 Ran
ran; our contract draft was wrong, not the code
kampmichael/RelativeFlatnessAndGeneralization/CorrelationFlatnessGeneralization/data_loaders.py
code served (permissive licence) · get_code("535c69c58c3d899b")
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 tuple, ndim 1, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim 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
import torchvision.transforms as transforms
from unittest.mock import MagicMock, patch
import os

torch.manual_seed(0)

# Mock the CIFAR10 dataset to avoid downloads
class MockCIFAR10Dataset:
    def __init__(self, root, train=True, download=False, transform=None):
        self.root = root
        self.train = train
        self.transform = transform
        self.data = torch.randn(10, 3, 32, 32)
        self.targets = torch.randint(0, 10, (10,)).tolist()
    
    def __len__(self):
        return len(self.targets)
    
    def __getitem__(self, idx):
        img = self.data[idx]
        if self.transform:
            img = self.transform(img)
        return img, self.targets[idx]

# Patch torchvision.datasets.CIFAR10 before importing/calling the function
original_cifar10 = torchvision.datasets.CIFAR10
torchvision.datasets.CIFAR10 = MockCIFAR10Dataset

ARGS = {
    'train_batch_size': 2,
    'test_batch_size': 2,
}
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 tuple, ndim 1, dtype family float — a tuple output has no array shape of its own; none is stated
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
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
softmax_accuracy Ran
ran; our contract draft was wrong, not the code
kampmichael/RelativeFlatnessAndGeneralization/RelativeFlatnessRegularizer(FAM)/FAMloss.py
code served (permissive licence) · get_code("10cb584d3d906e2f")
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 int, ndim 0, dtype family int, shape () as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape 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 numpy as np

torch.manual_seed(0)

# The function expects:
# - output: a tensor with .data.cpu().numpy() callable, shape (batch_size, num_classes)
#   where argmax gives predicted class indices
# - y: a tensor with .data.cpu().numpy() callable, shape (batch_size,) with true labels

# Create small tensors
batch_size = 2
num_classes = 4

# output: logits/scores with shape (2, 4) - batch of 2, 4 class scores
output = torch.randn(batch_size, num_classes)

# y: true labels with shape (2,) - batch of 2 true class indices
y = torch.tensor([0, 2], dtype=torch.long)

ARGS = {
    "output": output,
    "y": y,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type int, ndim 0, dtype family int, shape () — shape () as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
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
assemble_compare_measures Not yet run
unverified (harvested, no recorded run)
kampmichael/RelativeFlatnessAndGeneralization/CorrelationFlatnessGeneralization/plot_assemble_results.py
code served (permissive licence) · get_code("d83dceb54f2e4cdd")
How it ran

no invocation recorded.

calculateNeuronwiseHessians_fc_layer Not yet run
unverified (harvested, no recorded run)
kampmichael/RelativeFlatnessAndGeneralization/CorrelationFlatnessGeneralization/utils.py
code served (permissive licence) · get_code("7c6793c5676f54f5")
How it ran

no invocation recorded.

combineWeights Not yet run
unverified (harvested, no recorded run)
kampmichael/RelativeFlatnessAndGeneralization/SyntheticExperiments/reverseEngineerNetwork.py
code served (permissive licence) · get_code("41675c5109a70a82")
How it ran

no invocation recorded.

getReverseEngineeredModel_ridge Not yet run
unverified (harvested, no recorded run)
kampmichael/RelativeFlatnessAndGeneralization/SyntheticExperiments/reverseEngineerNetwork.py
code served (permissive licence) · get_code("1b510324243cfd6c")
How it ran

no invocation recorded.

reverseModelPropagation Not yet run
unverified (harvested, no recorded run)
kampmichael/RelativeFlatnessAndGeneralization/SyntheticExperiments/reverseEngineerNetwork.py
code served (permissive licence) · get_code("5b5a8f955effd35a")
How it ran

no invocation recorded.

Also present in other papers' code

Of 9 samples lifted from this paper's linked repositories, 9 carry a function identity and 0 do not. Of the 9 distinct functions with an identity, 0 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 0 later) and 9 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.

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-23.

Repositories linked to this paper

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

Abstract

Flatness of the loss curve around a model at hand has been shown to empirically correlate with its generalization ability. Optimizing for flatness has been proposed as early as 1994 by Hochreiter and Schmidthuber, and was followed by more recent successful sharpness-aware optimization techniques. Their widespread adoption in practice, though, is dubious because of the lack of theoretically grounded connection between flatness and generalization, in particular in light of the reparameterization curse - certain reparameterizations of a neural network change most flatness measures but do not change generalization. Recent theoretical work suggests that a particular relative flatness measure can be connected to generalization and solves the reparameterization curse. In this paper, we derive a regularizer based on this relative flatness that is easy to compute, fast, efficient, and works with arbitrary loss functions. It requires computing the Hessian only of a single layer of the network, which makes it applicable to large neural networks, and with it avoids an expensive mapping of the loss surface in the vicinity of the model. In an extensive empirical evaluation we show that this relative flatness aware minimization (FAM) improves generalization in a multitude of applications and models, both in finetuning and standard training. We make the code available at github.

For agents

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

get_harvested_code_for_paper("2307.02337")
get_code_for_paper("2307.02337")
have("2307.02337")

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

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

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

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

Connect an agent — have() is free.