Ignore padding in loss method
Browse files
modeling_gpt_optimized.py
CHANGED
@@ -195,5 +195,5 @@ class GPTOptim(GPT2PreTrainedModel):
|
|
195 |
logits = self.model.lm_head(x) # (B, T, vocab_size)
|
196 |
loss = None
|
197 |
if labels is not None:
|
198 |
-
loss = F.cross_entropy(logits.view(-1, logits.size(-1)), labels.view(-1))
|
199 |
return logits, loss
|
|
|
195 |
logits = self.model.lm_head(x) # (B, T, vocab_size)
|
196 |
loss = None
|
197 |
if labels is not None:
|
198 |
+
loss = F.cross_entropy(logits.view(-1, logits.size(-1)), labels.view(-1), ignore_index=config.eos_token_id)
|
199 |
return logits, loss
|