Skip to content

Fix RTDetrHungarianMatcher crash on infinite cost matrix#47016

Open
AyushDas4890 wants to merge 6 commits into
huggingface:mainfrom
AyushDas4890:fix-issue-47000-rtdetr-infeasible-cost-matrix
Open

Fix RTDetrHungarianMatcher crash on infinite cost matrix#47016
AyushDas4890 wants to merge 6 commits into
huggingface:mainfrom
AyushDas4890:fix-issue-47000-rtdetr-infeasible-cost-matrix

Conversation

@AyushDas4890

@AyushDas4890 AyushDas4890 commented Jul 2, 2026

Copy link
Copy Markdown

CI

What does this PR do?

Fixes #47000

RTDetrHungarianMatcher crashes with ValueError: cost matrix is infeasible
when the cost matrix contains infinite values. Under AMP, fp16 sigmoid
saturation gives probabilities of exactly 0.0 or 1.0, and the 1e-8 epsilon in
the focal class cost underflows in fp16, so the log() terms overflow to ±inf
before reaching scipy.optimize.linear_sum_assignment.

This applies the same guard that was merged for Mask2Former in #27897:
clamp the cost matrix to [-1e10, 1e10] before the assignment. DFineLoss
reuses this matcher, so D-FINE is fixed too.

Added a regression test that reproduces the failure with fp16 saturating
logits (both directions) and verifies the matcher returns valid indices.
The test fails without the fix and passes with it.

Disclosure: I used an AI assistant to help diagnose the root cause and draft
this fix myself; I have reviewed the changes and run the new test myself.

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

[For maintainers] Suggested jobs to run (before merge)

run-slow: rt_detr

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

CI recap

Dashboard: View test results in Grafana
Latest run: 28638832663:2
Result: failure | Jobs: 14 | Tests: 47,253 | Failures: 1 | Duration: 17h 29m

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.

RTDetrLoss crashing with "ValueError: cost matrix is infeasible"

1 participant