Mamba in RT-DETRv4 — What Could Make It Faster

  1. 1Mamba — Selective State Spaces, Step by Step
  2. 2Mamba-2 — When a State Space Model Is a Masked Attention Matrix
  3. 3Mamba-3 — A Better Step, a Turning State, More Work per Byte
  4. 4VMamba — Scanning an Image Four Ways
  5. 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. 1. What v4 Runs, and Where the Work Goes2
  2. 2. The Core Fact: AIFI Is Already Cheap2
  3. 3. What Others Measured2
  4. 4. What We Can Do, Ranked2
  5. 5. Getting a Scan onto a T42
  6. 6. The Experiment Plan2
  7. 7. Conclusion2
  8. 8. References2
  9. 9. Connections2
TrivediInformational[Page 1]
S. TrivediOct 2026

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.

  1. HGNetv2 → S3, S4, S5: at 640 × 640, 6,400, 1,600 and 400 tokens, width d = 256 (384 for X).
  2. AIFI: one attention layer on S5; its output F5 is what the teacher aligns to.
  3. CCFF: four convolution fusion blocks, then 300 queries → a 3- to 6-layer decoder.
4 / 5 · v44 / 8 · AIFI on S5
One pipeline, five versions. The RT-DETR pipeline for a 640 × 640 image, block by block. Step through the stages to see each block's output shape; switch the version to see which blocks it changes (rust outline), and switch to training to see the dashed parts that exist only while the model learns and are removed at inference.

No paper times v4 part by part; the nearest timings:

PartNearest published timingMy count, v4-S
AIFIits slot: 1.28 ms, RT-DETR-R18, RTX 3090, TensorRT FP16 (my conversion of Tab. 7 of [YANG26])0.40 G (3.2 %)
fusion blockshalving 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 %)
decoder0.4–0.5 ms per layer, RT-DETR-R50, T4 (Tab. 5 of [ZHAO24])not counted
whole model3.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 dff:

AIFI(L)=4Ld2⏟Q, K, V, out+2L2d⏟attention+2Lddff⏟FFN(1)

At S5 (L = 400, d = 256, dff = 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).

6405 / 6 · D_S5
Where the encoder spends its attention. Counts: how many attention scores one encoder layer computes as the input grows, if every token of the three maps attended to every other, if each map attended only to itself, or if only the 20 × 20 map did (AIFI); the rust line is what a deformable encoder samples instead. These are counts, not time. Measured: the paper's own walk from variant A to E, AP against latency.
5 / 7 · RT-DETRv4 S5640
RT-DETRv4 only
Tokens, cost and MambaOut's line. Multiply-adds, not time, on a log scale: one token mixer (or one whole block, with its feed-forward layer) at each place, for VMamba's scan, global attention and 7 × 7 windows. The shaded places are the ones MambaOut would call long, L > 6D, its line for a block with a feed-forward layer of 4D. My count; for the whole VMamba-T it lands within 1 % of the paper's.

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:

PaperChangeResultSpeed
EfficientIR-Det [YANG26]AIFI → bidirectional scan, RT-DETR-R18, infrared54.9 → 55.1 mAP50:95127.1 → 147.7 FPS; no AIFI 151.7 (3090, TensorRT FP16, Tab. 7)
Le-DETR [HUAN26]AIFI → local attention54.1 → 54.3 mAP5.18 → 5.01 ms (4090, FP16, PyTorch profiler, Tab. 3)
MSW-Mamba-Det [WANG26b]scan backbone + two more modules, RT-DETR57.9 → 60.4 AP50:95114.7 → 99.4 FPS; backbone alone 110.3 (3080)
Mamba YOLO [WANG24b]scan backbone + neck, COCOT 44.5 vs YOLOv8-S 44.9 AP1.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 / 6 · as deployed1 / 4 · S
Where a scan could save time. My placements, not measured on RT-DETRv4. Costs are my multiply-add counts at 640 × 640: what each change adds (+) or saves (−), next to the nearest timing someone published. Start at "as deployed" to see where the encoder's work goes; the dashed parts exist only in training, and F5 is the map the teacher is aligned to.

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.

5 / 7 · RT-DETRv4 S51280
RT-DETRv4 only
Tokens, cost and MambaOut's line. Multiply-adds, not time, on a log scale: one token mixer (or one whole block, with its feed-forward layer) at each place, for VMamba's scan, global attention and 7 × 7 windows. The shaded places are the ones MambaOut would call long, L > 6D, its line for a block with a feed-forward layer of 4D. My count; for the whole VMamba-T it lands within 1 % of the paper's.

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.

  1. Reproduce v4-S's 3.66 ms and 49.8 AP.
  2. Ceilings, no training: time v4 without AIFI, and with a narrower P3 block.
  3. Arm C: scan fusion block at P3, against a gated convolution of the same count.
  4. Arm A: a bidirectional scan for AIFI, DSI on the new F5, ρ searched again; also Mamba-2's chunked form.
  5. 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

  1. [LIAO25] Liao et al. RT-DETRv4: Painlessly Furthering Real-Time Object Detection with Vision Foundation Models. arXiv 2510.25257.
  2. [ZHAO24] Zhao et al. DETRs Beat YOLOs on Real-time Object Detection. CVPR 2024, arXiv 2304.08069.
  3. [PENG24] Peng et al. D-FINE: Redefine Regression Task in DETRs as Fine-grained Distribution Refinement. ICLR 2025, arXiv 2410.13842.
  4. [HUAN24] Huang et al. DEIM: DETR with Improved Matching for Fast Convergence. CVPR 2025, arXiv 2412.04234.
  5. [SIME25] Siméoni et al. DINOv3. arXiv 2508.10104.
  6. [GU23] Gu, Dao. Mamba: Linear-Time Sequence Modeling with Selective State Spaces. arXiv 2312.00752.
  7. [DAO24] Dao, Gu. Transformers are SSMs: Generalized Models and Efficient Algorithms Through Structured State Space Duality. arXiv 2405.21060.
  8. [LIU24] Liu et al. VMamba: Visual State Space Model. NeurIPS 2024, arXiv 2401.10166.
  9. [YU24] Yu, Wang. MambaOut: Do We Really Need Mamba for Vision? arXiv 2405.07992.
  10. [ZHU24] Zhu et al. Vision Mamba: Efficient Visual Representation Learning with Bidirectional State Space Model. ICML 2024, arXiv 2401.09417.
  11. [YANG26] Yang, Li, Xie. EfficientIR-Det: Towards Efficient and Accurate DETR for UAV Infrared Object Detection. Sensors 26(10):3129, 2026.
  12. [HUAN26] Huang et al. Le-DETR: Revisiting Real-Time Detection Transformer with Efficient Encoder Design. CVPR Findings 2026, arXiv 2602.21010.
  13. [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.
  14. [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).
  15. [YEHU26] Yehuala, Cheng, Lehtola. Increasing the Efficiency of DETR for Maritime High-Resolution Images. IEEE ITSC 2026, arXiv 2605.10269.
  16. [WANG24b] Wang et al. Mamba YOLO: A Simple Baseline for Object Detection with State Space Model. AAAI 2025, arXiv 2406.05835.
  17. [LEI25] Lei et al. MambaNeXt-YOLO: A Hybrid State Space Model for Real-time Object Detection. arXiv 2506.03654.
  18. [FAN26] Fan, Hui, Dai. LCMamNet: A Lightweight Cross-scale Mamba Network for Infrared Small Target Detection. arXiv 2607.24184.
  19. [STAT24] state-spaces/mamba issue #200: Generating onnx file for the inference of Mamba? 2024.
  20. [MZER24] MzeroMiko/VMamba issue #16: Vmamba's inference speed. 2024.
  21. [MICR26] microsoft/onnxruntime issue #27796: ONNX Loop op makes Mamba (SSM) models unusable on CPU and WebGPU. 2026.
  22. [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.

POINTS AT THIS PAGEPAPER · LINKED IN THE TEXTVMamba — Scanning an Image Four WaysThis pageTHIS PAGE POINTS ATPAPERRT-DETR — DETRs Beat YOLOs, Encoder byEncoderPAPERRT-DETRv4 — Borrowing a FoundationModel's EyesPAPERVMamba — Scanning an Image Four WaysPAPER · CITEDMamba — Selective State Spaces, Step byStepPAPER · CITEDMamba-2 — When a State Space Model Is aMasked Attention MatrixREFERENCE · CITED17 more papers, in the reference list

Related

Go deeper

  1. Start with
    Read
  2. Paper
  3. Paper
  4. Paper
  5. Paper
  6. Paper
  7. Read
  8. Read
  9. Paper
  10. Read
  11. Paper
  12. Paper
  13. Paper
  14. Paper
  15. Paper
  16. Paper
  17. Paper
  18. Paper
  19. Read
  20. Paper
  21. Paper
  22. Read
  23. Paper
  24. Paper
  25. Paper
  26. Paper
  27. You are here
    Mamba in RT-DETRv4 — What Could Make It Faster
    Read

Go broader

<- Older [Page 2] Newer ->