SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2406.00800 · NeurIPS · 2024

MagR: Weight Magnitude Reduction for Enhancing Post-Training Quantization

Xin Li, Zi Yang, Aozhong Zhang, Naigang Wang, Yanxia Deng, Penghang Yin

arXiv · PDF · Open in the Atlas

Code that ran

8 of 12 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; 8 failures of our instrument; 4 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/2406.00800.json · badge: /api/ran/2406.00800.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
aozhongzhang/magr canonical (classifier label)
classifier basis: classifier_2025
5 ran · 2 no recorded run
AozhongZhang/MagR canonical (classifier label)
classifier basis: census
3 ran · 2 no recorded run
FunctionStatusWhere it lives
W_proximal_preprocess Ran
ran; our contract draft was wrong, not the code
aozhongzhang/magr/MagR.py
code served (permissive licence) · get_code("a8ed3fb78e40f429")
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) and returned Tensor, ndim 2, dtype family float, shape (3, 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 small tensors with distinct dimensions
# W: weight matrix (n, m) where m is feature dim, n is output dim
W = torch.randn(3, 4)

# X: data matrix (m, n) where m is number of samples, n is feature dim
X = torch.randn(5, 4)

# device
device = torch.device('cpu')

# alpha: regularization parameter
alpha = 0.001

# n_iter: number of iterations
n_iter = 200

ARGS = {
    'W': W,
    'X': X,
    'device': device,
    'alpha': alpha,
    'n_iter': n_iter
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
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 (3, 4) — shape (3, 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
W_proximal_preprocess Ran
ran; our contract draft was wrong, not the code
aozhongzhang/magr/MagR.py
code served (permissive licence) · get_code("6001858533db7499")
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) and returned Tensor, ndim 2, dtype family float, shape (4, 3) 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)

# W_proximal_preprocess parameters:
# - W: weight matrix to be processed
# - X: data matrix
# - device: torch device
# - alpha: regularization parameter (default 0.001)
# - n_iter: number of iterations (default 200)

# Create small tensors
# W should be a weight matrix, let's make it (4, 3)
W = torch.randn(4, 3)

# X should be a data matrix with shape (m, n)
# The function uses SVD and matrix multiplications
# Let's make it (5, 3) so m > n for variety
X = torch.randn(5, 3)

# device - CPU only
device = torch.device('cpu')

# alpha - small float for regularization
alpha = 0.001

# n_iter - number of iterations
n_iter = 10  # reduced from 200 for speed

ARGS = {
    'W': W,
    'X': X,
    'device': device,
    'alpha': alpha,
    'n_iter': n_iter
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
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 (4, 3) — shape (4, 3) 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
find_layers Ran
ran; our contract draft was wrong, not the code
AozhongZhang/MagR/modelutils.py
pointer only (licence: MIT); the stored copy get_code serves, from squeezeailab/kvquant, is pointer only (licence: NONE) · get_code("a9e7f2cdf016b88b")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from squeezeailab/kvquant, and GitHub detected no licence in that repository when it was checked. 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_llama Ran
ran; our contract draft was wrong, not the code
aozhongzhang/magr/llama.py
code served (permissive licence) · get_code("88d590323ed219c8")
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) and returned MockLlamaForCausalLM. 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
from unittest.mock import Mock, patch
import sys

torch.manual_seed(0)

# Create a mock LlamaForCausalLM class since we can't download the real model
class MockLlamaForCausalLM:
    def __init__(self, *args, **kwargs):
        self.seqlen = None
    
    @classmethod
    def from_pretrained(cls, model_name, torch_dtype=None):
        return cls()

# Patch the transformers import to return our mock
mock_transformers = Mock()
mock_transformers.LlamaForCausalLM = MockLlamaForCausalLM
sys.modules['transformers'] = mock_transformers

# The function expects a model identifier string (HuggingFace model name)
# We'll pass a simple string identifier
ARGS = {
    'model': 'meta-llama/Llama-2-7b'
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
torch, transformers — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type MockLlamaForCausalLM — a MockLlamaForCausalLM output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a MockLlamaForCausalLM 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_wikitext2 Ran
ran; our contract draft was wrong, not the code
AozhongZhang/MagR/datautils.py
code served (permissive licence) · get_code("8f69762e4b3ffac1")
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 random

torch.manual_seed(0)
random.seed(0)

# The function uses:
# - nsamples: int, number of samples to generate
# - seed: int, random seed
# - seqlen: int, sequence length
# - model: string, model name (used only for tokenizer initialization)

# We need to mock the tokenizer and dataset loading since we can't download
# We'll create a minimal setup that bypasses the actual downloads

class MockTokenizer:
    def __call__(self, text, return_tensors=None):
        # Return a mock tokenized output with input_ids attribute
        # Make it large enough to sample from with seqlen
        input_ids = torch.randint(0, 1000, (1, 500))
        class TokenOutput:
            pass
        output = TokenOutput()
        output.input_ids = input_ids
        return output

class MockDataset:
    def __init__(self):
        self.data = {'text': ['sample text ' + str(i) for i in range(10)]}
    
    def __getitem__(self, key):
        return self.data[key]

# Monkey patch the imports to avoid network calls
import sys
from unittest.mock import MagicMock, patch

# Create mock modules
mock_datasets = MagicMock()
mock_datasets.load_dataset = MagicMock(return_value=MockDataset())

mock_transformers = MagicMock()
mock_transformers.AutoTokenizer.from_pretrained = MagicMock(return_value=MockTokenizer())

sys.modules['datasets'] = mock_datasets
sys.modules['transformers'] = mock_transformers

# Now define the arguments
ARGS = {
    'nsamples': 3,
    'seed': 42,
    'seqlen': 10,
    'model': 'gpt2'
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
datasets, torch, transformers — 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
linfty_proximal Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
aozhongzhang/magr/MagR.py
code served (permissive licence) · get_code("084f259f69174cdb")
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) 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 batch of tensors
# batch_size=2, feature_dim=4
x = torch.randn(2, 4)

# Scale parameter for the proximal operator
scale = 0.5

ARGS = {
    "x": x,
    "scale": scale,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
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
project_onto_l1_ball Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
aozhongzhang/magr/MagR.py
code served (permissive licence) · get_code("b9cfc2841388777e")
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) 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 batch of tensors to project
# batch_size=2, flattened dimension=4
x = torch.randn(2, 4)

# Set the L1 ball radius
eps = 1.0

ARGS = {
    "x": x,
    "eps": eps,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
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 Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
AozhongZhang/MagR/quant.py
code served (permissive licence) · get_code("41c57e55d21c4d96")
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 tensor for x (batch_size=2, features=4)
x = torch.randn(2, 4)

# Create scalar scale parameter
scale = torch.tensor(0.1)

# Create scalar zero parameter
zero = torch.tensor(0.0)

# Create integer maxq parameter (positive value for normal quantization)
maxq = 255

ARGS = {
    "x": x,
    "scale": scale,
    "zero": zero,
    "maxq": maxq,
}
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
get_c4_llama3 Not yet run
unverified (harvested, no recorded run)
AozhongZhang/MagR/datautils.py
code served (permissive licence) · get_code("93e54184e6ad61a5")
How it ran

no invocation recorded.

get_ptb Not yet run
unverified (harvested, no recorded run)
AozhongZhang/MagR/datautils.py
pointer only (licence: MIT); the stored copy get_code serves, from hartvigsen-group/composable-interventions, is pointer only (licence: NONE) · get_code("3a6ac4325dad94a4")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from hartvigsen-group/composable-interventions, and GitHub detected no licence in that repository when it was checked. 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. No invocation recorded.

llama_pack3 Not yet run
unverified (harvested, no recorded run)
aozhongzhang/magr/llama.py
code served (permissive licence) · get_code("f48c13b1095354d2")
How it ran

no invocation recorded.

llama_sequential Not yet run
unverified (harvested, no recorded run)
aozhongzhang/magr/llama.py
code served (permissive licence) · get_code("8a49f06400cfa533")
How it ran

no invocation recorded.

Also present in other papers' code

Of 12 samples lifted from this paper's linked repositories, 12 carry a function identity and 0 do not. Of the 11 distinct functions with an identity, 5 are also present in other papers whose code we hold (4 with at least one paper dated earlier, 3 the same month, 4 later) and 6 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
find_layers 27 other papers
15 dated earlier, 2 the same month, 8 later, 1 same year, order not determinable, 1 undated
2203.13474 (2022-03)
CodeGen: An Open Large Language Model for Code with Multi-Turn Program Synthesis
2023.emnlp-main.892 (2023 (year only))
Z-FOLD: A Frustratingly Easy Post-Training Quantization Scheme for LLMs
2307.09288 (2023-07)
Llama 2: Open Foundation and Fine-Tuned Chat Models
and 24 more not named here
quantize 9 other papers
4 dated earlier, 1 the same month, 3 later, 1 undated · 1 only as an assembly brick
2210.17323 (2022-10)
GPTQ: Accurate Post-Training Quantization for Generative Pre-trained Transformers
2023.emnlp-main.892 (2023 (year only))
Z-FOLD: A Frustratingly Easy Post-Training Quantization Scheme for LLMs
2312.05215 (2023-12)
DeltaZip: Efficient Serving of Multiple Full-Model-Tuned LLMs
and 6 more not named here
get_llama 5 other papers
2 dated earlier, 1 the same month, 1 later, 1 same year, order not determinable
2307.15290 (2023-07)
ChatHome: Development and Evaluation of a Domain-Specific Language Model for Home Renovation
2310.09499 (2023-10)
One-Shot Sensitivity-Aware Mixed Sparsity Pruning for Large Language Models
2024.findings-naacl.145 (2024 (year only))
Role Prompting Guided Domain Adaptation with General Capability Preserve for Large Language Models
and 2 more not named here
get_ptb 1 other paper
1 later
2407.06483 (2024-07)
Composable Interventions for Language Models
llama_sequential 1 other paper
1 dated earlier
2302.13971 (2023-02)
LLaMA: Open and Efficient Foundation Language Models

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

In this paper, we present a simple optimization-based preprocessing technique called Weight Magnitude Reduction (MagR) to improve the performance of posttraining quantization. For each linear layer, we adjust the pre-trained floating-point weights by solving a channel-wise ℓ ∞ -regularized optimization problem. This process greatly diminishes the maximum magnitude of the weights and smooths out outliers, while preserving the layer's output. The preprocessed weights exhibit reduced range, which facilitates the subsequent quantization process. To implement MagR, we address the ℓ ∞ -regularization by employing an efficient proximal gradient descent algorithm. Unlike existing preprocessing methods that involve linear transformations and subsequent post-processing steps, which can introduce significant overhead at inference time, MagR functions as a non-linear transformation, eliminating the need for any additional post-processing. This ensures that MagR introduces no overhead whatsoever during inference. Our experiments demonstrate that MagR achieves state-of-the-art performance on the Llama family of models. For example, we achieve a Wikitext2 perplexity of 5.95 on the LLaMA2-70B model for per-channel INT2 weight quantization without incurring any inference overhead. The code is available at https://github.com/AozhongZhang/MagR

For agents

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

get_harvested_code_for_paper("2406.00800")
get_code_for_paper("2406.00800")
have("2406.00800")

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

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

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

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

Connect an agent — have() is free.