Skip to content

Use deep copies instead of shallow copies for bbox_embed in GroundingDINO decoder (#37333). - #38999

Closed
rabibastinj wants to merge 1 commit into
huggingface:mainfrom
rabibastinj:fix/shallow-copy-groundingdino
Closed

rabibastinj wants to merge 1 commit into
huggingface:mainfrom
rabibastinj:fix/shallow-copy-groundingdino

Conversation

@rabibastinj

Copy link
Copy Markdown

Fixes #37333

The decoder was using shallow copies of GroundingDinoMLPPredictionHead, causing all bbox_embed layers to share the same instance, which led to unintended parameter sharing. This PR updates it to use copy.deepcopy().

What I Changed

  • Updated the model implementation to use copy.deepcopy() when decoder_bbox_embed_share=True.
  • Added two unit tests under tests/models/Rabi_Testcases/:
    • ✅ GD_Unique_Instances_Testcase.py – verifies each decoder layer gets a unique instance
    • ✅ GD_Layer_Independency_Testcase.py – ensures that modifying one layer does not affect another

Testing

  • Ran: pytest tests/models/Rabi_Testcases/
  • ✅ All tests passed successfully

@Rocketknight1

Rocketknight1 commented Jun 24, 2025 •

Copy link
Copy Markdown
Member

cc @qubvel, but @rabibastinj please delete the tests that copilot added - we don't want to add whole new test files just for this!

input_dim=config.d_model, hidden_dim=config.d_model, output_dim=4, num_layers=3
)
self.bbox_embed = nn.ModuleList([shared_head] * config.decoder_layers)
#self.bbox_embed = nn.ModuleList([shared_head] * config.decoder_layers)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

why not remove the comment?

@ArthurZucker

Copy link
Copy Markdown
Collaborator

Thanks a lot for the PR! This was superseded by #38238, which landed on main and covers the same change, so closing this one.

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

3 participants