Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions libreyolo/models/rfdetr/loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,14 @@ def loss_masks(self, outputs, targets, indices, num_boxes):
spatial_features = outputs["pred_masks"]["spatial_features"]
query_features = outputs["pred_masks"]["query_features"]
bias = outputs["pred_masks"]["bias"]
# If there are no matches, return an empty tensor like the Tensor branch does.
if idx[0].numel() == 0:
device = spatial_features.device
src_masks = torch.tensor([], device=device)
# Return zero losses that ARE connected to the mask head tensors so
# every mask-head parameter still receives a (zero) gradient.
# torch.tensor([]) has no grad_fn and silently drops those params from
# the backward graph, which violates DDP static_graph=True and causes
# a "finished reduction" crash whenever a rank sees an all-unlabeled batch.
zero = spatial_features.sum() * 0.0 + query_features.sum() * 0.0 + bias * 0.0
return {"loss_mask_ce": zero, "loss_mask_dice": zero}
else:
batched_selected_masks = []
per_batch_counts = idx[0].unique(return_counts=True)[1]
Expand Down
Loading