There was an error while loading. Please reload this page.
1 parent e7969a3 commit 905ccffCopy full SHA for 905ccff
1 file changed
src/fairseq2/models/hg/adapter.py
@@ -224,16 +224,13 @@ def forward( # type: ignore[override]
224
# HuggingFace returns a ModelOutput with .loss and .logits
225
loss: Tensor = outputs.loss
226
227
- # Handle reduction
228
- # HF models typically return mean loss, we need to convert based on reduction
+ # HF models return mean loss, need to optionally convert to "sum"
229
if reduction == "sum":
230
- # Convert from mean to sum
231
if target_mask is not None:
232
num_targets = target_mask.sum()
233
else:
234
num_targets = (labels != -100).sum()
235
loss = loss * num_targets
236
- # If reduction == "mean", loss is already in the right format
237
238
if return_logits:
239
return loss, cast(Tensor, outputs.logits)
0 commit comments