Add OmDet-Turbo
Author: yonigozlan
Pull request: yes
Labels: name: run-slow

# What does this PR do?

<!--
Congratulations! You've made it this far! You're not quite done yet though.

Once merged, your PR is going to appear in the release notes with the title you set, so make sure it's a great title that fully reflects the extent of your awesome contribution.

Then, please replace this with a description of the change and which issue is fixed (if applicable). Please also include relevant motivation and context. List any dependencies (if any) that are required for this change.

Once you're done, someone will review your PR shortly (see the section "Who can review?" below to tag some potential reviewers). They may suggest changes to make the code even better. If no one reviewed your PR after a week has passed, don't hesitate to post a new comment @-mentioning the same persons---sometimes notifications get lost.
-->

This PR adds support for [OmDet-Turbo](https://github.com/om-ai-lab/OmDet), an open-vocabulary detection model from Om Research Lab.



<!-- Remove if not applicable -->

## Who can review?

@amyeroberts @qubvel 

<!-- Your PR will be replied to more quickly if you can figure out the right person to tag with @

 If you know how to use git blame, that is the easiest way, otherwise, here is a rough guide of **who to tag**.
 Please tag fewer than 3 people.

Models:

- text models: @ArthurZucker
- vision models: @amyeroberts
- speech models: @sanchit-gandhi
- graph models: @clefourrier

Library:

- flax: @sanchit-gandhi
- generate: @zucchini-nlp (visual-language models) or @gante (all others)
- pipelines: @Narsil
- tensorflow: @gante and @Rocketknight1
- tokenizers: @ArthurZucker
- trainer: @muellerzr and @SunMarc

Integrations:

- deepspeed: HF Trainer/Accelerate: @muellerzr
- ray/raytune: @richardliaw, @amogkam
- Big Model Inference: @SunMarc
- quantization (bitsandbytes, autogpt): @SunMarc 

Documentation: @stevhliu and @MKhalusova

HF projects:

- accelerate: [different repo](https://github.com/huggingface/accelerate)
- datasets: [different repo](https://github.com/huggingface/datasets)
- diffusers: [different repo](https://github.com/huggingface/diffusers)
- rust tokenizers: [different repo](https://github.com/huggingface/tokenizers)

Maintained examples (not research project or legacy):

- Flax: @sanchit-gandhi
- PyTorch: See Models above and tag the person corresponding to the modality of the example.
- TensorFlow: @Rocketknight1

 -->


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

Hey @amyeroberts @qubvel !
I think this PR is ready for a first review. What's missing for now is adding/modifying tests (current ones are for Grounding Dino and not adapted to this model).
Short-terms TODOs left:
 - Tests
 - Docs, examples and some docstrings left to modify

Longer-terms TODOs:
- Add support for training

Hi @amyeroberts and @qubvel! When you have some time, could you please take another look at this PR? I've resolved your previous remarks and left the ones where I had questions open.

All the files I've modified are ready for review. I've commented out the modeling tests I haven't addressed yet (there's only one end-to-end integration test for now), but the processor tests are ready for review.

I'd like to highlight a significant issue: the `OmDetTurboMultiheadAttention` in the `OmDetTurboEncoderLayer` module. It reproduces the original model's behavior, but this one appears to be incorrectly implemented for batch inference. This issue makes the whole model unusable for batch inference if we want to use the original model weights and be consistent with the original model outputs.

Thanks in advance!

Thanks for the review @qubvel ! For the `OmdetTurboModel`, the task specific part of the model starts at the very beginning of the decoder, where there are two heads defined, one for the object detection scores and the other for the bboxes coordinates. So it is quite difficult to define a non task-specific `OmdetTurboModel`. It wouldn't be the first model not to have a `FooModel`, for example [LLaVaNext](https://github.com/huggingface/transformers/blob/8ec028adeda29fce81cf6c50fcfa2259beaea6cc/src/transformers/models/llava_next/modeling_llava_next.py#L227) doesn't have one either, maybe for the same reason? 
@amyeroberts if you think not having  `OmdetTurboModel` is ok, I think this should be ready for you to review! Sorry I probably pinged you for a final review too early before, but I'm hopeful it's better this time :)