rotary-embedding-torch
Rotary Embedding - Pytorch
What it is and what it does
Rotary Embedding Torch is a standalone library that adds rotary positional embeddings (RoPE) to transformer attention mechanisms in PyTorch. It provides efficient methods to encode position information by rotating query and key tensors, supporting both fixed and learned positional encodings along any tensor axis. The library implements several variants including standard rotary embeddings, axial embeddings for multi-dimensional data like video, length-extrapolatable embeddings (XPos) for handling sequences longer than training length, and fused Flash Attention kernels that compute attention with rotary embeddings in a single pass.
The package depends on torch and einops for tensor operations and is designed to integrate directly into transformer implementations at the attention layer level. It supports inference optimizations like key-value cache handling and includes options for sequence position interpolation to extend context windows. The library is actively maintained and carries no known security vulnerabilities.
Use it for:
- Adding rotary positional encoding to standard transformer attention layers during training and inference.
- Extending transformer context length beyond training sequence length using XPos or interpolation techniques.
- Implementing multi-dimensional positional embeddings for video or image transformers using axial rotary embeddings.
- Optimizing attention computation with fused Flash Attention kernels that incorporate rotary embeddings.
- Fine-tuning pretrained models to handle longer sequences via position interpolation.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Implements rotary positional embeddings for transformer attention layers in PyTorch, enabling efficient encoding of absolute and relative position information along any tensor axis.
Yes. The package is actively maintained, has low install friction, carries no known vulnerabilities, and provides a well-documented implementation of a proven positional encoding technique. It is suitable for production transformer projects that need rotary embeddings or their variants, particularly when extending context length or working with multi-dimensional data.
Install
rotary-embedding-torch on PyPI
pip
pip install rotary-embedding-torchuv
uv add rotary-embedding-torchpoetry
poetry add rotary-embedding-torchInstalling rotary-embedding-torch
Before you install
Low friction installation with only two runtime dependencies (einops and torch). Actively maintained with a recent release within the last two months.
License in practice
MIT license permits unrestricted use, modification, and distribution in both open-source and commercial projects with minimal obligations.
Quickstart
pip install rotary-embedding-torch
import torch
from rotary_embedding_torch import RotaryEmbedding
rotary_emb = RotaryEmbedding(dim=32)
q = torch.randn(1, 8, 1024, 64)
k = torch.randn(1, 8, 1024, 64)
q = rotary_emb.rotate_queries_or_keys(q)
k = rotary_emb.rotate_queries_or_keys(k)
Requires PyTorch and einops; Python 3.9 or later.
Verify before relying
- Whether the fused Flash Attention kernel with rotary embeddings requires Triton to be installed separately or if fallback is automatic.
- Performance characteristics and memory overhead compared to other positional encoding schemes in production transformer models.
- Compatibility with specific transformer architectures beyond the general attention pattern described.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — einops, torch |
| Maintenance | actively maintained — 55 days since the last release |
| First released | |
| Downloads | 714,094/month — #5,249 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: rotary_embedding_torch-0.9.1-py3-none-any.whl
Keywords: artificial intelligence, deep learning, positional embedding
Tags
More Artificial Intelligence packages
LiteLLM provides a unified Python interface to…
permissive · top 100 on PyPI
huggingface-hubClient library and CLI tool for downloading,…
permissive · top 100 on PyPI
langchainLangChain provides a framework for building…
permissive · top 1,000 on PyPI
hf-xethf-xet provides chunk-based deduplication and…
permissive · top 1,000 on PyPI
tokenizersTokenizers converts raw text into token…
permissive · top 1,000 on PyPI
transformersTransformers provides a unified framework for…
permissive · top 1,000 on PyPI
axial-positional-embeddingProvides axial positional embeddings for…
permissive · top 15,000 on PyPI
vit-pytorchProvides PyTorch implementations of Vision…
permissive · top 15,000 on PyPI
CoLT5-attentionImplements conditionally routed efficient…
permissive · top 15,000 on PyPI
vector-quantize-pytorchImplements vector quantization layers for…
permissive · top 5,000 on PyPI
torch-einops-utilsProvides utility functions for PyTorch and…
permissive · top 15,000 on PyPI
x-transformersx-transformers provides modular transformer…
permissive · top 5,000 on PyPI
entmaxEntmax provides PyTorch implementations of…
permissive · top 15,000 on PyPI
local-attentionImplements local windowed attention for…
permissive · top 15,000 on PyPI
torchPyTorch provides GPU-accelerated tensor…
permissive · top 1,000 on PyPI
conformerProvides PyTorch implementations of the…
permissive · top 15,000 on PyPI