Desciption: In DeepSpeed-Chat step1 PromptDataset. According to my understanding, the SFT part needs to mask the source part, and the source part does not participate in the loss calculation.
classPromptDataset(Dataset):
def__init__(self, prompt_dataset, chosen_dataset, reject_dataset,
pad_token_id, train_phase) ->None:
super().__init__()
self.prompt_dataset=prompt_datasetself.chosen_dataset=chosen_datasetself.reject_dataset=reject_datasetself.pad_token_id=pad_token_idself.train_phase=train_phasedef__len__(self):
length=len(self.chosen_dataset)
ifself.train_phase==3:
length=len(self.prompt_dataset)
returnlengthdef__getitem__(self, idx):
ifself.train_phase==1:
return {
"input_ids": self.chosen_dataset[idx]["input_ids"],
"attention_mask": self.chosen_dataset[idx]["attention_mask"],
"labels": self.chosen_dataset[idx]["input_ids"] # maybe: [*[-100] * source_len, *[target_ids]]
}
elifself.train_phase==2:
returnself.chosen_dataset[idx]["input_ids"], self.chosen_dataset[idx]["attention_mask"], \
self.reject_dataset[idx]["input_ids"], self.reject_dataset[idx]["attention_mask"]
elifself.train_phase==3:
returnself.prompt_dataset[idx]["input_ids"],self.prompt_dataset[idx]["attention_mask"], \
self.pad_token_id
Desciption: In DeepSpeed-Chat step1 PromptDataset. According to my understanding, the SFT part needs to mask the source part, and the source part does not participate in the loss calculation.