You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug] predict_with_generate=True causes 1D dimension collapse of eval_prediction.predictions in custom metrics (DDP) #8256
I have searched existing issues, and this is a new bug report. / 我已经搜索过现有的 issues,确认这是一个新的 bug report。
Bug Description / Bug 描述
Version
4.0.0.dev0
Describe the bug
When --predict_with_generate true is enabled in a multi-GPU (DDP) environment, the eval_prediction.predictions passed to a custom EvalMetrics subclass collapses from a 2D tensor (BatchSize, SeqLen) into a flattened 1D array.
This causes Serializer.from_tensor(preds) to fail with _pickle.UnpicklingError or IndexError because the data structure is corrupted during the gathering process.
Root Cause
In Seq2SeqTrainer.prediction_step, pad_sequence only performs local padding within each GPU. If GPU 0 and GPU 1 have different maximum sequence lengths for their local batches, accelerator.gather cannot stack them and flattens the tensors instead.
How to Reproduce / 如何复现
Run SFT with --predict_with_generate true on 2+ GPUs.
Use a custom EvalMetrics that accesses eval_prediction.predictions.
Observe that preds.ndim is 1 and the evaluation crashes.
Activity
ywb2018 commentedon May 17, 2026
遇到了同样的问题 没有解决,你解决了吗?
coldchair commentedon May 17, 2026
继承 Seq2SeqTrainer 改一下对应函数(先 all_gather 各自长度得到最大长度,然后 pad,再 all_gather tensor),让 AI 帮忙写一下
iisskj commentedon May 27, 2026
遇到同样的问题,希望新版本能 fix.
fix: preserve 2D predictions in predict_with_generate DDP eval
fix: preserve 2D predictions in predict_with_generate DDP eval (model…