--- id: rotary-embedding-torch version: "0.9.1" license: MIT license_treatment: permissive maintenance: active --- # rotary-embedding-torch — Rotary Embedding - Pytorch License: permissive · Maintenance: active · Downloads: 714.1K/mo ## 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 above — 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 pip install rotary-embedding-torch uv add rotary-embedding-torch 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_current - Install friction: low - Maintenance: active - Downloads: 714.1K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags rotary positional embeddings pytorch, rope transformer attention, position encoding transformers, rotary embeddings attention layers, sequence position encoding pytorch, transformer positional encoding, relative position embeddings, transformers, positional-encoding, attention-mechanism [View on SkillFed](https://skillfed.io/packages/rotary-embedding-torch) · [View on PyPI](https://pypi.org/project/rotary-embedding-torch/)