[RT-DETR] Fix onnx inference bug for Optype (Where)
Author: YHallouard
Pull request: yes

# What does this PR do?

- ~~Implement `RTDetrOnnxConfig` for RT-DETR~~
- Fix Error `Error: Type parameter (T) of Optype (Where) bound to different types (tensor(float) and tensor(double) in node (/model/decoder/Where)` during onnx inference. Already fixed on lyuwenyu/RT-DETR (https://github.com/lyuwenyu/RT-DETR/issues/307)

Fixes


## Before submitting
- [X] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [X] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#create-a-pull-request),
      Pull Request section?
- [X] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? Please add a link
      to it if that's the case. https://github.com/lyuwenyu/RT-DETR/issues/307
- [ ] Did you make sure to update the documentation with your changes? Here are the
      [documentation guidelines](https://github.com/huggingface/transformers/tree/main/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [X] Did you write any new necessary tests? No, I didn't found any tests related to OnnxConfig. But I still open to add tests if you think it is required.


## 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.

<!-- 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, @qubvel
- speech models: @ylacombe, @eustlb
- graph models: @clefourrier

Library:

- flax: @sanchit-gandhi
- generate: @zucchini-nlp (visual-language models) or @gante (all others)
- pipelines: @Rocketknight1
- tensorflow: @gante and @Rocketknight1
- tokenizers: @ArthurZucker
- trainer: @muellerzr and @SunMarc
- chat templates: @Rocketknight1

Integrations:

- deepspeed: HF Trainer/Accelerate: @muellerzr
- ray/raytune: @richardliaw, @amogkam
- Big Model Inference: @SunMarc
- quantization (bitsandbytes, autogpt): @SunMarc

Documentation: @stevhliu

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:
Hey! 🤗 Thanks for your contribution to the `transformers` library!

Before merging this pull request, slow tests CI should be triggered. To enable this:
- Add the `run-slow` label to the PR
- When your PR is ready for merge and all reviewers' comments have been addressed, push an empty commit with the command `[run-slow]` followed by a comma separated list of all the models to be tested, i.e. `[run_slow] model_to_test_1, model_to_test_2`
  - If the pull request affects a lot of models, put at most 10 models in the commit message
- A `transformers` maintainer will then approve the workflow to start the tests

(For maintainers) The documentation for slow tests CI on PRs is [here](https://www.notion.so/huggingface2/CI-for-pull-requests-8335bd9217d24d1e8ed1d3a016f39804).

Hi @SangbumChoi, how are you ? I saw that you were the main maintainer of RT-DETR. Thank you very much for your work !

I propose a fix for the anchor generation to avoid a bug in onnx inference : `Error: Type parameter (T) of Optype (Where) bound to different types (tensor(float) and tensor(double) in node (/model/decoder/Where)`. It has already been discussed here: https://github.com/lyuwenyu/RT-DETR/issues/307

What do you feel about it ? 

> Thanks for the contribution! For me it looks great,
> 
> 1. I think it would be helpful to add some ONNX conversion description script in `rt_detr.md`?
> 
> Requesting @qubvel for the final approvement!

Thanks for your reply ! Yes it would be interesting, what do you think about adding a section : 

----


## ONNX Tips
See `RTDetrConfig` in this section. (put the link to that section)
```python
from transformers.models.rt_detr.import RTDetrConfig, RTDetrOnnxConfig  # type: ignore[import-untyped]
from transformers.onnx.convert import export_pytorch  # type: ignore[import-untyped]

rtdetr_onnx_config = RTDetrOnnxConfig(config=RTDetrConfig(), task="object-detection")

export_pytorch(
    preprocessor=preprocessor,
    model=model,
    config=rtdetr_onnx_config,
    opset=17,
    output=output_path,
    tokenizer=None,
    device="cuda",
)
```

> t will be better to add this config to [Optimum](https://github.com/huggingface/optimum),

Hi @qubvel, honestly I wasn't aware of this repository ! Very interesting discovery ! 
I see how to put it in optimum, but since there is no `ORTModelForObjectDetection` yet in Optimum (thing i can work on maybe in the future). What do you think about putting this config (RTDetrOnnxConfig) in transformers and in optimum ?

But I can rework the `rt_detr.md`Onnx section, specifying in transformer section that is deprecated and also put a optimum section

Hey @YHallouard sorry for the confusion, I think we need better doc on this  😢 let's not add anything that we know is already deprecated! If you need guidance on ONNX and Optimum contribution for this, I am sure @michaelbenayoun will be happy to help! 

Hi @ArthurZucker, @michaelbenayoun, 

No problem, I removed th Onnx config and openned a pull request in optimum. https://github.com/huggingface/optimum/pull/2040

Hi @ArthurZucker, should I run a `run-slow` ?

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