This is your go-to reference when you need to push transformer models beyond their trained context limits. It covers the four main techniques actually being used in production: RoPE for rotary position embeddings, YaRN for efficient extension up to 128k tokens, ALiBi for training-free extrapolation, and position interpolation for quickly adapting models like LLaMA from 2k to 32k contexts. The implementations are practical and the comparison table makes it easy to pick the right approach. If you're fine-tuning an existing model for longer documents, position interpolation or YaRN will save you compute. If you're training from scratch and want unlimited context, ALiBi is surprisingly simple and effective.

skills.sh installs
1K
GitHub stars
14.4K
last updated
Aug 21, 2026

Install

$ npx -y skills add orchestra-research/ai-research-skills --skill long-context --agent claude-code

Installs into .claude/skills of the current project.

Files

Long Context: Extending Transformer Context Windows

When to Use This Skill

Use Long Context techniques when you need to:

  • Process long documents (32k, 64k, 128k+ tokens) with transformer models
  • Extend context windows of pre-trained models (LLaMA, Mistral, etc.)
  • Implement efficient positional encodings (RoPE, ALiBi)
  • Train models with length extrapolation capabilities
  • Deploy models that handle variable-length inputs efficiently
  • Fine-tune existing models for longer contexts with minimal compute

Key Techniques: RoPE (Rotary Position Embeddings), YaRN, ALiBi (Attention with Linear Biases), Position Interpolation

Papers: RoFormer (arXiv 2104.09864), YaRN (arXiv 2309.00071), ALiBi (arXiv 2108.12409), Position Interpolation (arXiv 2306.15595)

Installation

# HuggingFace Transformers (includes RoPE, YaRN support)
pip install transformers torch

# For custom implementations
pip install einops  # Tensor operations
pip install rotary-embedding-torch  # Standalone RoPE

# Optional: FlashAttention for efficiency
pip install flash-attn --no-build-isolation

Quick Start

RoPE (Rotary Position Embeddings)

Sponsors

Details

Repository
github.com/orchestra-research/ai-research-skills
Categories
AI & Agent Building, Data Science & ML
First seen
Jun 3, 2026

More from orchestra-research/ai-research-skills

All 95
1orchestra-research avatarnanogptorchestra-research/ai-research-skillsEducational GPT implementation in ~300 lines. Reproduces GPT-2 (124M) on OpenWebText. Clean, hackable code for learning transformers. By Andrej Karpathy. Perfec1Kskills.sh installs
2orchestra-research avatarpytorch-fsdp2orchestra-research/ai-research-skillsAdds PyTorch FSDP2 (fully_shard) to training scripts with correct init, sharding, mixed precision/offload config, and distributed checkpointing. Use when models1Kskills.sh installs
3orchestra-research avatarmodal-serverless-gpuorchestra-research/ai-research-skillsServerless GPU cloud platform for running ML workloads. Use when you need on-demand GPU access without infrastructure management, deploying ML models as APIs, o1Kskills.sh installs
4orchestra-research avatarmoe-trainingorchestra-research/ai-research-skillsTrain Mixture of Experts (MoE) models using DeepSpeed or HuggingFace. Use when training large-scale models with limited compute (5× cost reduction vs dense mode1Kskills.sh installs
5orchestra-research avatarllama-factoryorchestra-research/ai-research-skillsExpert guidance for fine-tuning LLMs with LLaMA-Factory - WebUI no-code, 100+ models, 2/3/4/5/6/8-bit QLoRA, multimodal support1Kskills.sh installs
6orchestra-research avatarmodel-mergingorchestra-research/ai-research-skillsMerge multiple fine-tuned models using mergekit to combine capabilities without retraining. Use when creating specialized models by blending domain-specific exp1Kskills.sh installs