Skip to content

Fix incorrect bbox_embed initialization when decoder_bbox_embed_share=False in GroundingDINO - #38238

Merged
Cyrilvallez merged 3 commits into
huggingface:mainfrom
islemyakoubi:islemyakoubi/issue37333
May 30, 2025
Merged

Cyrilvallez merged 3 commits into
huggingface:mainfrom
islemyakoubi:islemyakoubi/issue37333

Conversation

@islemyakoubi

Copy link
Copy Markdown
Contributor

Fixes #37333

This PR corrects the initialization of the bbox_embed layers in GroundingDinoForObjectDetection when config.decoder_bbox_embed_share is set to False.

What does this PR do?
Previously, the bbox_embed list was not properly initialized with independent layers when decoder_bbox_embed_share=False. The current implementation mistakenly overwrites the list in each loop iteration, resulting in incorrect behavior.

This PR:

Ensures that a new GroundingDinoMLPPredictionHead is created per decoder layer when decoder_bbox_embed_share=False

Uses nn.ModuleList properly to store separate instances

Preserves shared head behavior when decoder_bbox_embed_share=True

Motivation
Fixing this ensures that each decoder layer has its own bounding box prediction head when specified, which is essential for the expected decoding behavior and model performance.

@yonigozlan yonigozlan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice looks ready to merge to me! Could we first get the comments in English though 😉

@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@islemyakoubi

Copy link
Copy Markdown
Contributor Author

@yonigozlan I've updated the French comments to English as requested.

@islemyakoubi

Copy link
Copy Markdown
Contributor Author

@yonigozlan

@yonigozlan yonigozlan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great thanks for iterating! LGTM

@islemyakoubi

islemyakoubi commented May 28, 2025 •

Copy link
Copy Markdown
Contributor Author

Great thanks for iterating! LGTM

Thanks a lot! Happy to contribute 🙏

@Cyrilvallez Cyrilvallez left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks! Indeed old code did not make sense at all

@Cyrilvallez
Cyrilvallez merged commit 98568d1 into huggingface:main May 30, 2025
@islemyakoubi

Copy link
Copy Markdown
Contributor Author

LGTM thanks! Indeed old code did not make sense at all

Thanks! Glad the changes make sense now

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.

A shallow copy in groundingdino

4 participants