Skip to main content

Attention mechanisms from Every_Thing_About_Transformer, as an importable library

Project description

transformer-lib

Attention mechanisms from Every_Thing_About_Transformer, as an importable Python library.

Installation

pip install -e .

Usage

from transformer_lib import MultiHeadAttention
import torch

mha = MultiHeadAttention(embed_dim=512, num_heads=8)
x = torch.randn(2, 10, 512)
out = mha(x, x, x)

Available Modules

Module Description
SelfAttention Basic scaled dot-product self-attention
MultiHeadAttention Multi-head attention with separate Q/K/V projections
CausalAttention Multi-head with lower-triangular causal mask
CrossAttention Encoder-decoder cross-attention with self-attention pre-step
GlobalAttention Additive (Bahdanau-style) alignment scoring
MultiQueryAttention Shared K/V across all heads
GroupedQueryAttention Groups of query heads sharing K/V (GQA)
MultiHeadLatentAttention Latent-space compression for keys/values

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

transformer_lib-0.1.0.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

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

transformer_lib-0.1.0-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file transformer_lib-0.1.0.tar.gz.

File metadata

  • Download URL: transformer_lib-0.1.0.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for transformer_lib-0.1.0.tar.gz
Algorithm Hash digest
SHA256 aaa0f4b2bfd1bceab6d0a3d77306fe6325ed5de692d36237a7e01bd3253a3734
MD5 12a4022ca99d65f84581e78d1c6f1d4c
BLAKE2b-256 45bcacf7bb5f4947d12704a08fb63666145cf044866111f6138cda9fd70f104e

See more details on using hashes here.

File details

Details for the file transformer_lib-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for transformer_lib-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b0f1c563485d20d57090ec6f0018ccbf7142453668ca89e13296d038f38df103
MD5 1299733200c39cab912f8ea0557b0d22
BLAKE2b-256 18a95c9dc5ab70d93b42d19fb5a998d86deb4fde3f49e5678f7c151c090a758e

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