Skip to content

Commit 905ccff

Browse files
rsyuecirquit
andauthored
Update src/fairseq2/models/hg/adapter.py
Co-authored-by: Alexander Erben <aerben@meta.com>
1 parent e7969a3 commit 905ccff

1 file changed

Lines changed: 1 addition & 4 deletions

File tree

src/fairseq2/models/hg/adapter.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,16 +224,13 @@ def forward( # type: ignore[override]
224224
# HuggingFace returns a ModelOutput with .loss and .logits
225225
loss: Tensor = outputs.loss
226226

227-
# Handle reduction
228-
# HF models typically return mean loss, we need to convert based on reduction
227+
# HF models return mean loss, need to optionally convert to "sum"
229228
if reduction == "sum":
230-
# Convert from mean to sum
231229
if target_mask is not None:
232230
num_targets = target_mask.sum()
233231
else:
234232
num_targets = (labels != -100).sum()
235233
loss = loss * num_targets
236-
# If reduction == "mean", loss is already in the right format
237234

238235
if return_logits:
239236
return loss, cast(Tensor, outputs.logits)

0 commit comments

Comments
 (0)