Simple Recurrent Units for Highly Parallelizable Recurrence
Project description
News
SRU++, a new SRU variant, is released. [tech report] [blog]
The experimental code and SRU++ implementation are available on the dev branch which will be merged into master later.
About
SRU is a recurrent unit that can run over 10 times faster than cuDNN LSTM, without loss of accuracy tested on many tasks.
Average processing time of LSTM, conv2d and SRU, tested on GTX 1070
Reference:
Simple Recurrent Units for Highly Parallelizable Recurrence [paper]
@inproceedings{lei2018sru,
title={Simple Recurrent Units for Highly Parallelizable Recurrence},
author={Tao Lei and Yu Zhang and Sida I. Wang and Hui Dai and Yoav Artzi},
booktitle={Empirical Methods in Natural Language Processing (EMNLP)},
year={2018}
}
When Attention Meets Fast Recurrence: Training Language Models with Reduced Compute [paper]
@article{lei2021srupp,
title={When Attention Meets Fast Recurrence: Training Language Models with Reduced Compute},
author={Tao Lei},
journal={arXiv preprint arXiv:2102.12459},
year={2021}
}
Requirements
Install requirements via pip install -r requirements.txt
.
Installation
From source:
SRU can be installed as a regular package via python setup.py install
or pip install .
.
From PyPi:
pip install sru
Directly use the source without installation:
Make sure this repo and CUDA library can be found by the system, e.g.
export PYTHONPATH=path_to_repo/sru
export LD_LIBRARY_PATH=/usr/local/cuda/lib64
Examples
The usage of SRU is similar to nn.LSTM
. SRU likely requires more stacking layers than LSTM. We recommend starting by 2 layers and use more if necessary (see our report for more experimental details).
import torch
from sru import SRU, SRUCell
# input has length 20, batch size 32 and dimension 128
x = torch.FloatTensor(20, 32, 128).cuda()
input_size, hidden_size = 128, 128
rnn = SRU(input_size, hidden_size,
num_layers = 2, # number of stacking RNN layers
dropout = 0.0, # dropout applied between RNN layers
bidirectional = False, # bidirectional RNN
layer_norm = False, # apply layer normalization on the output of each layer
highway_bias = -2, # initial bias of highway gate (<= 0)
)
rnn.cuda()
output_states, c_states = rnn(x) # forward pass
# output_states is (length, batch size, number of directions * hidden size)
# c_states is (layers, batch size, number of directions * hidden size)
Contributing
Please read and follow the guidelines.
Other Implementations
@musyoku had a very nice SRU implementaion in chainer.
@adrianbg implemented the first CPU version.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file sru-2.6.0.tar.gz
.
File metadata
- Download URL: sru-2.6.0.tar.gz
- Upload date:
- Size: 22.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.6.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e472e32bb3492d10faa121a29f985660c81fb649989924da90c8d1fcafd1152c |
|
MD5 | e67408b94e399b972e5544fb2d655bb2 |
|
BLAKE2b-256 | 40ca7537e0ef8c3361402b1787474f0960521d4de82673ab45c1f11909e1c7a1 |
File details
Details for the file sru-2.6.0-py3-none-any.whl
.
File metadata
- Download URL: sru-2.6.0-py3-none-any.whl
- Upload date:
- Size: 24.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.6.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bcb4d6c095145ffc564223067e60f5d8a6f363ba66de00a87de14faa9947058f |
|
MD5 | 9721f130eab26435b831a8f699838d4c |
|
BLAKE2b-256 | 905606bfae51fab82bae05567af7f43f22e0948fe06c76b06b77ae67846a6089 |