Skip to main content
QUICK REVIEW

[Paper Review] Packing: Towards 2x NLP BERT Acceleration

Matej Kosec, Sheng Fu|arXiv (Cornell University)|Jun 29, 2021
VLSI and FPGA Design TechniquesEngineering6 references4 citations
TL;DR

This paper proposes deterministic histogram-based packing algorithms to eliminate padding in BERT pretraining, achieving a 2x speed-up in sequences/sec by combining multiple sequences into single samples. The methods—SPFHP and NNLSHP—operate on sequence length histograms for linear-time efficiency, enabling near-optimal packing with minimal impact on model performance and full convergence during BERT-Large pretraining.

ABSTRACT

We find that at sequence length 512 padding tokens represent in excess of 50% of the Wikipedia dataset used for pretraining BERT (Bidirectional Encoder Representations from Transformers). Therefore by removing all padding we achieve a 2x speed-up in terms of sequences/sec. To exploit this characteristic of the dataset, we develop and contrast two deterministic packing algorithms. Both algorithms rely on the assumption that sequences are interchangeable and therefore packing can be performed on the histogram of sequence lengths, rather than per sample. This transformation of the problem leads to algorithms which are fast and have linear complexity in dataset size. The shortest-pack-first histogram-packing (SPFHP) algorithm determines the packing order for the Wikipedia dataset of over 16M sequences in 0.02 seconds. The non-negative least-squares histogram-packing (NNLSHP) algorithm converges in 28.4 seconds but produces solutions which are more depth efficient, managing to get near optimal packing by combining a maximum of 3 sequences in one sample. Using the dataset with multiple sequences per sample requires additional masking in the attention layer and a modification of the MLM loss function. We demonstrate that both of these changes are straightforward to implement and have relatively little impact on the achievable performance gain on modern hardware. Finally, we pretrain BERT-Large using the packed dataset, demonstrating no loss of convergence and the desired 2x speed-up.

Motivation & Objective

  • Address the inefficiency caused by excessive padding (over 50%) in BERT pretraining on the Wikipedia dataset at sequence length 512.
  • Develop fast, deterministic packing algorithms that avoid per-sample processing by operating on sequence length histograms.
  • Achieve near-optimal packing efficiency while maintaining model convergence and performance during BERT pretraining.
  • Demonstrate that attention masking and modified MLM loss for packed sequences are lightweight and effective on modern hardware.

Proposed method

  • Transform the packing problem from per-sequence processing to histogram-based optimization, reducing complexity to linear in dataset size.
  • Design the shortest-pack-first histogram-packing (SPFHP) algorithm to prioritize shorter sequences, achieving packing in 0.02 seconds for 16M sequences.
  • Implement the non-negative least-squares histogram-packing (NNLSHP) algorithm to optimize depth efficiency, allowing up to three sequences per packed sample.
  • Introduce sequence-specific masking in the self-attention layer to prevent attention between tokens from different original sequences in a packed sample.
  • Modify the masked language modeling (MLM) loss function to account for the fact that some tokens are masked due to packing rather than random corruption.
  • Pretrain BERT-Large using the packed dataset to validate that performance is preserved and the 2x speed-up is achieved.

Experimental results

Research questions

  • RQ1Can deterministic histogram-based packing eliminate over 50% padding in BERT pretraining without sacrificing model convergence?
  • RQ2How efficient are histogram-based packing algorithms in terms of runtime and packing depth compared to per-sample methods?
  • RQ3What is the performance impact of attention masking and modified MLM loss in packed BERT training?
  • RQ4Can a 2x speed-up in sequences/sec be achieved with minimal degradation in downstream task performance?

Key findings

  • Packing reduces padding to less than 50% of the input at sequence length 512, enabling a 2x speed-up in sequences per second during BERT pretraining.
  • The SPFHP algorithm packs the entire 16M-sequence Wikipedia dataset in just 0.02 seconds, demonstrating linear-time scalability.
  • The NNLSHP algorithm achieves higher packing depth efficiency, approaching optimal packing by combining up to three sequences per sample.
  • The modified attention masking and MLM loss functions have minimal impact on model performance, preserving convergence during BERT-Large pretraining.
  • BERT-Large pretraining using the packed dataset achieves the same convergence behavior as standard training, confirming the method's viability.
  • The approach is practical on modern hardware, with both packing algorithms and inference modifications being straightforward to implement.

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.