Fix flaky SAM-HQ integration tests by adding set_seed#43133
Fix flaky SAM-HQ integration tests by adding set_seed#43133raimbekovm wants to merge 2 commits intohuggingface:mainfrom
Conversation
|
|
|
You're right. I investigated the architecture: The original SAM-HQ has one shared
During conversion, the tensor is mapped only to The proper fix would be to either share the embedding between both (like the original) or copy the tensor to both locations during checkpoint loading. The Should I update the PR to fix the root cause instead? |
|
Yes, I think so! At the very least a PR that did that would give us a good starting point to check what it fixes and if there are any regressions |
Share positional_embedding between shared_image_embedding and prompt_encoder.shared_embedding using _tied_weights_keys mechanism, matching the original SAM-HQ architecture where pe_layer is shared.
|
[For maintainers] Suggested jobs to run (before merge) run-slow: sam_hq |
|
Implemented the proper fix mentioned in the PR description. What changed:
Why this approach:
The Tests:
The |
|
cc @NielsRogge @molbap @yonigozlan for review, since I'm not the expert on SAM models! |
|
hello @raimbekovm ! Thanks for raising this issue. The issue appears to be more important than the scope of this PR, so I opened another one to fix everything that's wrong here #43420 |
|
Glad I could help surface the issue — feel free to ping me if you need any help! |
What does this PR do?
Fixes flaky
SamHQModelIntegrationTestby addingset_seed(0)insetUp().The root cause: HF SAM-HQ creates two independent
SamHQPositionalEmbeddinginstances (shared_image_embeddingandprompt_encoder.shared_embedding), but the checkpoint only loads weights toshared_image_embedding. The other one stays randomly initialized, causing non-deterministic test results.Note: This is a workaround. The proper fix would be to share the embedding between both (like the original SAM-HQ) or copy weights to both during loading. Happy to implement that instead if preferred.
Fixes #42890
Before submitting
Pull Request section?
to it if that's the case. tests/models/sam_hq/test_modeling_sam_hq.py::SamHQModelIntegrationTest may fail since a lot of cases are lack of set_seed() #42890
Who can review?
@NielsRogge @molbap @yonigozlan