TrAct - Training Activations
Official implementation for our NeurIPS 2024 paper TrAct: Making First-layer Pre-Activations Trainable. In this work, we provide TrAct, a method for more effective and efficient training of the first layer that accelerates training by between 25% and 300%. Herein, rather than using the training dynamics of training weight, we provide a closed form solution for training activations by indirectly updating weights, leading to faster and better training.
Video @ YouTube.
💻 Installation
TrAct can be installed via pip from PyPI with
pip install torch_tract
Alternatively, it is sufficient to copy the src/tract.py into your existing project.
👩💻 Usage
The tract.py file contains the TrAct wrapper, which replaces torch.nn.Linear and torch.nn.Conv2d modules by TrActLinear and TrActConv2d modules, respectively.
After initialization, simply wrap your first layer in a TrAct(layer, l=l), wherein l / λ is the only hyperparameter.
The default for this is l=0.1 and performs very well.
Please refer to the paper for additional information on the hyperparameter.
In the script, TrAct is implemented via:
# regular initialization of model
model = resnet18(num_classes=num_classes)
# apply TrAct to first layer
model.conv1 = TrAct(model.conv1, l=args.l)
Using the same change, it can also be applied to, e.g., ResNet training on ImageNet. Analogously, it can be applied for other codebases and experiments, e.g.:
# For CIFAR ViT: https://github.com/omihub777/ViT-CIFAR/
model.emb = TrAct(model.emb, l=args.l)
# For DeiT: https://github.com/facebookresearch/deit/
model.patch_embed.proj = TrAct(model.patch_embed.proj, l=args.l)
To reproduce the first seed of Figure 1, run:
python train_cifar.py --method normal --n_epochs 100 --lr 0.08 --optim sgd_w_momentum_cosine --seed 0
python train_cifar.py --method normal --n_epochs 200 --lr 0.08 --optim sgd_w_momentum_cosine --seed 0
python train_cifar.py --method normal --n_epochs 400 --lr 0.08 --optim sgd_w_momentum_cosine --seed 0
python train_cifar.py --method normal --n_epochs 800 --lr 0.08 --optim sgd_w_momentum_cosine --seed 0
python train_cifar.py --method tract --l 0.1 --n_epochs 100 --lr 0.08 --optim sgd_w_momentum_cosine --seed 0
python train_cifar.py --method tract --l 0.1 --n_epochs 200 --lr 0.08 --optim sgd_w_momentum_cosine --seed 0
python train_cifar.py --method tract --l 0.1 --n_epochs 400 --lr 0.08 --optim sgd_w_momentum_cosine --seed 0
python train_cifar.py --method tract --l 0.1 --n_epochs 800 --lr 0.08 --optim sgd_w_momentum_cosine --seed 0
python train_cifar.py --method normal --n_epochs 100 --lr 0.010 --optim adam_cosine --seed 0
python train_cifar.py --method normal --n_epochs 200 --lr 0.010 --optim adam_cosine --seed 0
python train_cifar.py --method normal --n_epochs 400 --lr 0.001 --optim adam_cosine --seed 0
python train_cifar.py --method normal --n_epochs 800 --lr 0.001 --optim adam_cosine --seed 0
python train_cifar.py --method tract --l 0.1 --n_epochs 100 --lr 0.010 --optim adam_cosine --seed 0
python train_cifar.py --method tract --l 0.1 --n_epochs 200 --lr 0.010 --optim adam_cosine --seed 0
python train_cifar.py --method tract --l 0.1 --n_epochs 400 --lr 0.001 --optim adam_cosine --seed 0
python train_cifar.py --method tract --l 0.1 --n_epochs 800 --lr 0.001 --optim adam_cosine --seed 0
📖 Citing
@inproceedings{petersen2024tract,
title={TrAct: Making First-layer Pre-Activations Trainable},
author={Petersen, Felix and Borgelt, Christian and Ermon, Stefano},
booktitle={Conference on Neural Information Processing Systems (NeurIPS)},
year={2024}
}
License
TrAct is released under the MIT license. See LICENSE for additional details about it.
Metadata
Release files for torch-tract 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| torch_tract-1.0.0.tar.gz | 6.4 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| torch_tract-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.9 kB
Release files / torch_tract-1.0.0.tar.gz
| Download URL | torch_tract-1.0.0.tar.gz |
|---|---|
| Size | 6.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cf8d245d3738afbce9c07157fb9617ffe6bf418685094a52f27fccb34320378b
|
|
BLAKE2b-256 checksum How to use checksums |
d96193d3909492bbb173b96fce3e381fa29bcb6578f1f9980caf974a19d5a7a7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.6
|
Release files / torch_tract-1.0.0-py3-none-any.whl
| Download URL | torch_tract-1.0.0-py3-none-any.whl |
|---|---|
| Size | 6.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
87de498da4c54eae0702d94aaa4d5cee542ddaffd39e113ed51bd9096a92aba3
|
|
BLAKE2b-256 checksum How to use checksums |
1e0064645611f74fceb20fe6b1724ee670124316eda4423ae8981f94892476fa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.6
|
Security for torch-tract 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.