Repository navigation
[shardformer]: fix pooled token for left-padded inputs in pipeline sequence classification - #6458
Arthur031221 wants to merge 1 commit into
Conversation
|
Grep says # if no pad token found, use modulo instead of reverse indexing for ONNX compatibility
sequence_lengths = torch.eq(input_ids, self.config.pad_token_id).int().argmax(-1) - 1
sequence_lengths = sequence_lengths % input_ids.shape[-1] # mistral.py omits this second lineThose five are not hit by the left-padding bug: on
Only the last row separates those five from That is the index arithmetic computed on its own (torch 2.2.2, CPU) — I have not run those five pipeline forwards. And the modulo is there deliberately for ONNX, so it isn't a free swap; happy to leave the five if that's the intended scope. |
|
Thanks. Your last row is right, and it disproves the sentence in the PR body that said the |
…ification The pipeline forwards of LlamaForSequenceClassification and Qwen2ForSequenceClassification located the pooled token with ne(input_ids, pad_token_id).sum(-1) - 1. That is the last real token only for right-padded rows. For a left-padded row it points into the middle of the sequence, so the logits and loss differ from the model without pipeline parallelism. Use the rightmost non-pad token, as transformers and the Qwen3 pipeline forward already do. Signed-off-by: Arthur031221 <124417490+Arthur031221@users.noreply.github.com>
4ba2693 to
be3a6c1
Compare
Checklist before creating the PR
[doc/gemini/tensor/...]: A concise descriptionpip install pre-commit && pre-commit installIssue number
Refs #6457
What does this PR do?
With pipeline parallelism,
LlamaForSequenceClassificationandQwen2ForSequenceClassificationpool the wrong token on left-padded batches, so results differ from the unpipelined model.The pipeline forwards in
_llama_tf4.py,_llama_tf5.pyand_qwen2_tf4.pyusetorch.ne(input_ids, pad_token_id).sum(-1) - 1, which only gives the last real token with right padding. This now takes the rightmost non-pad token, like transformers and the Qwen3 forward do.opt.pyhas the same line, but its pipeline forward raises a ValueError on the pinned transformers 5.17.0, so I left it alone and usedRefs. Theeq(...).argmax(-1) - 1poolers in gpt2, bloom, falcon, gptj and mistral are different and untouched.The new test compares both pipeline forwards with the model's own
forwardon left and right padded batches. Without the fix Llama fails on 5.17.0 and Qwen2 on 4.51.3.Checklist before requesting a review
Do you enjoy contributing to Colossal-AI?
Assisted by Claude/Codex.