快速结论:在使用 packed sequence(如 DataCollatorWithFlattening)进行 padding-free 训练 Qwen3.8-Flash-Next 时,其 PLE 层的 n-gram shift 与 short convolution 会跨样本边界读取 token,导致同一文档的 log-prob 受前面打包序列影响。优先检查这两个 PLE 子模块是否已传入并使用 seq_idx / cu_seq_lens_q。
适用环境:Issue 已确认环境为 Linux(glibc2.35)、Python 3.13.9、transformers 5.24.0(main 5.25.0.dev0 同样复现)、PyTorch 2.14.1+cu130、NVIDIA H100 80GB HBM3,单卡运行,未使用 DeepSpeed。
最快修复方案:暂无确认的一步修复方案。n-gram shift 部分已由 #51576 修复;PLE short conv 部分仍需等待 causal_conv1d_fn 支持 dilation 后跟进修复。
注意事项:关闭 PLE 层可让序列间差异变为 0,但这只是规避而非修复;short conv 的修复依赖上游 kernel 支持 dilation,修复前在 packed 训练中仍可能存在跨样本污染。
问题场景
用户在 Linux + NVIDIA H100 上,用 transformers 加载 Qwen3.8-Flash-Next(含 PLE 层:n-gram embedding + PLE short convolution),配合 DataCollatorWithFlattening(return_flash_attn_kwargs=True, return_seq_idx=True) 和 use_cache=False 做 packed sequence / padding-free 训练。将同一文档分别打包在两个不同前缀之后,比较其 log-probs 时,发现首个 token 起就出现差异;当 ple_layer_ids=[](关闭 PLE 层)时差异恒为 0。
报错原文
Qwen3.8-Flash-Next: the n-gram shift and the PLE short convolution ignore packed-sequence boundaries, so padding-free training mixes tokens
ple_layer_ids=[1]: max |Δlogp| of the same document after two prefixes, per position: [0.0209, 0.0123, 0.0078, 0.0105, 0.0054, 0.0037] ...
ple_layer_ids=[]: max |Δlogp| of the same document after two prefixes, per position: [0.0, 0.0, 0.0, 0.0, 0.0, 0.0] ...
原因分析
Issue 指出 PLE 层有两个环节未遵守 packed-sequence 边界(attention 与 gated DeltaNet 本身是正常的):
1. Qwen4ExpTextNGramEmbedding._shift_right_ignore_eos 只在 eos_token_id(<|endoftext|>)处重置 n-gram 上下文,导致打包序列的首批 token 会读到前一个序列的尾部 token。
2. Qwen4ExpTextPLELayer._short_conv(dilated conv1d)未考虑打包序列边界,会读取前一个序列最后 short_conv_state_len 个位置。
自 PR #51273 起,这两个模块都能收到 forward 的 kwargs(打包批次中携带 seq_idx 和 cu_seq_lens_q),但均未使用。
环境排查
- 确认 transformers 版本:5.24.0 或 main(5.25.0.dev0)均可能受影响。
- 确认 PyTorch 版本与 CUDA 版本(Issue 为 2.14.1+cu130)。
- 确认是否使用
DataCollatorWithFlattening且开启return_flash_attn_kwargs=True、return_seq_idx=True。 - 确认模型配置中是否设置了
ple_layer_ids(为空时 PLE 层不参与,问题不出现)。 - 确认
use_cache=False,并与 Issue 一致单卡运行以排除并行配置干扰。
解决步骤
- 先用最小复现脚本确认现象:同一文档分别打包在不同前缀后,比较
log_softmax后的 log-probs;对比ple_layer_ids=[1]与ple_layer_ids=[]两组结果。 - 若确认差异仅出现在开启 PLE 层时,升级到包含 #51576 的 transformers 版本,处理 n-gram shift 跨边界读取问题。
- 对 short conv 部分,检查当前 transformers 是否已跟进
causal_conv1d_fn的 dilation 支持(上游为 huggingface/kernels-community PR #1404);在修复合入前,可优先尝试避免在 PLE 层开启时使用 packed 边界紧邻的批次,或暂时关闭 PLE 层做对照测试。 - 若需自行修改,检查
_shift_right_ignore_eos与_short_conv是否使用 forward kwargs 中的seq_idx/cu_seq_lens_q来重置上下文;这属于推测性修复方向,需以官方合入为准。
验证方法
重新运行 Issue 中的复现脚本:若修复生效,同一文档在两个不同前缀后的 per-position max |Δlogp| 应接近或等于 0(与 ple_layer_ids=[] 的结果一致)。同时确认 packed 训练中首个 token 的 loss/log-prob 不再随前一序列内容变化。
参考来源
huggingface/transformers #51572
AI 工具推荐
想把多个 AI 模型放在一个入口?
GamsGo AI 集成 ChatGPT、DeepSeek、Gemini、Claude、Midjourney、Veo 等常用模型,适合写作、绘图、视频和日常 AI 工作流。
推广链接:通过此链接购买,我可能获得佣金,不影响你的价格。
这个方案解决了吗?
可以继续搜索完整报错,或查看同一工具的其他排查指南。

![[Bug]: `tenant_llm_id` / `tenant_embd_id` / ... reference columns created as INTEGER on upgrade, but code stores 32-char hex model ids (500](https://www.chat-gpts.plus/wp-content/uploads/2026/12/18756-c90e98ae-768x403.jpg)
![[Bug]: Agent tools discard full conversational context when FullChatHistoryAsInput is enabled](https://www.chat-gpts.plus/wp-content/uploads/2026/12/21455-4d8665a7-768x403.jpg)