Fix RT-DETR indexing error when num_feature_levels exceeds backbone o…
Author: c1prk
Pull request: yes

<!-- ci-dashboard-badge:start -->
[![CI](https://transformers-ci.lor-e.huggingface.cool/badge/pr?pr=46833)](https://transformers-ci.lor-e.huggingface.cool/d/pytest-observability-by-pr/pytest-observability-branch?var-pr=46833)
<!-- ci-dashboard-badge:end -->

# What does this PR do?

Fixes a `TypeError` in `RTDetrModel.forward` that occurs when `num_feature_levels` is set higher than the number of backbone output levels (default is 3).

When extra decoder feature levels need to be synthesized, the first extra level passed the entire list of encoder feature maps to a `Conv2d` layer and indexed `[-1]` on the *result*, instead of indexing `[-1]` on the input list first to select a single tensor. The corrected line now matches the pattern already used correctly on the very next line of the same block.

```python
# Before (buggy): indexes the conv2d output, passing a list into conv2d
sources.append(self.decoder_input_proj[_len_sources](encoder_outputs.last_hidden_state)[-1])

# After (correct): indexes the input list first, passing a single tensor
sources.append(self.decoder_input_proj[_len_sources](encoder_outputs.last_hidden_state[-1]))
```

The change is made in `modular_rt_detr.py` (the source of truth) and `modeling_rt_detr.py` is regenerated from it. The default config (`num_feature_levels=3`) is unaffected, so no existing behavior changes. A regression test was added that builds the model with `num_feature_levels=4` and confirms the forward pass returns logits of the expected shape.

AI assistance was used to help diagnose and draft this fix; I reviewed and verified every changed line and reproduced both the bug and the fix myself.

Fixes #46832

## Code Agent Policy

- [x] 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).
- [x] Did you read the [contributor guideline](https://huggingface.co/docs/transformers/contributing) and the [Pull Request](https://huggingface.co/docs/transformers/pr_checks) checks?
- [x] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? #46832
- [ ] Did you make sure to update the documentation with your changes according to the [guidelines](https://github.com/huggingface/transformers/tree/main/docs)?
- [x] Did you write any new necessary [tests](https://huggingface.co/docs/transformers/testing)?

## Test results

```
python -m pytest tests/models/rt_detr/test_modeling_rt_detr.py -k num_feature_levels -v
```
(passes locally)

## Who can review?

@yonigozlan @molbap

<!-- ci-dashboard-recap:start -->

---

### CI recap

**Dashboard:** [View test results in Grafana](https://transformers-ci.lor-e.huggingface.cool/d/pytest-observability-by-pr/pytest-observability-branch?var-pr=46833)
**Latest run:** [28008623115:2](https://github.com/huggingface/transformers/actions/runs/28065725740)
**Result:** `success` | **Jobs:** 4 | **Tests:** 1,015 | **Failures:** 0 | **Duration:** 5m 32s

<!-- ci-dashboard-recap:end -->

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

run-slow: d_fine, pp_doclayout_v2, rt_detr, rt_detr_v2

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