Skip to content

Fix Sam3Processor missing input_boxes_labels for padded None entries#45171

Merged
yonigozlan merged 9 commits intohuggingface:mainfrom
Kash6:fix/sam3-processor-input-boxes-padding-45059
Apr 15, 2026
Merged

Fix Sam3Processor missing input_boxes_labels for padded None entries#45171
yonigozlan merged 9 commits intohuggingface:mainfrom
Kash6:fix/sam3-processor-input-boxes-padding-45059

Conversation

@Kash6
Copy link
Copy Markdown
Contributor

@Kash6 Kash6 commented Apr 1, 2026

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.

  • I confirm that this is not a pure code agent PR.

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

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

Kash6 and others added 2 commits April 1, 2026 14:22
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
@Rocketknight1
Copy link
Copy Markdown
Member

cc @yonigozlan @molbap @NielsRogge!

@Kash6
Copy link
Copy Markdown
Contributor Author

Kash6 commented Apr 8, 2026

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.

Copy link
Copy Markdown
Member

@yonigozlan yonigozlan left a comment

Choose a reason for hiding this comment

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

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!

@github-actions
Copy link
Copy Markdown
Contributor

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

run-slow: sam3

@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.

@yonigozlan yonigozlan added this pull request to the merge queue Apr 15, 2026
Merged via the queue into huggingface:main with commit 18aa086 Apr 15, 2026
22 checks passed
@Kash6 Kash6 deleted the fix/sam3-processor-input-boxes-padding-45059 branch April 15, 2026 15:22
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.

SAM3 PCS very weird behaviour when providing text and bounding boxes

4 participants