Hierarchical Balance Packing: Towards Efficient Supervised Fine-tuning for Long-Context LLM

Yongqiang Yao, Jingru Tan, Kaihuan Liang, Feizhao Zhang, Jiahao Hu +5 more
3/10/2025
3 citations
cs.LGcs.AI

Official code: ModelTC/HBP (4 stars, Python, Apache-2.0, last commit 2025-09-30).

Abstract

Training Long-Context Large Language Models (LLMs) is challenging, as hybrid training with long-context and short-context data often leads to workload imbalances. Existing works mainly use data packing to alleviate this issue, but fail to consider imbalanced attention computation and wasted communication overhead.

Show full abstract

This paper proposes Hierarchical Balance Packing (HBP), which designs a novel batch-construction method and training recipe to address those inefficiencies. In particular, the HBP constructs multi-level data packing groups, each optimized with a distinct packing length. It assigns training samples to their optimal groups and configures each group with the most effective settings, including sequential parallelism degree and gradient checkpointing configuration. To effectively utilize multi-level groups of data, we design a dynamic training pipeline specifically tailored to HBP, including curriculum learning, adaptive sequential parallelism, and stable loss. Our extensive experiments demonstrate that our method significantly reduces training time over multiple datasets and open-source models while maintaining strong performance. For the largest DeepSeek-V2 (236B) MoE model, our method speeds up the training by 2.4$\times$ with competitive performance. Codes will be released at https://github.com/ModelTC/HBP.

View on arXivView PDF

Code Implementations(1)

ModelTC/HBPOfficial100%
Apache-2.0

[NeurIPS 2025] This is the official PyTorch implementation of "Hierarchical Balance Packing: Towards Efficient Supervised Fine-tuning for Long-Context LLM".

40Python, ShellSep 30, 20251 years agoApache-2.0

Similar Papers

Cite this paper

@article{yao2025hierarchical,
  title  = {Hierarchical Balance Packing: Towards Efficient Supervised Fine-tuning for Long-Context LLM},
  author = {Yongqiang Yao and Jingru Tan and Kaihuan Liang and Feizhao Zhang and Jiahao Hu and Shuo Wu and Yazhe Niu and Ruihao Gong and Dahua Lin and Ningyi Xu},
  year   = {2025},
  eprint = {2503.07680},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2503.07680v3}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2503.07680.svg)](https://codeofpaper.com/paper/2503.07680)

Discussion