SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2206.06501 · ICML · 2022

Optimal Clipping and Magnitude-aware Differentiation for Improved Quantization-aware Training

Charbel Sakr, Steve Dai, Rangharajan Venkatesan, Brian Zimmer, William Dally, Brucek Khailany

arXiv · PDF · Open in the Atlas

Code that ran

9 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 8 have no contract verdict; 1 failure of our instrument; 0 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/2206.06501.json · badge: /api/ran/2206.06501.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
zavareh1/ClippedQuantFL community (classifier label)
classifier basis not recorded on the link
9 ran · 0 no recorded run
FunctionStatusWhere it lives
compute_global_clipping_scalar Ran
ran on a synthesized input
zavareh1/ClippedQuantFL/model/cifar10DET_quantizedmaxscalar.py
code served (permissive licence) · get_code("608ae6fff31fd3f3")
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

torch.manual_seed(0)

class SimpleModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear1 = nn.Linear(4, 3)
        self.linear2 = nn.Linear(3, 2)
    
    def forward(self, x):
        x = self.linear1(x)
        x = self.linear2(x)
        return x

model = SimpleModel()

ARGS = {
    "model": model,
    "bitW": 4,
    "iterations": 10
}
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
compute_optimal_clipping_scalar Ran
ran on a synthesized input
zavareh1/ClippedQuantFL/model/cifar10DET_quantizedoctav.py
code served (permissive licence) · get_code("0cc294de59beb777")
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. 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 matplotlib
matplotlib.use('Agg')  # Non-interactive backend to avoid display issues

torch.manual_seed(0)

# Create a small tensor with random values
# Using shape (2, 4) for a small batch
tensor = torch.randn(2, 4) * 10  # Scale up to have more interesting distribution

ARGS = {
    'tensor': tensor,
    'bitW': 4,
    'iterations': 10,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
matplotlib, 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
distribute Ran
ran on a synthesized input
zavareh1/ClippedQuantFL/data.py
code served (permissive licence) · get_code("4518324b5d7bd6f0")
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 list, ndim 2, dtype family int; 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 random

# Create a simple dataset - list of (x, y) tuples
# The function iterates over dataset with "for _, y in dataset"
# so we need tuples where second element is the class label
dataset = [
    (torch.randn(4), 0),
    (torch.randn(4), 1),
    (torch.randn(4), 2),
    (torch.randn(4), 0),
    (torch.randn(4), 1),
    (torch.randn(4), 2),
    (torch.randn(4), 0),
    (torch.randn(4), 1),
    (torch.randn(4), 2),
    (torch.randn(4), 0),
    (torch.randn(4), 1),
    (torch.randn(4), 2),
    (torch.randn(4), 0),
    (torch.randn(4), 1),
    (torch.randn(4), 2),
    (torch.randn(4), 0),
    (torch.randn(4), 1),
    (torch.randn(4), 2),
]

# Parameters for the function
distribution = 'noniid'  # Can also test with 'unbalanced' or None
numclients = 2
numclasses = 3

ARGS = {
    'dataset': dataset,
    'distribution': distribution,
    'numclients': numclients,
    'numclasses': numclasses
}
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 list, ndim 2, dtype family int — a list 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
quantize Ran
ran on a synthesized input
zavareh1/ClippedQuantFL/model/cifar10DET_quantizedmaxscalar.py
code served (permissive licence) · get_code("00cb1200d5219763")
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 2, dtype family float, shape (2, 4) 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

torch.manual_seed(0)

# x should be a tensor with values in a reasonable range for quantization
x = torch.randn(2, 4)

# k should be an integer representing the bit-width for quantization
k = 8

ARGS = {
    "x": x,
    "k": k,
}
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 Tensor, ndim 2, dtype family float, shape (2, 4) — shape (2, 4) 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
quantize_weights Ran
ran on a synthesized input
zavareh1/ClippedQuantFL/model/cifar10DET_quantizedmaxscalar.py
code served (permissive licence) · get_code("8b2338dff703aa86")
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 2, dtype family float, shape (2, 4) 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

torch.manual_seed(0)

# Create a small weight tensor (2D for a layer weight matrix)
weight = torch.randn(2, 4)

# Scale parameter s
s = torch.tensor(0.5)

# Bitwidth parameter
bitW = 4

# Per-tensor quantization flag
per_tensor = True

# Construct ARGS dictionary with all parameters
ARGS = {
    'weight': weight,
    's': s,
    'bitW': bitW,
    'per_tensor': per_tensor
}
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 Tensor, ndim 2, dtype family float, shape (2, 4) — shape (2, 4) 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
quantize_weights Ran
ran on a synthesized input
zavareh1/ClippedQuantFL/model/cifar10DET_quantizedoctav.py
code served (permissive licence) · get_code("d15db84a08ceff80")
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 2, dtype family float, shape (2, 4) 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 matplotlib
matplotlib.use('Agg')  # Use non-interactive backend

torch.manual_seed(0)

# Create a small weight tensor (2x4 matrix)
weight = torch.randn(2, 4)

# Compute optimal clipping scalar
s = 0.5

# Define ARGS dictionary with all parameters for quantize_weights
ARGS = {
    'weight': weight,
    's': s,
    'bitW': 4,
    'per_tensor': True
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
matplotlib, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 2, dtype family float, shape (2, 4) — shape (2, 4) 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
quantize_weights Ran
ran on a synthesized input
zavareh1/ClippedQuantFL/model/cifar10STOCH_quantizedmaxscalar.py
code served (permissive licence) · get_code("4f8147e48aa2c397")
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 2, dtype family float, shape (2, 4) 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

torch.manual_seed(0)

# Create a small weight tensor (2x4)
weight = torch.randn(2, 4, requires_grad=True)

# Create a scaling factor s
s = torch.tensor(0.5)

# Create bitW parameter (number of bits for quantization)
bitW = 4

# Create per_tensor parameter (whether to quantize per tensor or per row)
per_tensor = True

ARGS = {
    "weight": weight,
    "s": s,
    "bitW": bitW,
    "per_tensor": per_tensor
}
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 Tensor, ndim 2, dtype family float, shape (2, 4) — shape (2, 4) 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
quantize_weights Ran
ran on a synthesized input
zavareh1/ClippedQuantFL/model/cifar10STOCH_quantizedoctav.py
code served (permissive licence) · get_code("fe0240bc2fecf97c")
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 2, dtype family float, shape (2, 4) 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
torch.manual_seed(0)

# Create a small weight tensor (2x4 to have distinct dimensions)
weight = torch.randn(2, 4) * 0.5

# Compute s using the compute_optimal_clipping_scalar function
s = torch.tensor(0.5)

# Set bitW parameter
bitW = 4

# Set per_tensor parameter
per_tensor = True

ARGS = {
    "weight": weight,
    "s": s,
    "bitW": bitW,
    "per_tensor": per_tensor
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
matplotlib, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 2, dtype family float, shape (2, 4) — shape (2, 4) 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
read_dir Ran
ran; our contract draft was wrong, not the code
zavareh1/ClippedQuantFL/data.py
code served (permissive licence) · get_code("ce8a5a415feadd1f")
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 os
import torch
import json
import tempfile
from collections import defaultdict

# Create a temporary directory with test JSON files
temp_dir = tempfile.mkdtemp()

# Create first JSON file with users and user_data
data1 = {
    'users': ['user1', 'user2'],
    'user_data': {
        'user1': {'x': [1, 2, 3], 'y': 0},
        'user2': {'x': [4, 5, 6], 'y': 1}
    }
}

with open(os.path.join(temp_dir, 'data1.json'), 'w') as f:
    json.dump(data1, f)

# Create second JSON file with users, hierarchies, and user_data
data2 = {
    'users': ['user3', 'user4'],
    'hierarchies': ['group1', 'group2'],
    'user_data': {
        'user3': {'x': [7, 8, 9], 'y': 2},
        'user4': {'x': [10, 11, 12], 'y': 3}
    }
}

with open(os.path.join(temp_dir, 'data2.json'), 'w') as f:
    json.dump(data2, f)

# Create third file that should be ignored (not .json)
with open(os.path.join(temp_dir, 'ignore.txt'), 'w') as f:
    f.write('ignored')

ARGS = {
    'data_dir': temp_dir
}
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 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

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, 1 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 1 later) and 8 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
read_dir 1 other paper
1 later
2407.18365 (2024-07)
FADAS: Towards Federated Adaptive Asynchronous Optimization

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

Data clipping is crucial in reducing noise in quantization operations and improving the achievable accuracy of quantization-aware training (QAT). Current practices rely on heuristics to set clipping threshold scalars and cannot be shown to be optimal. We propose Optimally Clipped Tensors And Vectors (OCTAV), a recursive algorithm to determine MSE-optimal clipping scalars. Derived from the fast Newton-Raphson method, OC-TAV finds optimal clipping scalars on the fly, for every tensor, at every iteration of the QAT routine. Thus, the QAT algorithm is formulated with provably minimum quantization noise at each step. In addition, we reveal limitations in common gradient estimation techniques in QAT and propose magnitude-aware differentiation as a remedy to further improve accuracy. Experimentally, OCTAV-enabled QAT achieves state-ofthe-art accuracy on multiple tasks. These include training-from-scratch and retraining ResNets and MobileNets on ImageNet, and Squad fine-tuning using BERT models, where OCTAV-enabled QAT consistently preserves accuracy at low precision (4-to-6-bits). Our results require no modifications to the baseline training recipe, except for the insertion of quantization operations where appropriate.

For agents

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

get_harvested_code_for_paper("2206.06501")
get_code_for_paper("2206.06501")
have("2206.06501")

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

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

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

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

Connect an agent — have() is free.