Files
myWiki/concepts/sequence-packing.md

31 lines
1.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: "Sequence Packing (序列打包)"
created: 2025-06-02
updated: 2025-06-02
type: concept
tags: [training-optimization, efficiency, placeholder]
sources: []
---
# Sequence Packing
> 将多个短序列拼接为一个长序列以提升 GPU 利用率的训练技术Krell et al., 2022需通过位置 ID 防止跨样本注意力污染。
## 核心思想
在监督微调中batch 内的序列长度通常不均匀。序列打包将多个短序列拼接在一起,使 GPU 处理的 token 数最大化。
## 实现要点
1. **无污染保证**:通过设置不同的 position ID 区间来防止不同序列之间的注意力泄漏
2. **掩码叠加**:打包掩码(防跨样本污染)可与自定义注意力掩码通过逻辑 AND 结合
## 在 One-Pass to Reason 中的应用
[[goru-one-pass-to-reason-2025]] 中的 Flex-Pack 配置将序列打包与 [[block-sparse-attention]] 叠加,实现最佳加速效果。
## 相关
- [[goru-one-pass-to-reason-2025|One-Pass to Reason]]
- [[block-sparse-attention]]