[SAM3] Enable single-scale input support in Mask Decoder#43044
[SAM3] Enable single-scale input support in Mask Decoder#43044CodersAcademy006 wants to merge 3 commits into
Conversation
Allow Sam3MaskDecoder.forward to receive a single tensor for backbone_features in addition to the standard multi-scale list. When a bare tensor is passed it is wrapped in a list internally and a UserWarning is emitted so callers are aware they are using the single-scale fallback path. The existing _embed_pixels method and multi-scale FPN path are unchanged — a single-element list already works correctly through _embed_pixels since it operates on the last element of the list. Adds test_mask_decoder_single_scale_input to verify: - single tensor input produces valid output and emits UserWarning - multi-scale list input continues to work unchanged Fixes huggingface#43043
Sam3LiteTextMaskDecoder inherits from Sam3MaskDecoder via the modular conversion system. Apply the same single-tensor normalization introduced in the parent class so the generated file stays consistent with what check_modular_conversion expects. Fixes check_repository_consistency CI failure caused by stale generated modeling_sam3_lite_text.py after the parent class was updated.
|
[For maintainers] Suggested jobs to run (before merge) run-slow: sam3, sam3_lite_text |
…tput Align docstring wording with what check_modular_conversion generates from the parent Sam3MaskDecoder class, resolving the remaining consistency check failure.
|
Hi, Severity: action required | Category: correctness How to fix: Validate feature list length Agent prompt to fix - you can give this to your LLM of choice:
We noticed a couple of other issues in this PR as well - happy to share if helpful. Found by Qodo code review. FYI, Qodo is free for open-source. |
Enables single-scale inference for
Sam3MaskDecoder, bringing parity with the original implementation where full FPN levels aren't strictly required. I modified theforwardmethod to handle single-tensor inputs by bypassing the multi-scale fusion block and routing the feature directly through the primary projection layer.This change is fully backward compatible: standard multi-scale inputs continue to use the existing FPN path. I also added a contract check that logs a warning when the input scale count deviates from the config, ensuring users are explicitly aware when the model falls back to single-scale mode. Tests added to verify both the new fallback path and regression safety.
Fixes #43043