rotary-embedding-torch  by lucidrains

PyTorch library for rotary embeddings in transformers

Created 4 years ago
750 stars

Top 46.3% on SourcePulse

GitHubView on GitHub
Project Summary

This library provides a standalone PyTorch implementation of Rotary Embeddings (RoPE), a relative positional encoding technique that enhances Transformer models. It's designed for researchers and engineers seeking to improve sequence modeling performance with state-of-the-art positional encoding, offering benefits like efficient rotation of information along tensor axes and improved results with minimal overhead.

How It Works

Rotary Embeddings apply rotations to query and key vectors in attention mechanisms, encoding relative positional information directly into the attention scores. This approach is advantageous as it injects positional awareness without adding parameters or complexity to the model architecture, unlike absolute positional embeddings. The library supports standard RoPE, axial RoPE for multi-dimensional inputs (e.g., video), and length-extrapolatable variants like XPos and positional interpolation.

Quick Start & Requirements

  • Install: $ pip install rotary-embedding-torch
  • Requirements: PyTorch. No specific CUDA or Python version is mandated, but GPU acceleration is typical for Transformer workloads.
  • Usage: Import RotaryEmbedding and apply its rotate_queries_or_keys or rotate_queries_and_keys methods to query and key tensors before the attention dot product. See the README for detailed examples and inference caching.

Highlighted Details

  • Implements RoFormer, XPos (length extrapolation), and positional interpolation for context extension.
  • Supports axial rotary embeddings for multi-dimensional inputs like images and video.
  • Includes utility for key-value caching during inference to handle positional offsets.
  • Offers flexibility in choosing embedding dimensions and frequency configurations.

Maintenance & Community

The library is maintained by lucidrains, a prolific contributor to open-source AI research implementations. The README includes citations to key papers and community discussions, indicating active engagement with the research landscape.

Licensing & Compatibility

The library is released under the MIT license, permitting commercial use and integration into closed-source projects.

Limitations & Caveats

The README notes that the positional interpolation feature has received mixed community feedback regarding its effectiveness. The XPos implementation is noted as being suitable only for autoregressive transformers.

Health Check
Last Commit

1 month ago

Responsiveness

1 day

Pull Requests (30d)
0
Issues (30d)
0
Star History
14 stars in the last 30 days

Explore Similar Projects

Starred by Alex Yu Alex Yu(Research Scientist at OpenAI; Former Cofounder of Luma AI) and Phil Wang Phil Wang(Prolific Research Paper Implementer).

Cosmos-Tokenizer by NVIDIA

0.1%
2k
Suite of neural tokenizers for image and video processing
Created 10 months ago
Updated 7 months ago
Starred by Alex Yu Alex Yu(Research Scientist at OpenAI; Former Cofounder of Luma AI), Lianmin Zheng Lianmin Zheng(Coauthor of SGLang, vLLM), and
2 more.

HunyuanVideo by Tencent-Hunyuan

0.2%
11k
PyTorch code for video generation research
Created 9 months ago
Updated 3 weeks ago
Starred by Andrej Karpathy Andrej Karpathy(Founder of Eureka Labs; Formerly at Tesla, OpenAI; Author of CS 231n), Jiayi Pan Jiayi Pan(Author of SWE-Gym; MTS at xAI), and
15 more.

taming-transformers by CompVis

0.1%
6k
Image synthesis research paper using transformers
Created 4 years ago
Updated 1 year ago
Feedback? Help us improve.