-
Notifications
You must be signed in to change notification settings - Fork 3
Ensure Equivalence With DPO Padding and Padding Free #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
09a79ea
d0da2fd
54c1dc8
736734f
16a037c
0853acd
3a543b8
705ba44
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -195,7 +195,10 @@ def process_batch( | |
| return processed | ||
|
|
||
|
|
||
| def concatenated_inputs(batch: Dict[str, Union[List, torch.LongTensor]]) -> Dict[str, torch.LongTensor]: | ||
| def concatenated_inputs( | ||
| batch: Dict[str, Union[List, torch.LongTensor]], | ||
| pad_token_id: int = 0, | ||
| ) -> Dict[str, torch.LongTensor]: | ||
| """Concatenate the chosen and rejected inputs into a single tensor. | ||
|
|
||
| Args: | ||
|
|
@@ -209,12 +212,12 @@ def concatenated_inputs(batch: Dict[str, Union[List, torch.LongTensor]]) -> Dict | |
| concatenated_batch = {} | ||
| for k in batch: | ||
| if k.startswith("chosen") and isinstance(batch[k], torch.Tensor): | ||
| pad_value = -100 if "labels" in k else 0 | ||
| pad_value = -100 if "labels" in k else pad_token_id | ||
| concatenated_key = k.replace("chosen", "concatenated") | ||
| concatenated_batch[concatenated_key] = pad_to_length(batch[k], max_length, pad_value=pad_value) | ||
| for k in batch: | ||
| if k.startswith("rejected") and isinstance(batch[k], torch.Tensor): | ||
| pad_value = -100 if "labels" in k else 0 | ||
| pad_value = -100 if "labels" in k else pad_token_id | ||
| concatenated_key = k.replace("rejected", "concatenated") | ||
| concatenated_batch[concatenated_key] = torch.cat( | ||
| (concatenated_batch[concatenated_key], pad_to_length(batch[k], max_length, pad_value=pad_value)), dim=0 | ||
|
|
@@ -234,7 +237,11 @@ def concatenated_forward( | |
| We do this to avoid doing two forward passes, because it's faster for FSDP. | ||
| """ | ||
| if not packing: | ||
| concatenated_batch = concatenated_inputs(batch) | ||
| try: | ||
| pad_token_id = model.tokenizer.pad_token_id | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do models usually have a
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. they will usually have, though the model is typed as |
||
| except: | ||
| pad_token_id = 0 | ||
| concatenated_batch = concatenated_inputs(batch, pad_token_id=pad_token_id) | ||
| else: | ||
| concatenated_batch, bs = pf_concatenated_inputs(batch) | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Intentionally deleted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes there is a dup two lines belwo