Tamp reduces the space and time cost of deep neural networks by replacing their dense weight matrices with structured transforms (circulant, Toeplitz, skew-circulant, low-rank, ACDC, …), making large models more practical on resource-limited devices. It accompanies the paper Tamp: A Library for Compact Deep Neural Networks with Structured Matrices (ACM Multimedia 2016).
Each transform is implemented once in a framework-agnostic C++ core (structured/) and exposed two ways:
- a TensorFlow custom op (
structured/interface/tensorflow/), used by the CIFAR-10 models inmodels/; - a Caffe layer (
structured/interface/caffe/), used with the forked Caffe in thecaffe/submodule.
See CLAUDE.md for the architecture and developer reference.
This is a legacy research toolchain: Python 2, TensorFlow 0.x/1.0-era, gcc-4.9 / gcc-5, CUDA (nvcc), and either Intel MKL or CBLAS/ATLAS + FFTW + protobuf. Run all build scripts from the repository root.
Install TensorFlow (a virtualenv install is recommended) and activate it:
$ source ~/tensorflow/bin/activate
Build the custom op (CBLAS/ATLAS + FFTW). This emits layer_op.so at the repository root:
$ ./scripts/build_tensorflow-cblas.sh
A standalone CUDA core library (libtampp.so, Intel MKL) can instead be built with ./scripts/acquire_processor.sh (which sources scripts/build_workflow.sh for the MKL paths and GPU arch flags).
Then train and evaluate a model from inside its directory — the relative imports and ../../*.so paths require it:
$ cd models/cifar10_circulant
$ python cifar10_train.py # train (single GPU; see cifar10_multi_gpu_train.py for multi-GPU)
$ python cifar10_eval.py # evaluate
Note: each model's layer_op.py loads a specific .so filename (e.g. ../../circ_op_sq.so). Symlink or rename the built .so to the name the model expects, or edit layer_op.py.
The forked Caffe in caffe/ is required — vanilla Caffe has no interface for Tamp-style plugins. Initialize the submodule first:
$ git submodule update --init --recursive
Follow the Caffe install instructions to build it (this also generates the protocol-buffer headers Tamp integrates against). Then build the Tamp Caffe core and the C++ tool harnesses:
$ ./scripts/build_caffe-cores.sh # -> libtampc.so (Caffe-bound core)
$ ./scripts/build_caffe-tools.sh # builds the tools/ harnesses against Caffe
Enable Tamp by adding the built library to USE_TAMP in Caffe's Makefile.config and rebuilding Caffe.
models/cifar10_<transform>/ each fork the TensorFlow CIFAR-10 tutorial, replacing the fully-connected layers with the Tamp op for one structured transform: circulant, toep (Toeplitz), skew (skew-circulant), lowrank, and acdc. See each directory's README.md.
If you use Tamp in your research, please cite:
B. Gong, B. Jou, F. Yu, and S.-F. Chang. Tamp: A Library for Compact Deep Neural Networks with Structured Matrices. In Proceedings of the 24th ACM International Conference on Multimedia (MM '16), pp. 1206–1209, 2016. https://dl.acm.org/doi/10.1145/2964284.2973802
@inproceedings{gong2016tamp,
title = {Tamp: A Library for Compact Deep Neural Networks with Structured Matrices},
author = {Gong, Bingchen and Jou, Brendan and Yu, Felix and Chang, Shih-Fu},
booktitle = {Proceedings of the 24th ACM International Conference on Multimedia (MM '16)},
pages = {1206--1209},
year = {2016},
doi = {10.1145/2964284.2973802}
}Tamp's original code is released under the GNU General Public License v3.0 — Copyright (C) 2016–2017 Bingchen Gong.
Incorporated third-party components keep their own (GPLv3-compatible) licenses:
- the
caffe/submodule and the Caffe-derived code instructured/— BSD 2-Clause (BVLC), with DeepLab additions (© George Papandreou et al.); - the TensorFlow CIFAR-10 models under
models/— Apache License 2.0 (© Google); structured/lib/stringtoargcargv.cpp— © 2011 Bernhard Eder.