MCPcopy Create free account
hub / github.com/OpenMOSS/MOSS / collate_fn

Method collate_fn

finetune_moss.py:113–124  ·  view source on GitHub ↗
(self, batch)

Source from the content-addressed store, hash-verified

111 return data, attn_mask, label
112
113 def collate_fn(self, batch):
114 batch_input_ids, batch_attn_mask, batch_labels = [], [], []
115 for input_ids, attn_mask, label in batch:
116 batch_input_ids.append(input_ids)
117 batch_attn_mask.append(attn_mask)
118 batch_labels.append(label)
119
120 batch_input_ids = torch.nn.utils.rnn.pad_sequence(batch_input_ids, batch_first=True, padding_value=self.tokenizer.eos_token_id)
121 batch_attn_mask = torch.nn.utils.rnn.pad_sequence(batch_attn_mask, batch_first=True, padding_value=0).to(torch.bool)
122 batch_labels = torch.nn.utils.rnn.pad_sequence(batch_labels, batch_first=True, padding_value=-100)
123
124 return batch_input_ids, batch_attn_mask, batch_labels
125
126
127class SFTMetric:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected