fix: add compatible_model_types to suppress model type mismatch warnings
Author: leoneperdigao
Pull request: yes

## Summary
<!-- Add a brief summary of changes -->

## Related Issue
Fixes #43408

**Issue:** Warning: You are using a model of type sam3_video to instantiate a model of type sam3_tracker
**URL:** https://github.com/huggingface/transformers/issues/43408

## Problem
### System Info

When using the sample code to create a SAM3 Tracker Model like:
```python
from transformers import Sam3TrackerProcessor, Sam3TrackerModel

model = Sam3TrackerModel.from_pretrained("facebook/sam3")
processor = Sam3TrackerProcessor.from_pretrained("facebook/sam3")
```

The following warning will be displayed:
```ba  
You are using a model of type sam3_video to instantiate a model of type sam3_tracker. This is not supported for all configurations of models and can yield errors.
```

This happens with version `5.0.0.dev0`


### Who can help?

_No response_

### Information

- [x] The official example scripts
- [ ] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [ ] My own task or dataset (give details below)

### Reproduction

```python
from transformers import Sam3TrackerProcessor, Sam3TrackerModel

model = Sam3TrackerModel.from_pretrained("facebook/sam3")
processor = Sam3TrackerProcessor.from_pretrained("facebook/sam3")
```

### Expected behavior

Idealy the model should be instantiated without a Warning.

## Solution
<!-- Describe your solution -->

## Tests
<!-- Describe tests added/modified -->

## Checklist
- [ ] Code follows project style guidelines
- [ ] Tests added/updated and passing
- [ ] Documentation updated (if applicable)
- [ ] Self-review completed

## Additional Notes
<!-- Any additional notes -->


Comments:
Hi! I analyzed the CI failures and they appear to be unrelated to the changes in this PR:

- `test_tokenization_class_priority` - Marked as flaky, HerbertTokenizer assertion issue
- `test_apply_chat_template_with_audio` - Audio file loading error (`bcn_weather.mp3`)
- `test_apply_chat_template_with_image` / `test_batch_apply_chat_template` - Image loading errors (`picsum_237_200x300.jpg`)
- `FuyuProcessingTest` tests - Image loading errors (`bus.png`)

The test for the feature introduced in this PR (`test_compatible_model_types_no_warning`) passes locally.

That said, I might be missing something. Please let me know if there is anything I should look into further or if you have any suggestions. Happy to make adjustments!

cc @nielsrogge @molbap @yonigozlan for SAM

> Hey @leoneperdigao ! Thank you for opening this PR! Happy to merge this, let's wait on core maintainers approval @vasqu @Cyrilvallez @ArthurZucker. Also, we have the same issue with sam2/sam2_video, would you mind adding the fix for sam2 as well? Thanks!

Thanks @yonigozlan! I fixed it for SAM2 as well

The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_43495). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Bump @vasqu @Cyrilvallez @ArthurZucker ;) 

Humm, not super convinced by the added flag. Shouldn't we simply update the MODEL_MAPPINGS here?

> Humm, not super convinced by the added flag. Shouldn't we simply update the MODEL_MAPPINGS here?

@Cyrilvallez I considered MODEL_MAPPINGS, but I believe `compatible_model_types` may be more appropriate because:

1. MODEL_MAPPINGS are for `AutoModel` automatic dispatch, whereas this warning appears during explicit config loading (e.g., `Sam2Config.from_pretrained("sam2_video_checkpoint")`)

2. `compatible_model_types` explicitly documents the compatibility relationship in the config itself

3. Modifying MODEL_MAPPINGS could have unintended side effects on AutoModel behavior

That said, I'm open to discussion! Could you clarify which specific MODEL_MAPPING you had in mind and how it would address the warning for explicit config loading? I want to make sure I understand your suggestion correctly.

Oh indeed you're not using AutoModel in your example, sorry. Then I believe the warning is very legitimate. You're not using the correct model class, so I think it's quite important that the user be aware that the weights may not load correctly. 
IDK what you think @vasqu @ArthurZucker but I tend to lend against this change, as I think it would open a pandora box of potential issues if we start relying on it, and I believe the warning is legitinate/not harmful in general here

> Oh indeed you're not using AutoModel in your example, sorry. Then I believe the warning is very legitimate. You're not using the correct model class, so I think it's quite important that the user be aware that the weights may not load correctly. IDK what you think @vasqu @ArthurZucker but I tend to lend against this change, as I think it would open a pandora box of potential issues if we start relying on it, and I believe the warning is legitinate/not harmful in general here


That's a fair point - I understand the concern.

On the other hand the original issue (#43408) raises a valid UX concern: the warning can be misleading for architecturally compatible models (like sam2/sam3 and their video variants), potentially causing "warning fatigue" or unnecessary confusion.

If we feel it is not good to incorporate this change as is, I'd then suggest the following:

1. Adjust the warning text to indicate this *might* be intentional (e.g., "This may be expected if the models share compatible architectures")

2. Document the relationship in the sam2/sam3 config docstrings without suppressing the warning

Agreeing with @Cyrilvallez here, it should be a rare occurrence and it will open a whole other set of issues in the future for us if we get lenient on config standards. I think that adjusting the warning message + docstring is the best solution for now as you pointed out

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

run-slow: edgetam, sam2, sam3, sam3_tracker

@Cyrilvallez @vasqu  I adjusted as agreed. Can you verify ?