long-context_skill

This skill helps extend transformer context windows for long documents using RoPE, YaRN, ALiBi, and position interpolation to improve efficiency and
  • TeX

5.2k

GitHub Stars

1

Bundled Files

2 months ago

Catalog Refreshed

4 months ago

First Indexed

Readme & install

Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.

Installation

Preview and clipboard use veilstrat where the catalogue uses aiagentskills.

npx veilstrat add skill orchestra-research/ai-research-skills --skill long-context

  • SKILL.md15.2 KB

Overview

This skill packages practical techniques for extending transformer context windows using RoPE, YaRN, ALiBi and position interpolation. It targets engineers and researchers who need to process very long sequences (32k–128k+ tokens) or extend pre-trained models with minimal fine-tuning. The content focuses on actionable implementations, integration patterns, and trade-offs for production and research use.

How this skill works

The skill implements and explains rotary position embeddings (RoPE) and their scaling, YaRN NTK-aware interpolation, ALiBi attention biases, and linear position interpolation. It provides code patterns for applying rotary embeddings to Q/K, generating ALiBi slopes and biases, and updating model configs for rope_scaling. It also covers fine-tuning recipes and incremental scaling strategies to preserve quality when increasing context length.

When to use it

  • Processing very long documents (32k, 64k, 128k+ tokens).
  • Extending pre-trained RoPE-based models (LLaMA, Mistral) beyond their original context limits.
  • Implementing efficient positional encodings for new models or research experiments.
  • Fine-tuning models for length extrapolation with minimal compute.
  • Deploying models that must handle variable-length inputs efficiently in production.

Best practices

  • Choose method by use case: ALiBi for new models, YaRN for efficient extension of existing RoPE models, interpolation for quick low-cost extension.
  • Scale gradually: incrementally increase context (e.g., 8k→16k→32k) and fine-tune at each step to avoid instability.
  • Prefer long-document training data matching target lengths; avoid relying on short-document corpora when training for long context.
  • Use conservative scaling factors for quality; larger factors need more fine-tuning steps (rough rule: steps ≈ 100 × factor).
  • Combine memory optimizations (gradient checkpointing, FlashAttention, vLLM paging) when fine-tuning or serving long contexts.

Example use cases

  • Extend LLaMA-2-7B to 32k tokens via rope_scaling and 1k fine-tuning steps for long-document QA.
  • Use YaRN to push a pretrained model to 128k context with fewer fine-tuning steps than baseline interpolation.
  • Deploy an ALiBi-trained model in a streaming chat service to bias attention toward recency with lower memory use.
  • Implement custom long-context attention layer that applies RoPE to Q/K and integrates with FlashAttention for efficient inference.
  • Fine-tune a model on concatenated book chapters or arXiv papers to improve long-range coherence.

FAQ

Position interpolation or aggressive rope scaling will usually degrade quality unless followed by fine-tuning; minimal fine-tuning (e.g., ~1k steps) is recommended for modest extensions.

Which method has the best extrapolation?

ALiBi provides strong extrapolation for models trained from scratch. YaRN offers excellent extrapolation when extending pretrained RoPE models with fewer steps.

How to pick scaling factor?

Start conservatively (×2–×4). Larger factors (×8, ×16) require more fine-tuning and incremental scaling to maintain stability.

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational
long-context skill by orchestra-research/ai-research-skills | VeilStrat