SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 1612.01064 · 2016

Trained Ternary Quantization

arXiv · PDF · Open in the Atlas

Code that ran

5 of 7 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; 1 honoured the contract we drafted, 0 violated it and 0 have no contract verdict; 4 failures of our instrument; 2 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/1612.01064.json · badge: /api/ran/1612.01064.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
yamilvindas/aTTQ extension (classifier label)
classifier basis: classifier_2025
2 ran · 1 no recorded run
vinsis/ternary-quantization reimplementation (classifier label)
classifier basis: classifier_2025
2 ran · 0 no recorded run
czhu95/ternarynet reimplementation (classifier label)
classifier basis: classifier_2025
1 ran · 1 no recorded run
FunctionStatusWhere it lives
computeMeanMetricsLastEpochs Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
yamilvindas/aTTQ/src/utils/plot_results_classification.py
pointer only (licence: NOASSERTION) · get_code("bd0565df4c59e38b")
How it ran

The body of this sample is withheld: GitHub could not classify the licence of this paper's repository, yamilvindas/aTTQ (NOASSERTION). 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_data Ran
ran; our contract draft was wrong, not the code
czhu95/ternarynet/examples/Ternary-Net/tw-cifar10-resnet.py
code served (permissive licence) · get_code("262b8057646d1be3")
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 PrefetchData. 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 numpy as np
from unittest.mock import Mock, MagicMock

torch.manual_seed(0)

# Mock the dataset module and related classes
class MockCifar10:
    def __init__(self, train_or_test):
        self.train_or_test = train_or_test
        self.data = [(np.random.rand(32, 32, 3).astype(np.float32), np.random.randint(0, 10)) for _ in range(10)]
    
    def get_per_pixel_mean(self):
        return np.random.rand(32, 32, 3).astype(np.float32)
    
    def __len__(self):
        return len(self.data)
    
    def __getitem__(self, idx):
        return self.data[idx]

class MockImgAug:
    def __init__(self, *args, **kwargs):
        self.args = args
        self.kwargs = kwargs
    
    def __call__(self, x):
        return x

class CenterPaste(MockImgAug):
    pass

class RandomCrop(MockImgAug):
    pass

class Flip(MockImgAug):
    pass

class MapImage(MockImgAug):
    def __init__(self, func):
        self.func = func
    
    def __call__(self, x):
        return self.func(x)

class AugmentImageComponent:
    def __init__(self, ds, augmentors):
        self.ds = ds
        self.augmentors = augmentors
    
    def __len__(self):
        return len(self.ds)
    
    def __getitem__(self, idx):
        data = self.ds[idx]
        return data

class BatchData:
    def __init__(self, ds, batch_size, remainder=False):
        self.ds = ds
        self.batch_size = batch_size
        self.remainder = remainder
    
    def __len__(self):
        return len(self.ds) // self.batch_size
    
    def __iter__(self):
        for i in range(len(self)):
            yield [self.ds[j] for j in range(i * self.batch_size, min((i + 1) * self.batch_size, len(self.ds)))]

class PrefetchData:
    def __init__(self, ds, prefetch_size, num_workers):
        self.ds = ds
        self.prefetch_size = prefetch_size
        self.num_workers = num_workers
    
    def __len__(self):
        return len(self.ds)
    
    def __iter__(self):
        return iter(self.ds)

# Create mock modules
dataset = Mock()
dataset.Cifar10 = MockCifar10

imgaug = Mock()
imgaug.CenterPaste = CenterPaste
imgaug.RandomCrop = RandomCrop
imgaug.Flip = Flip
imgaug.MapImage = MapImage

# Inject mocks into the function's namespace
import sys
current_module = sys.modules[__name__]
setattr(current_module, 'dataset', dataset)
setattr(current_module, 'imgaug', imgaug)
setattr(current_module, 'AugmentImageComponent', AugmentImageComponent)
setattr(current_module, 'BatchData', BatchData)
setattr(current_module, 'PrefetchData', PrefetchData)

ARGS = {
    'train_or_test': 'train'
}
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 PrefetchData — a PrefetchData output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a PrefetchData 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_quantization_grads Ran
ran; our contract draft was wrong, not the code
vinsis/ternary-quantization/quantification.py
code served (permissive licence) · get_code("b834150b9d445a4f")
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 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

torch.manual_seed(0)

# Create small tensors with distinct sizes for different dimensions
batch_size = 2
dim = 4

# grad_data: gradient tensor
grad_data = torch.randn(batch_size, dim)

# full_precision_data: full precision weights
full_precision_data = torch.randn(batch_size, dim)

# w_p_data: positive weight scaling factor
w_p_data = torch.tensor(1.5)

# w_n_data: negative weight scaling factor
w_n_data = torch.tensor(0.8)

# threshold: quantization threshold (optional, has default)
threshold = 0.15

ARGS = {
    "grad_data": grad_data,
    "full_precision_data": full_precision_data,
    "w_p_data": w_p_data,
    "w_n_data": w_n_data,
    "threshold": threshold,
}
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 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_results_data Ran
ran; our contract draft was wrong, not the code
yamilvindas/aTTQ/src/utils/plot_results_classification.py
pointer only (licence: NOASSERTION) · get_code("0ba505651b8b7e1c")
How it ran

The body of this sample is withheld: GitHub could not classify the licence of this paper's repository, yamilvindas/aTTQ (NOASSERTION). 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.

quantize Ran
ran, honoured the contract we drafted
vinsis/ternary-quantization/quantification.py
code served (permissive licence) · get_code("d68f2c13b2387a62")
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 tensor for tensor_data
tensor_data = torch.randn(2, 4)

# Create scalar weights for w_p and w_n
w_p = 1.0
w_n = 1.0

# threshold uses the default value from the function signature
threshold = 0.15

ARGS = {
    "tensor_data": tensor_data,
    "w_p": w_p,
    "w_n": w_n,
    "threshold": threshold,
}
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
get_data Not yet run
unverified (harvested, no recorded run)
czhu95/ternarynet/examples/Ternary-Net/p-cifar10-resnet.py
code served (permissive licence) · get_code("6986da09c8c85488")
How it ran

no invocation recorded.

plotMeanMetrics Not yet run
unverified (harvested, no recorded run)
yamilvindas/aTTQ/src/utils/plot_results_classification.py
pointer only (licence: NOASSERTION) · get_code("cca5ba3ad019a6c9")
How it ran

The body of this sample is withheld: GitHub could not classify the licence of this paper's repository, yamilvindas/aTTQ (NOASSERTION). 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.

Also present in other papers' code

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

Deep neural networks are widely used in machine learning applications. However, the deployment of large neural networks models can be difficult to deploy on mobile devices with limited power budgets. To solve this problem, we propose Trained Ternary Quantization (TTQ), a method that can reduce the precision of weights in neural networks to ternary values. This method has very little accuracy degradation and can even improve the accuracy of some models (32, 44, 56-layer ResNet) on CIFAR-10 and AlexNet on ImageNet. And our AlexNet model is trained from scratch, which means it's as easy as to train normal full precision model. We highlight our trained quantization method that can learn both ternary values and ternary assignment. During inference, only ternary values (2-bit weights) and scaling factors are needed, therefore our models are nearly 16x smaller than full-precision models. Our ternary models can also be viewed as sparse binary weight networks, which can potentially be accelerated with custom circuit. Experiments on CIFAR-10 show that the ternary models obtained by trained quantization method outperform full-precision models of ResNet-32,44,56 by 0.04%, 0.16%, 0.36%, respectively. On ImageNet, our model outperforms full-precision AlexNet model by 0.3% of Top-1 accuracy and outperforms previous ternary models by 3%.

For agents

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

get_harvested_code_for_paper("1612.01064")
get_code_for_paper("1612.01064")
have("1612.01064")

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

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

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

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

Connect an agent — have() is free.