Skip to main content
QUICK REVIEW

[Paper Review] Efficient Sequence Packing without Cross-contamination: Accelerating Large Language Models without Impacting Performance

Mario Michael Krell, Matej Kosec|arXiv (Cornell University)|Jun 29, 2021
Natural Language Processing TechniquesComputer Science6 citations
TL;DR

This paper proposes a novel formalization of sequence packing as a bin-packing problem to eliminate padding tokens in large language model training, achieving up to 2x speedup without performance loss. By using efficient, mathematically equivalent packing algorithms and modifying attention mechanisms to prevent cross-contamination, the method enables high-throughput training on standard hardware with no accuracy degradation.

ABSTRACT

Effective training of today's large language models (LLMs) depends on large batches and long sequences for throughput and accuracy. To handle variable-length sequences on hardware accelerators, it is common practice to introduce padding tokens, so that all sequences in a batch have the same length. We show in this paper that the variation in sequence lengths in common NLP datasets is such that up to 50% of all tokens can be padding. In less common, but not extreme, cases (e.g. GLUE-cola with sequence length 128), the ratio is up to 89%. Existing methods to address the resulting inefficiency are complicated by the need to avoid cross-contamination in self-attention, by a reduction in accuracy when sequence ordering information is lost, or by customized kernel implementations only valid for specific accelerators. This paper introduces a new formalization of sequence packing in the context of the well-studied bin packing problem, and presents new algorithms based on this formulation which, for example, confer a 2x speedup for phase 2 pre-training in BERT. We show how existing models can be adapted to ensure mathematical equivalence between the original and packed models, meaning that packed models can be trained with existing pre-training and fine-tuning practices.

Motivation & Objective

  • Address the inefficiency caused by padding tokens in variable-length sequence batching for large language models.
  • Overcome limitations of existing methods that suffer from cross-contamination, accuracy loss, or hardware-specific optimizations.
  • Develop a general-purpose, accelerator-agnostic sequence packing framework compatible with standard training and fine-tuning workflows.
  • Ensure mathematical equivalence between packed and unpacked models to preserve convergence behavior and model performance.
  • Achieve near-optimal packing efficiency while avoiding the need for separator tokens or complex kernel implementations.

Proposed method

  • Formalize sequence packing as a bin-packing problem with a novel mathematical formulation to minimize padding.
  • Introduce two deterministic, efficient algorithms based on established solvers (e.g., non-negative least squares) to compute optimal packing strategies.
  • Use a weighted linear programming formulation with residual penalties to minimize padding tokens and handle leftover sequences.
  • Modify the self-attention mechanism to prevent cross-contamination between sequences in a packed batch, ensuring attention is computed only within sequences.
  • Introduce a residual-based correction step to handle leftover sequences by dynamically adding new packing strategies.
  • Ensure model equivalence by adjusting the attention mask and position embeddings to preserve attention patterns in packed sequences.

Experimental results

Research questions

  • RQ1Can sequence packing be formalized as a bin-packing problem to minimize padding while maintaining model performance?
  • RQ2What are the performance and accuracy trade-offs of existing packing methods that rely on separator tokens or sorted batching?
  • RQ3Can a packing strategy be designed that is both efficient and compatible with standard training pipelines without hardware-specific optimizations?
  • RQ4How can cross-contamination in self-attention be prevented in packed sequences without introducing accuracy loss?
  • RQ5To what extent can the proposed method improve training throughput while preserving convergence behavior and model accuracy?

Key findings

  • Up to 50% of tokens in the Wikipedia pre-training dataset are padding tokens at sequence length 512, and up to 89% in GLUE-cola at length 128.
  • The proposed packing method achieves a theoretical speedup of up to 2x for phase 2 pre-training in BERT by eliminating padding tokens.
  • The convergence behavior of BERT-large on the packed dataset is mathematically equivalent to that on the unpacked dataset, with no drop in performance.
  • The method reduces padding tokens to near-zero levels, achieving a packing efficiency of 98.7% on the Wikipedia dataset.
  • The algorithm computes optimal packing strategies in under a second for datasets with millions of sequences, enabling real-time preprocessing.
  • The approach is hardware-agnostic and compatible with standard training and fine-tuning workflows, requiring no model retraining or custom kernels.

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.