Fix Sam3Processor missing input_boxes_labels for padded None entries#45171
Conversation
When input_boxes contains a mix of None and real box entries (e.g. input_boxes=[None, [[x1,y1,x2,y2]]]), the processor pads None entries with [-10,-10,0,0] but does not generate corresponding input_boxes_labels. The model's geometry encoder then treats all boxes as valid (box_mask=ones), including the padded ones, causing different behavior compared to input_boxes=None. Generate default input_boxes_labels when not provided by the user: None entries get label -10 (the pad value) so the model masks them out, real entries get label 1 (positive). User-provided labels are preserved unchanged. Adds processor tests covering mixed None/real batches, all-real batches, no-boxes, and user-provided label preservation. Fixes huggingface#45059
|
Friendly ping @yonigozlan @NielsRogge @molbap @Rocketknight1, this is a small processor fix (one new method and 4 tests) for the batched input_boxes inconsistency in Sam3Processor. CI quality checks all pass; the failing jobs are pre-existing flaky tests on main. Happy to address any feedback. |
yonigozlan
left a comment
There was a problem hiding this comment.
Hello @Kash6 ! Thanks a lot for working on this and fixing this bug. I just made a few simplifications/standardization, and we're ready to merge!
|
[For maintainers] Suggested jobs to run (before merge) run-slow: sam3 |
|
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. |
When input_boxes contains a mix of None and real box entries (e.g. input_boxes=[None, [[x1,y1,x2,y2]]]), the processor pads None entries with [-10,-10,0,0] but does not generate corresponding input_boxes_labels. The model's geometry encoder then treats all boxes as valid (box_mask=ones), including the padded ones, causing different behavior compared to input_boxes=None.
Generate default input_boxes_labels when not provided by the user: None entries get label -10 (the pad value) so the model masks them out, real entries get label 1 (positive). User-provided labels are preserved unchanged.
Adds processor tests covering mixed None/real batches, all-real batches, no-boxes, and user-provided label preservation.
What does this PR do?
Fixes #45059
Code Agent Policy
The Transformers repo is currently being overwhelmed by a large number of PRs and issue comments written by
code agents. We are currently bottlenecked by our ability to review and respond to them. As a result,
we ask that new users do not submit pure code agent PRs at this time.
You may use code agents in drafting or to help you diagnose issues. We'd also ask autonomous "OpenClaw"-like agents
not to open any PRs or issues for the moment.
PRs that appear to be fully agent-written will probably be closed without review, and we may block users who do this
repeatedly or maliciously.
This is a rapidly-evolving situation that's causing significant shockwaves in the open-source community. As a result,
this policy is likely to be updated regularly in the near future. For more information, please read
CONTRIBUTING.md.Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.
@yonigozlan @molbap @NielsRogge @zucchini-nlp