Skip to content

Conversation

@yashwantbezawada
Copy link
Contributor

Summary

Fixes an UnboundLocalError that occurs in the RT-DETR loss computation when config.auxiliary_loss is False.

Problem

The variable auxiliary_outputs is conditionally assigned inside an if config.auxiliary_loss: block, but it's referenced later in the function regardless of whether the condition was true. When auxiliary_loss is disabled, this causes:

UnboundLocalError: local variable 'auxiliary_outputs' referenced before assignment

Solution

Initialize auxiliary_outputs = None before the conditional block to ensure it's always defined before use.

Changes

  • Added auxiliary_outputs = None initialization in src/transformers/loss/loss_rt_detr.py:450

Testing

This fix ensures the function works correctly whether config.auxiliary_loss is True or False.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant