Repository navigation
fix(dpo): move chosen padding past rejected sequences in packed concatenation - #2372
Open
ApacheWang wants to merge 2 commits into
Open
ApacheWang wants to merge 2 commits into
ApacheWang wants to merge 2 commits into
Conversation
Signed-off-by: bc15575202581 <bc15575202581@gmail.com>
Signed-off-by: bc15575202581 <bc15575202581@gmail.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Drafted by Antigravity and Codex.
Summary
Fixes
concatenated_inputsinopen_instruct/padding_free_collator.pyso trailing padding from the packedchosenside is moved after therejectedtokens instead of sitting inside the first rejected sequence's attention document.Root Cause
TensorDataCollatorWithFlatteningDPOpadschosenandrejectedindependently tomax_seq_lengthwhile settingchosen_cu_seq_lens_k[-1]to the unpadded chosen token count. Previously,concatenated_inputsconcatenated the full paddedchosentensor in front ofrejectedand offsetrejected_cu_seq_lens_{q,k}by the padded widthchosen_features["input_ids"].shape[-1]. As a result:max_seq_length=5,concatenated_input_idswas[11, 12, 0, 0, 0, 21, 22, 23, 0, 0]andconcatenated_cu_seq_lens_kwas[0, 2, 8].[2, 8), causing the first rejected sequence to attend over the 3 leading chosen padding tokens (for example througholmo_core_utils.doc_lens_from_cu_seq_lensinopen_instruct/dpo_utils.py).seq_idxaddedchosen_num_seqsto rejected padding entries (-1), turning padding indices into non-negative values.Changes
open_instruct/padding_free_collator.py: Move chosen trailing padding ([chosen_length:]) afterrejectedforinput_ids,labels,position_ids, andseq_idx, offsetrejected_cu_seq_lens_{q,k}by the realchosen_length, and preserve-1padding values inrejected_features["seq_idx"].open_instruct/dpo_utils.py: Addpacked_layout_version = 2tocompute_reference_cache_hashwhenargs.packingis enabled so cached reference log-probs computed under the old padded layout are not reused.open_instruct/test_packed_dpo_collation.py&open_instruct/test_padding_free_collator.py: Add regression testtest_concatenated_dpo_padding_stays_outside_real_documentsand updateTestDPOPackingIndices.test_concatenated_cu_seq_lens_with_paddingto assert compact document boundaries[0, ..., 100, 150, 200].Verification
ff2546d:open_instruct/test_packed_dpo_collation.pyfails ([0, 2, 8] != [0, 2, 5]and chosen padding sits before rejected tokens).open_instruct/test_packed_dpo_collation.pypasses (1 passed).ruff checkandruff format --checkpass on all modified files.