pykernsformer
The pykernsformer module extends the torch.nn.TransformerEncoderLayer class to include custom attention formulas.
Installation
You can install the pykernsformer package using pip as
pip install pykernsformer
Usage
pykernsformer comes with the following built in attention kernels.
| pykernsformer | Attention | Formula | Citation |
|---|---|---|---|
attention |
Regular | $softmax(\frac{QK^T}{\sqrt{d_k}})V$ | Vaswani et al. |
attention_linear |
Linear | $\frac{QK^T}{\sum_k QK^T}V$ | |
attention_periodic |
Periodic | $softmax(-\frac{2\sin^2(\pi\frac{\sqrt{2 - 2q_ik_j^T}}{p})}{\sqrt{d_k}})V$ | |
attention_LP |
Locally Periodic | $softmax(-\frac{2\sin^2(\pi\frac{\sqrt{2 - 2\hat{q}_i\hat{k}_j^T}}{p})}{\sqrt{d_k}} + \frac{{q_i}{k_j^T}}{\sqrt{d_k}})V$ | |
attention_RQ |
Rational Quadratic | $\frac{\left( 1 + \frac{1}{\alpha \sqrt{d_k}} - \frac{2QK^T}{2 \alpha \sqrt{d_k}} \right)^{-\alpha}}{\sum_k \left( 1 + \frac{1}{\alpha \sqrt{d_k}} - \frac{2QK^T}{2 \alpha \sqrt{d_k}} \right)^{-\alpha}}V$ |
You can also implement your own attention function with the following signature:
def attention_custom(query, key, value, mask=None, dropout=None):
[...]
p_attn = [...] # the attention matrix
[...]
return torch.matmul(p_attn, value), p_attn
Metadata
Release files for pykernsformer 0.0.4
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 | Actions |
|---|---|---|---|---|
| pykernsformer-0.0.4.tar.gz | 2.7 kB | Without provenance | Details for pykernsformer-0.0.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pykernsformer-0.0.4-py3-none-any.whl | Python 3 | none | any | Details for pykernsformer-0.0.4-py3-none-any.whl |
Total release size: 5.5 kB
Release files / pykernsformer-0.0.4.tar.gz
| Download URL | pykernsformer-0.0.4.tar.gz |
|---|---|
| Size | 2.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
156dc0f62a652adf97d593d6457e3cd3301ab5ee09b6a046057766e23d8b64a7
|
|
BLAKE2b-256 checksum How to use checksums |
226f749f7b77f7b073f84d0a1d14db3a5e5340e7acc9076748c0ad01ad50f74f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.7.10
|
Release files / pykernsformer-0.0.4-py3-none-any.whl
| Download URL | pykernsformer-0.0.4-py3-none-any.whl |
|---|---|
| Size | 2.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3609a2dc2ea652219983ffee48bd298a0b1eaa8e9d037327cfacea76b4b94bce
|
|
BLAKE2b-256 checksum How to use checksums |
4c1dc054a9bc3f7d56100e049c6c27ad4ebd053ab19f49cb4327bb5c5f383b8e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.7.10
|
Security for pykernsformer 0.0.4
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.