Skip to content

Commit 923d825

Browse files
Fix UnboundLocalError in RT-DETR loss computation
Initialize auxiliary_outputs to None before conditional use to prevent UnboundLocalError when config.auxiliary_loss is False. Fixes the error: UnboundLocalError: local variable 'auxiliary_outputs' referenced before assignment This occurs when auxiliary_loss is disabled but the variable is still referenced later in the function.
1 parent 66d5711 commit 923d825

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

src/transformers/loss/loss_rt_detr.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,7 @@ def RTDetrForObjectDetectionLoss(
447447
outputs_loss = {}
448448
outputs_loss["logits"] = logits
449449
outputs_loss["pred_boxes"] = pred_boxes
450+
auxiliary_outputs = None # Initialize to prevent UnboundLocalError when auxiliary_loss is False
450451
if config.auxiliary_loss:
451452
if denoising_meta_values is not None:
452453
dn_out_coord, outputs_coord = torch.split(outputs_coord, denoising_meta_values["dn_num_split"], dim=2)

0 commit comments

Comments
 (0)