SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2111.12273 · 2021

Sharpness-aware Quantization for Deep Neural Networks

arXiv · PDF · Open in the Atlas

Code that ran

6 of 11 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 6 have no contract verdict; 0 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/2111.12273.json · badge: /api/ran/2111.12273.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
zhuang-group/saq canonical (classifier label)
classifier basis not recorded on the link
6 ran · 5 no recorded run
FunctionStatusWhere it lives
data_parallel Ran
ran on a synthesized input
zhuang-group/saq/core/model_transform.py
code served (permissive licence) · get_code("3da0ed128a47216d")
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 SimpleModel. 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 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 model for testing
class SimpleModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 3)
    
    def forward(self, x):
        return self.linear(x)

# Since the function requires CUDA and we're CPU-only,
# we need to construct arguments that would work if CUDA were available.
# The function will fail on the cuda() calls, but that's expected behavior.

model = SimpleModel()
n_gpus = 1
gpu0 = 0

ARGS = {
    'model': model,
    'n_gpus': n_gpus,
    'gpu0': gpu0
}
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 SimpleModel — a SimpleModel output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a SimpleModel 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
get_imagenet_dataloader Ran
ran on a synthesized input
zhuang-group/saq/core/dataloader.py
code served (permissive licence) · get_code("961a136f0e5151f9")
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 os
import tempfile
import torch
import torch.utils.data
import torchvision.datasets as datasets
import torchvision.transforms as transforms
from PIL import Image
import numpy as np

torch.manual_seed(0)

# Create a temporary directory structure for ImageNet-like data
temp_dir = tempfile.mkdtemp()
data_path = temp_dir
dataset_name = 'imagenet'
dataset_path = os.path.join(data_path, dataset_name)

# Create train and val directories
traindir = os.path.join(dataset_path, 'train')
valdir = os.path.join(dataset_path, 'val')

os.makedirs(os.path.join(traindir, 'class1'), exist_ok=True)
os.makedirs(os.path.join(traindir, 'class2'), exist_ok=True)
os.makedirs(os.path.join(valdir, 'class1'), exist_ok=True)
os.makedirs(os.path.join(valdir, 'class2'), exist_ok=True)

# Create minimal dummy images
def create_dummy_image(path):
    img_array = np.random.randint(0, 255, (32, 32, 3), dtype=np.uint8)
    img = Image.fromarray(img_array)
    img.save(path)

for i in range(2):
    create_dummy_image(os.path.join(traindir, 'class1', f'img_{i}.jpg'))
    create_dummy_image(os.path.join(traindir, 'class2', f'img_{i}.jpg'))
    create_dummy_image(os.path.join(valdir, 'class1', f'img_{i}.jpg'))
    create_dummy_image(os.path.join(valdir, 'class2', f'img_{i}.jpg'))

# Create a simple logger stand-in
class SimpleLogger:
    def info(self, msg):
        pass

logger = SimpleLogger()

ARGS = {
    'dataset': 'imagenet',
    'batch_size': 2,
    'n_threads': 2,
    'data_path': data_path,
    'transfroms_name': 'default',
    'distributed': False,
    'logger': logger,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
PIL, numpy, 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
get_logger Ran
ran on a synthesized input
zhuang-group/saq/core/logger.py
code served (permissive licence) · get_code("5d93362f9df2f82e")
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 Logger. 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 logging
import os
import sys
import tempfile

# Create a temporary directory for the logger to write to
temp_dir = tempfile.mkdtemp()

ARGS = {
    "save_path": temp_dir,
    "logger_name": "test_logger"
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Logger — a Logger output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a Logger 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
get_lr Ran
ran on a synthesized input
zhuang-group/saq/core/engine.py
code served (permissive licence) · get_code("601ccb52d01d6f2c")
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 float, ndim 0, dtype family float, 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 torch.nn as nn
import torch.optim as optim

torch.manual_seed(0)

# Create a minimal model
model = nn.Linear(4, 2)

# Create an optimizer with the model's parameters
optimizer = optim.SGD(model.parameters(), lr=0.01)

# The function get_lr() accesses optimizer.param_groups and reads the 'lr' key
# We need to pass a valid optimizer instance that has param_groups set up

ARGS = {
    'optimizer': optimizer
}
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 float, 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
get_optimizer Ran
ran on a synthesized input
zhuang-group/saq/core/optim.py
code served (permissive licence) · get_code("cb0169bdacbbefc8")
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 small model
class SimpleModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.layer1 = nn.Linear(4, 3)
        self.layer2 = nn.Linear(3, 2)
        self.bn = nn.BatchNorm1d(3)
    
    def forward(self, x):
        x = self.layer1(x)
        x = self.bn(x)
        x = self.layer2(x)
        return x

# Create args object
class Args:
    def __init__(self):
        self.lr = 0.001
        self.weight_decay = 0.0001
        self.momentum = 0.9
        self.alpha = 0.99
        self.eps = 1e-8
        self.no_decay_keys = []
        self.opt_type = 'Adam'

model = SimpleModel()
args = Args()

ARGS = {
    'model': model,
    'args': 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 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
list2sequential Ran
ran on a synthesized input
zhuang-group/saq/core/model_transform.py
code served (permissive licence) · get_code("e8b97da0d2b443fb")
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 Sequential. 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 some simple nn.Module layers to put in a list
layer1 = nn.Linear(4, 3)
layer2 = nn.ReLU()
layer3 = nn.Linear(3, 2)

# Test case 1: pass a list of modules
model_list = [layer1, layer2, layer3]

ARGS = {
    "model": model_list
}
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 Sequential — a Sequential output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a Sequential output the recorded ndim 1 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
get_cifar_dataloader Not yet run
unverified (harvested, no recorded run)
zhuang-group/saq/core/dataloader.py
code served (permissive licence) · get_code("c40f16f8c552876e")
How it ran

no invocation recorded.

get_cifar_train_val_test_dataloader Not yet run
unverified (harvested, no recorded run)
zhuang-group/saq/core/dataloader.py
code served (permissive licence) · get_code("b02977776bf3caf6")
How it ran

no invocation recorded.

model2list Not yet run
unverified (harvested, no recorded run)
zhuang-group/saq/core/model_transform.py
code served (permissive licence) · get_code("46bf64171d2a9bf5")
How it ran

no invocation recorded.

train Not yet run
unverified (harvested, no recorded run)
zhuang-group/saq/core/engine.py
code served (permissive licence) · get_code("f924bc6970c6a9da")
How it ran

no invocation recorded.

val Not yet run
unverified (harvested, no recorded run)
zhuang-group/saq/core/engine.py
code served (permissive licence) · get_code("d9191590db201cdf")
How it ran

no invocation recorded.

Also present in other papers' code

Of 11 samples lifted from this paper's linked repositories, 11 carry a function identity and 0 do not. Of the 11 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 11 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

Network quantization is a dominant paradigm of model compression. However, the abrupt changes in quantized weights during training often lead to severe loss fluctuations and result in a sharp loss landscape, making the gradients unstable and thus degrading the performance. Recently, Sharpness-Aware Minimization (SAM) has been proposed to smooth the loss landscape and improve the generalization performance of the models. Nevertheless, directly applying SAM to the quantized models can lead to perturbation mismatch or diminishment issues, resulting in suboptimal performance. In this paper, we propose a novel method, dubbed Sharpness-Aware Quantization (SAQ), to explore the effect of SAM in model compression, particularly quantization for the first time. Specifically, we first provide a unified view of quantization and SAM by treating them as introducing quantization noises and adversarial perturbations to the model weights, respectively. According to whether the noise and perturbation terms depend on each other, SAQ can be formulated into three cases, which are analyzed and compared comprehensively. Furthermore, by introducing an efficient training strategy, SAQ only incurs a little additional training overhead compared with the default optimizer (e.g., SGD or AdamW). Extensive experiments on both convolutional neural networks and Transformers across various datasets (i.e., ImageNet, CIFAR-10/100, Oxford Flowers-102, Oxford-IIIT Pets) show that SAQ improves the generalization performance of the quantized models, yielding the SOTA results in uniform quantization. For example, on ImageNet, SAQ outperforms AdamW by 1.2% on the Top-1 accuracy for 4-bit ViT-B/16. Our 4-bit ResNet-50 surpasses the previous SOTA method by 0.9% on the Top-1 accuracy.

For agents

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

get_harvested_code_for_paper("2111.12273")
get_code_for_paper("2111.12273")
have("2111.12273")

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

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

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

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

Connect an agent — have() is free.