Skip to content
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

WIP: Preventing the loss from being computed when the input token is EOS Token #878

Draft
wants to merge 22 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions llmfoundry/models/mpt/modeling_mpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,12 @@ def __init__(
def get_targets(self, batch: Mapping) -> torch.Tensor:
targets = torch.roll(batch['labels'], shifts=-1)
targets[:, -1] = -100
# The model should not be trained to predict the word after the eos_token, because it comes from a different sequence.
if self.tokenizer is not None and hasattr(self.tokenizer,
'eos_token_id'):
targets = torch.where(
batch['labels'] == self.tokenizer.eos_token_id, -100,
targets)
return targets

def forward(self, batch: MutableMapping) -> CausalLMOutputWithPast:
Expand Down
Loading