Mamba in RT-DETRv4 — What Could Make It Faster
- 1Mamba — Selective State Spaces, Step by Step
- 2Mamba-2 — When a State Space Model Is a Masked Attention Matrix
- 3Mamba-3 — A Better Step, a Turning State, More Work per Byte
- 4VMamba — Scanning an Image Four Ways
- 5Mamba in RT-DETRv4 — What Could Make It Faster
Summary
RT-DETRv4's one attention layer works on 400 tokens, so a scan has little to save there. This read follows the work through v4 at inference, ranks five places a Mamba-style block could go by what each could save, puts my multiply-add counts next to the timings other papers published, and ends with the experiment I would run. Nothing here has been run on RT-DETRv4.
Table of Contents
- 1. What v4 Runs, and Where the Work Goes2
- 2. The Core Fact: AIFI Is Already Cheap2
- 3. What Others Measured2
- 4. What We Can Do, Ranked2
- 5. Getting a Scan onto a T42
- 6. The Experiment Plan2
- 7. Conclusion2
- 8. References2
- 9. Connections2
Think of v4 as a kitchen. Everybody wants to replace the chef who looks slow (AIFI, the attention layer), but the queue is at the prep station (the fusion blocks). Mamba [GU23] mixes tokens at linear cost, so: where in RT-DETRv4 [LIAO25] could a Mamba-style block save time?
NOTE: This is not a paper, and nothing here has been run on RT-DETRv4. It is an idea that still needs implementing and timing. "My count" is my arithmetic; every placement is my proposal. Have a suggestion, or tried one of these? Mention this read and mail it to contact@shreejal.ai.
How it could get faster, in short (§4 has the numbers):
- Slim the fusion blocks, not AIFI. A lighter scan block at P3 in place of the convolution block: about 16 % less work for v4-S, my count.
- Swap AIFI for a scan only after that: one published swap ran 0.8–1.1 ms faster, but it moves the map the teacher trains on.
- Use scans when the image gets big (around 1,280 px and up), where attention's cost grows fastest.
Brush up ;) RT-DETRv4 — Borrowing a Foundation Model's Eyes for DSI and GAM, RT-DETR — DETRs Beat YOLOs, Encoder by Encoder §3 for AIFI and CCFF, VMamba — Scanning an Image Four Ways for SS2D.
1. What v4 Runs, and Where the Work Goes
At inference v4 is D-FINE's network [PENG24] trained with DEIM's recipe [HUAN24]; the DINOv3 teacher [SIME25] and GAM exist only in training.
- HGNetv2 → S3, S4, S5: at 640 × 640, 6,400, 1,600 and 400 tokens, width d = 256 (384 for X).
- AIFI: one attention layer on S5; its output F5 is what the teacher aligns to.
- CCFF: four convolution fusion blocks, then 300 queries → a 3- to 6-layer decoder.
No paper times v4 part by part; the nearest timings:
| Part | Nearest published timing | My count, v4-S |
|---|---|---|
| AIFI | its slot: 1.28 ms, RT-DETR-R18, RTX 3090, TensorRT FP16 (my conversion of Tab. 7 of [YANG26]) | 0.40 G (3.2 %) |
| fusion blocks | halving their width, a step on the way to D-FINE-L: 10.69 → 8.01 ms, T4 (Tab. 3 of [PENG24]) | 6.14 G (49 %) |
| decoder | 0.4–0.5 ms per layer, RT-DETR-R50, T4 (Tab. 5 of [ZHAO24]) | not counted |
| whole model | 3.66 / 5.91 / 8.07 / 12.90 ms, S / M / L / X, T4, TensorRT FP16 (Tab. 1 of [LIAO25]) | — (Table 1: 25 GFLOPs) |
Table. 1 Where the work goes. My counts are multiply-adds at 640 × 640, batch 1; shares count 2 FLOPs per multiply-add against Table 1's 25 GFLOPs (0.40 G = 0.79 GFLOPs = 3.2 %).
NOTE: v4 does not say if its GFLOPs are FLOPs or multiply-adds; my count of D-FINE's "halve the fusion width" step gives 75.4 GFLOPs against its published 76 G drop, so I read FLOPs. And work is not time: that step cut 45 % of the FLOPs and 25 % of the latency.
2. The Core Fact: AIFI Is Already Cheap
One AIFI layer in multiply-adds, with L tokens, width d and FFN width :
At S5 (L = 400, d = 256, = 1024): 0.105 + 0.082 + 0.210 = 0.396 G. The L² term, the only one a scan removes, is the smallest.
- A VSS block [LIU24] in VMamba's released setting saves 0.115 G, 0.9 % of v4-S; in Mamba's own setting it costs 0.091 G more.
- MambaOut [YU24]: attention outgrows the linear terms only when L > 6d, 1,536 tokens. S5 sits at 0.26 of that line.
So at 640 × 640 a scan cannot make AIFI meaningfully cheaper in arithmetic; whether it runs faster is a kernel question (§3).
RT-DETRv4 only
3. What Others Measured
I found no paper that puts Mamba inside RT-DETRv2, v3, v4 or D-FINE (searched 2026-10-19). One puts an SSM backbone into DEIM for steel defects [HU26], but it is behind a paywall and I could not read it. Our list is a plan, not a result. The closest timings:
| Paper | Change | Result | Speed |
|---|---|---|---|
| EfficientIR-Det [YANG26] | AIFI → bidirectional scan, RT-DETR-R18, infrared | 54.9 → 55.1 mAP50:95 | 127.1 → 147.7 FPS; no AIFI 151.7 (3090, TensorRT FP16, Tab. 7) |
| Le-DETR [HUAN26] | AIFI → local attention | 54.1 → 54.3 mAP | 5.18 → 5.01 ms (4090, FP16, PyTorch profiler, Tab. 3) |
| MSW-Mamba-Det [WANG26b] | scan backbone + two more modules, RT-DETR | 57.9 → 60.4 AP50:95 | 114.7 → 99.4 FPS; backbone alone 110.3 (3080) |
| Mamba YOLO [WANG24b] | scan backbone + neck, COCO | T 44.5 vs YOLOv8-S 44.9 AP | 1.5 vs 1.9 ms (4090, TensorRT FP16, Tab. 1) |
Table. 2 As each paper reports it. None is v4, none is timed on a T4.
- AIFI's slot is small: 1.28 ms with attention, 0.18 ms with the scan, of 7.87 ms (my conversion; Tab. 4 prints 141.6 FPS for the scan). The same R18 runs in 4.61 ms on a T4 (Tab. 1 of [LIAO25]): only the share, about 16 %, transfers.
- Scan backbones are not faster on the edge: on a Jetson Orin, TensorRT FP16, Mamba-YOLO-T runs at 34.3 FPS against YOLOv8-S's 67.5 (Tab. 7 of [LEI25]).
- Scans pay at high resolution: Vim is "2.8× faster than DeiT" at 1248 × 1248 [ZHU24]. At 1920 × 1080 a pruned ViM-backbone DETR runs at 6.9 FPS, its ViT twin 3.6, RT-DETR-R50 1.1 (Quadro T600 [YEHU26]): pruning does much of it.
4. What We Can Do, Ranked
All five are my proposals, ranked by what they could save.
1. A scan fusion block at P3 (C). - Change: the P3 fusion block → a 1 × 1 from 512 to 256, then a VMamba-style scan mixer. - Why: the fusion blocks hold the work (49 % of v4-S, 38 % of v4-L); on the way to D-FINE-L their width was worth 2.68 ms. My count: −1.95 G for S (−16 %), −9.13 G for L; Mamba's own setting gives S +1.35 G. - Risk: the saving comes from the slimmer block, not the scan; P3 carries the small objects (v4-S APS 30.6); a 6,400-step scan must reach TensorRT (§5). - Measure: against a gated convolution of the same count (MambaOut's control).
2. AIFI → a bidirectional scan (A). - Why: the only timed AIFI → scan swap, 0.8–1.1 ms faster on a 3090 (Tab. 4 and 7 of [YANG26]) at 0.7 GFLOPs more (57.7 vs 57.0): kernel time, not arithmetic. - Risk: F5 becomes the scan's output. v4's gain hangs on aligning F5 to DINOv3 (54.3 vs 53.8 AP, Tab. 3 of [LIAO25]); GAM's ρ = 11 / 3.5 / 2 / 2 % is tuned on AIFI's gradient (Tab. A). - Measure: first time v4 with AIFI removed; that ceiling needs no training.
3. A scan only when the input grows. At 1280 × 1280, S5 holds 1,600 tokens: AIFI 2.57 G, scan 1.12 G, 7 × 7 windows 1.30 G (my count). MambaOut's L = 6d line (1,536 tokens at S5) is crossed between 1,248 and 1,280 px; windows win almost as much with plain matrix multiplies.
RT-DETRv4 only
4. Global mixing at S3 (B). 5.8× cheaper than attention there, but it adds +4.50 G (+36 % of v4-S). Attention on S3 and S4 cost RT-DETR +4.3 ms and −0.4 AP (my difference of D and D_S5, Tab. 3 of [ZHAO24]). Accuracy, not speed.
5. A scan backbone (D). 4.4 G per block for S, 17.8 G for L, before subtracting the block it replaces; slower on the edge (Table 2), and HGNetv2's pretraining is lost.
Not worth it: the decoder (300 queries have no order; its knob is the layer count) and Mamba's own setting (dearer than AIFI and the S fusion block).
5. Getting a Scan onto a T4
v4 ships as ONNX opset 16 → TensorRT FP16; a scan has no standard road there:
- No ONNX op; its author: "We have no experience with ONNX" [STAT24]. In a VMamba block the scan "takes 80%+ of the training time" [MZER24].
- Generic export gives a slow Loop op or a 298 MB unrolled graph [MICR26]; NVIDIA's plugin is for language models, "O(seq_len) serial launches" [NVID26a].
- Accuracy can drop: LCMamNet went from 71.18 mIoU in PyTorch FP16 to 65.96 in TensorRT FP16 (Tab. II of [FAN26]).
My routes, none tried: unroll the fixed-size scan, wrap the GPU kernel in a plugin, use Mamba-2's chunked form [DAO24] (Mamba-2 — When a State Space Model Is a Masked Attention Matrix), or a gated convolution.
6. The Experiment Plan
Table 1's protocol (T4, TensorRT FP16, batch 1, 640 × 640) with v4's own export and benchmark scripts.
- Reproduce v4-S's 3.66 ms and 49.8 AP.
- Ceilings, no training: time v4 without AIFI, and with a narrower P3 block.
- Arm C: scan fusion block at P3, against a gated convolution of the same count.
- Arm A: a bidirectional scan for AIFI, DSI on the new F5, ρ searched again; also Mamba-2's chunked form.
- Report AP, APS, latency and export route. Success: v4's AP at lower latency.
7. Conclusion
- The work is in the fusion blocks (49 % of v4-S, my count), not in AIFI (3.2 %); at 640 a scan at S5 has almost nothing to save.
- Try first a slimmer scan fusion block at P3 against a gated convolution, then the AIFI swap.
- Missing: a T4 timing of any selective scan, and a standard road to TensorRT.
Again: this is an idea, not a result. If you implement any of it, or see a better place for the scan, mail contact@shreejal.ai and mention this read.
The series ends here. For the scan itself, go back to Mamba — Selective State Spaces, Step by Step. Stay tuned ;)
8. References
- [LIAO25] Liao et al. RT-DETRv4: Painlessly Furthering Real-Time Object Detection with Vision Foundation Models. arXiv 2510.25257.
- [ZHAO24] Zhao et al. DETRs Beat YOLOs on Real-time Object Detection. CVPR 2024, arXiv 2304.08069.
- [PENG24] Peng et al. D-FINE: Redefine Regression Task in DETRs as Fine-grained Distribution Refinement. ICLR 2025, arXiv 2410.13842.
- [HUAN24] Huang et al. DEIM: DETR with Improved Matching for Fast Convergence. CVPR 2025, arXiv 2412.04234.
- [SIME25] Siméoni et al. DINOv3. arXiv 2508.10104.
- [GU23] Gu, Dao. Mamba: Linear-Time Sequence Modeling with Selective State Spaces. arXiv 2312.00752.
- [DAO24] Dao, Gu. Transformers are SSMs: Generalized Models and Efficient Algorithms Through Structured State Space Duality. arXiv 2405.21060.
- [LIU24] Liu et al. VMamba: Visual State Space Model. NeurIPS 2024, arXiv 2401.10166.
- [YU24] Yu, Wang. MambaOut: Do We Really Need Mamba for Vision? arXiv 2405.07992.
- [ZHU24] Zhu et al. Vision Mamba: Efficient Visual Representation Learning with Bidirectional State Space Model. ICML 2024, arXiv 2401.09417.
- [YANG26] Yang, Li, Xie. EfficientIR-Det: Towards Efficient and Accurate DETR for UAV Infrared Object Detection. Sensors 26(10):3129, 2026.
- [HUAN26] Huang et al. Le-DETR: Revisiting Real-Time Detection Transformer with Efficient Encoder Design. CVPR Findings 2026, arXiv 2602.21010.
- [WANG26b] Wang et al. MSW-Mamba-Det: Multi-Scale Windowed State-Space Modeling for End-to-End Defect Detection in Photovoltaic Module Electroluminescence Images. Sensors 26(9):2616, 2026.
- [HU26] Hu, Zhou, Xu. Mamba-HCIM: A Lightweight Steel Plate Surface Defect Detector via Spatial-Frequency Dual Enhancement. The Journal of Supercomputing 82:441, 2026 (not read).
- [YEHU26] Yehuala, Cheng, Lehtola. Increasing the Efficiency of DETR for Maritime High-Resolution Images. IEEE ITSC 2026, arXiv 2605.10269.
- [WANG24b] Wang et al. Mamba YOLO: A Simple Baseline for Object Detection with State Space Model. AAAI 2025, arXiv 2406.05835.
- [LEI25] Lei et al. MambaNeXt-YOLO: A Hybrid State Space Model for Real-time Object Detection. arXiv 2506.03654.
- [FAN26] Fan, Hui, Dai. LCMamNet: A Lightweight Cross-scale Mamba Network for Infrared Small Target Detection. arXiv 2607.24184.
- [STAT24] state-spaces/mamba issue #200: Generating onnx file for the inference of Mamba? 2024.
- [MZER24] MzeroMiko/VMamba issue #16: Vmamba's inference speed. 2024.
- [MICR26] microsoft/onnxruntime issue #27796: ONNX Loop op makes Mamba (SSM) models unusable on CPU and WebGPU. 2026.
- [NVID26a] NVIDIA TensorRT-Edge-LLM 0.9.0 docs: Mamba Plugin. 2026.
9. Connections
What this page builds on, cites or links to, and what points back at it. A plain box is a “builds on”; “cited” and “linked in the text” are the lighter links. Hover a box for a preview.
Related
- Paper · this builds on it
- Paper · this builds on it (earlier in the series)
- Paper · same series: Mamba
- Paper · same series: Mamba
- Paper · this builds on it
- Read · cites the same paper
Go deeper
-
Start withRead
-
Paper
-
Paper
-
Paper
-
Paper
-
Paper
-
Read
-
Read
-
Paper
-
Read
-
Paper
-
Paper
-
Paper
-
Paper
-
Paper
-
Paper
-
Paper
-
Paper
-
Read
-
Paper
-
Paper
-
Read
-
Paper
-
Paper
-
Paper
-
Paper
-
You are hereMamba in RT-DETRv4 — What Could Make It FasterRead
Go broader
- Sits under
- SeriesMambapart 5 of 5 · start from the first part
- Its tags on the map
- Also under these tagsNetwork Pruning of Object DetectorsEdge deployment, Object detectionINT8 Quantization of Object DetectorsEdge deployment, Object detectionLow-Compute, High-FPS Background SubtractionEdge deploymentEfficientDet — A Comprehensive ReviewEfficient networks, Object detectionSNIPER: Efficient Multi-Scale TrainingEfficient networks, Object detection
- Ask the mapWhat connects Mamba in RT-DETRv4 and …type the other page's name; the map answers with the chain of links between them