Skip to main content
QUICK REVIEW

[Paper Review] Giraffe: Adventures in Expanding Context Lengths in LLMs

Arka Pal, Deep Karkhanis|arXiv (Cornell University)|Aug 21, 2023
Topic ModelingComputer Science5 citations
TL;DR

This paper proposes Giraffe, a family of 13B parameter LLMs fine-tuned from LLaMA and LLaMA2 to extend context lengths up to 32k tokens using linear interpolation of rotary positional embeddings. The key finding is that linear scaling outperforms other methods, with further gains from increasing the scale factor at inference, while custom evaluation tasks reveal significant performance degradation beyond 24k tokens despite reasonable perplexity.

ABSTRACT

Modern large language models (LLMs) that rely on attention mechanisms are typically trained with fixed context lengths which enforce upper limits on the length of input sequences that they can handle at evaluation time. To use these models on sequences longer than the train-time context length, one might employ techniques from the growing family of context length extrapolation methods -- most of which focus on modifying the system of positional encodings used in the attention mechanism to indicate where tokens or activations are located in the input sequence. We conduct a wide survey of existing methods of context length extrapolation on a base LLaMA or LLaMA 2 model, and introduce some of our own design as well -- in particular, a new truncation strategy for modifying the basis for the position encoding. We test these methods using three new evaluation tasks (FreeFormQA, AlteredNumericQA, and LongChat-Lines) as well as perplexity, which we find to be less fine-grained as a measure of long context performance of LLMs. We release the three tasks publicly as datasets on HuggingFace. We discover that linear scaling is the best method for extending context length, and show that further gains can be achieved by using longer scales at evaluation time. We also discover promising extrapolation capabilities in the truncated basis. To support further research in this area, we release three new 13B parameter long-context models which we call Giraffe: 4k and 16k context models trained from base LLaMA-13B, and a 32k context model trained from base LLaMA2-13B. We also release the code to replicate our results.

Motivation & Objective

  • To evaluate and compare zero-shot context length extrapolation methods for LLMs trained on fixed-length sequences.
  • To develop and test novel positional encoding strategies, including a truncated basis, for extending context beyond the model's original training length.
  • To introduce and release three new long-context LLMs (Giraffe-4k, 16k, 32k) fine-tuned from base LLaMA and LLaMA2 models.
  • To create and release three new benchmark datasets (LongChat-Lines, FreeFormQA, AlteredNumericQA) to enable fine-grained evaluation of long-context performance.
  • To demonstrate that perplexity alone is insufficient for assessing long-context capabilities, and that task-specific benchmarks reveal critical performance degradation.

Proposed method

  • Fine-tuned base LLaMA and LLaMA2 models using linear interpolation of rotary positional embeddings (RoPE) with varying scale factors.
  • Proposed a new truncated basis for positional encodings to improve extrapolation beyond the original context length.
  • Evaluated methods using three new public datasets: LongChat-Lines (key-value retrieval), FreeFormQA, and AlteredNumericQA (question-answering on long documents).
  • Applied instruction fine-tuning (IFT) with a fixed prompt structure to ensure consistent evaluation across context lengths.
  • Used perplexity on a document corpus as a baseline metric, but emphasized its limitations in capturing long-context reasoning accuracy.
  • Released code and weights for three 13B models with 4k, 16k, and 32k context lengths on HuggingFace.

Experimental results

Research questions

  • RQ1Does linear interpolation of rotary positional embeddings provide the best zero-shot extrapolation performance for long-context LLMs compared to other methods like sinusoidal, learned, or scaled RoPE?
  • RQ2How does the placement of the question and answer within long context sequences affect model performance across different context lengths?
  • RQ3Can a truncated basis for positional encodings enable true extrapolation beyond the model's original context length, and how does it compare to linear scaling?
  • RQ4To what extent does perplexity correlate with actual long-context reasoning accuracy, and do custom benchmarks reveal performance degradation not captured by perplexity?
  • RQ5Can increasing the scale factor at inference time beyond the finetuning scale improve performance, and is there a limit to this improvement?

Key findings

  • Linear interpolation of rotary positional embeddings consistently outperformed other methods, including learned and sinusoidal positional encodings, across all evaluation tasks.
  • Performance degradation was observed on FreeFormQA and AlteredNumericQA beyond 24k context length, even when perplexity remained stable, indicating a disconnect between coherence and reasoning accuracy.
  • Placing the question at the end of the context improved accuracy on FreeFormQA and AlteredNumericQA at longer lengths, suggesting that attention mechanisms may favor recent tokens in long sequences.
  • The truncated basis for positional encodings showed promising extrapolation capabilities, though not surpassing linear scaling, and warrants further investigation.
  • Increasing the scale factor at inference time beyond the finetuning scale improved performance up to a 2x factor, but gains plateaued beyond that, suggesting a practical limit to this approach.
  • Perplexity was found to be a coarse metric for long-context performance, as models could generate coherent outputs with high perplexity while failing on reasoning tasks.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.