Skip to main content

Another attention variant

Project description

kl-div-attention

Just another attention variant, where the query key distance uses KL divergence, for testing Gitlab workflow

Install

$ pip install kl-div-attention

Usage

import torch
from kl_div_attention import KLDivAttention

attn = KLDivAttention(
    dim = 512,
    heads = 8,
    dim_head = 64,
    causal = True,
    prenorm = True, 
    fused_mode = 'flash'    # use fused triton flash attention
).cuda()

tokens = torch.randn(1, 1024, 512).cuda()

out = attn(tokens) + tokens

assert out.shape == tokens.shape

Training

You can train a small transformer on Enwik8 with KL-divergence attention using the provided training script.

Eg. to use the fused Triton kernel and reverse KL divergence

$ uv run train_enwik8.py --fused-mode flash

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kl_div_attention-0.1.1.tar.gz (36.6 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kl_div_attention-0.1.1-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file kl_div_attention-0.1.1.tar.gz.

File metadata

  • Download URL: kl_div_attention-0.1.1.tar.gz
  • Upload date:
  • Size: 36.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for kl_div_attention-0.1.1.tar.gz
Algorithm Hash digest
SHA256 3a358d85542d7bf8c95c8e89ac48d6746426cdcc39c88b011634bc1caffe727d
MD5 9574ae2b53698594c40ba2af7249db63
BLAKE2b-256 4c94f6e6a95c8c45c7e70fa273dba1e1a3eb1bfbdde6ee60bcc6165550a146e9

See more details on using hashes here.

File details

Details for the file kl_div_attention-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for kl_div_attention-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b3f10adabc356c5e039d686c436d1e1e3956e977044d0ae4ab6d43a07f9a4705
MD5 25faa76e55cc07c6d2daa3470a3f8b2d
BLAKE2b-256 ed28a00513f08971a3a19afde568c0e0d17abd996c6a7602f0968a9737c6f23b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page