skillfed

rotary-embedding-torch

Rotary Embedding - Pytorch

rotary-embedding-torch v0.9.1 714.1K downloads/30d#5,249 on PyPI
Permissive license MIT Active released

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-torch

uv

uv add rotary-embedding-torch

poetry

poetry add rotary-embedding-torch

Installing 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

Development Status :: 4 - BetaIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseProgramming Language :: Python :: 3.6Topic :: Scientific/Engineering :: Artificial Intelligence

Tags

rotary positional embeddings pytorchrope transformer attentionposition encoding transformersrotary embeddings attention layerssequence position encoding pytorchtransformer positional encodingrelative position embeddings
transformerspositional-encodingattention-mechanism

More Artificial Intelligence packages

Further reading