Skip to main content
QUICK REVIEW

[Paper Review] Extending Llama-3's Context Ten-Fold Overnight

Peitian Zhang, Ninglu Shao|arXiv (Cornell University)|Apr 30, 2024
Advanced Vision and ImagingComputer Science4 citations
TL;DR

This paper presents Llama-3-8B-Instruct-80K-QLoRA, a method to extend Llama-3’s context length from 8K to 80K using only 3.5K synthetic training samples generated by GPT-4 and QLoRA fine-tuning. The model achieves state-of-the-art performance on long-context benchmarks while preserving short-context capabilities, training in just 8 hours on a single 8xA800 (80GB) GPU machine.

ABSTRACT

We extend the context length of Llama-3-8B-Instruct from 8K to 80K via QLoRA fine-tuning. The entire training cycle is super efficient, which takes 8 hours on one 8xA800 (80G) GPU machine. The resulted model exhibits superior performances across a broad range of evaluation tasks, such as NIHS, topic retrieval, and long-context language understanding; meanwhile, it also well preserves the original capability over short contexts. The dramatic context extension is mainly attributed to merely 3.5K synthetic training samples generated by GPT-4 , which indicates the LLMs' inherent (yet largely underestimated) potential to extend its original context length. In fact, the context length could be extended far beyond 80K with more computation resources. Therefore, the team will publicly release the entire resources (including data, model, data generation pipeline, training code) so as to facilitate the future research from the community: \url{https://github.com/FlagOpen/FlagEmbedding}.

Motivation & Objective

  • To enable efficient, low-resource extension of Llama-3-8B-Instruct’s context length from 8K to 80K without significant compute overhead.
  • To investigate whether large language models can inherently generalize to much longer contexts using minimal synthetic data.
  • To preserve the original model’s performance on short-context tasks while achieving superior long-context capabilities.
  • To release a fully reproducible training recipe, including data, code, and model weights, to accelerate community research in long-context LLMs.
  • To explore the feasibility of extrapolating beyond 80K context length using the same method with increased compute.

Proposed method

  • Synthesized 3.5K long-context training samples using GPT-4, covering three tasks: Single-Detail QA, Multi-Detail QA (on homogeneous and heterogeneous contexts), and Biography Summarization.
  • Constructed multi-turn conversations by grouping question-answer pairs from the same long context (64K–80K tokens) to simulate instruction-tuning scenarios.
  • Combined the synthetic data with 5K RedPajama and 12K LongAlpaca instances to mitigate catastrophic forgetting during fine-tuning.
  • Applied QLoRA with LoRA on Q, K, V, O projections and the embedding layer, using rank=32 and alpha=16, with a batch size of 8 and linear decay learning rate of 5e-5.
  • Extended the RoPE rotary position embedding base from 500K to 200M to support longer context during training.
  • Trained the model for one epoch using a single 8xA800 (80GB) GPU, completing in 8 hours with gradient checkpointing and no model parallelism.
Figure 1: The accuracy score of Llama-3-8B-Instruct-80K-QLoRA on Needle-In-A-HayStack task. The blue vertical line indicates the training length, i.e. 80K.
Figure 1: The accuracy score of Llama-3-8B-Instruct-80K-QLoRA on Needle-In-A-HayStack task. The blue vertical line indicates the training length, i.e. 80K.

Experimental results

Research questions

  • RQ1Can a small amount of synthetic data generated by a powerful LLM like GPT-4 enable effective and efficient long-context fine-tuning of a smaller LLM?
  • RQ2To what extent can a fine-tuned LLM generalize to context lengths beyond its maximum training length (e.g., 80K to 128K)?
  • RQ3Does extending context length via this method compromise the model’s performance on short-context tasks?
  • RQ4How does the performance of the extended model compare to original and other long-context LLMs on standard long-context benchmarks?
  • RQ5Can the proposed method be scaled to achieve even longer context lengths with additional computational resources?

Key findings

  • The Llama-3-8B-Instruct-80K-QLoRA model achieved 100% accuracy on the Needle-In-A-Haystack task across its full 80K training context length and generalized well to unseen positions up to 128K.
  • On the Topic Retrieval benchmark, the model maintained 100% accuracy across all evaluated context lengths (5K to 70K), outperforming the original Llama-3-8B-Instruct, which failed beyond 9K.
  • On LongBench, the model achieved an average score of 47.19, significantly outperforming the original Llama-3-8B-Instruct (43.20) and Llama-3-8B-Instruct-262K (43.73) across multiple tasks including Single-Doc, Multi-Doc, and Summ.
  • On InfiniteBench, the model achieved 30.92 on LongBookQA and 14.73 on LongBookSum, outperforming the original Llama-3-8B-Instruct (7.00 and 16.40) and approaching GPT-4 performance on summarization.
  • On MMLU, the model scored 64.44 in zero-shot evaluation, slightly below the original Llama-3-8B-Instruct (65.91), indicating a minor trade-off in short-context capability, but still superior to other open-source models of similar scale.
  • The entire training process completed in just 8 hours on a single 8xA800 (80GB) GPU, demonstrating high efficiency and reproducibility.
Figure 2: The accuracy of Topic Retrieval task.
Figure 2: The accuracy of Topic Retrieval task.

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.