Skip to content

Fix TensorRT GridSample inference for LT-DETR - #917

Merged
yutong-xiang-97 merged 4 commits into
mainfrom
yutong-trn-2329-fix-tensorrt-gridsample
Jul 28, 2026
Merged

Fix TensorRT GridSample inference for LT-DETR#917
yutong-xiang-97 merged 4 commits into
mainfrom
yutong-trn-2329-fix-tensorrt-gridsample

Conversation

@yutong-xiang-97

@yutong-xiang-97 yutong-xiang-97 commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

What has changed and why?

This is PR 2 of a three-PR stack and is based on
yutong-trn-2329-fix-onnx-verification.

LT-DETR TensorRT engines could build and run successfully while silently producing
incorrect detections or segmentations because TensorRT compiled the deformable-attention
GridSample path incorrectly.

For ONNX export, the affected DFINE and RT-DETRv2 attention modules now replace native
grid_sample with equivalent gather-based bilinear interpolation built from simpler
operations such as Pad, Gather, multiplication, and addition. The resulting ONNX
graphs contain no GridSample nodes, so no opset-specific TensorRT parser workaround is
needed. Training and ordinary deployment retain the faster native grid_sample path.

The ONNX-only conversion is applied through an explicit runtime-checkable export
protocol. DINOv3 ViT-S/16 FP16 TensorRT export remains strongly typed independently of
the GridSample fix, preserving the graph's FP32 attention operations and preventing
FP16 overflow. Other model and precision combinations retain the existing weakly typed
path.

How has it been tested?

Raw ONNX Runtime versus TensorRT results on the T4 with TensorRT 10.13.3.9:

  • Object detection:
    • logits max/mean difference: 7.97e-4 / 1.46e-5
    • boxes max/mean difference: 5.21e-5 / 3.58e-7
  • Instance segmentation:
    • labels: exact match
    • boxes max/mean difference: 1.05e-2 / 1.48e-4
    • masks max/mean difference: 1.16e-3 / 2.95e-5
    • scores max/mean difference: 6.87e-6 / 4.29e-7

Did you update CHANGELOG.md?

  • Yes
  • Not needed (internal change)

Did you update the documentation?

  • Yes
  • Not needed (the exported model interface is unchanged)

@yutong-xiang-97
yutong-xiang-97 force-pushed the yutong-trn-2329-fix-onnx-verification branch from 4927b77 to 9029640 Compare July 28, 2026 09:42
@yutong-xiang-97
yutong-xiang-97 marked this pull request as ready for review July 28, 2026 11:32
@yutong-xiang-97

Copy link
Copy Markdown
Contributor Author

/review

@yutong-xiang-97
yutong-xiang-97 force-pushed the yutong-trn-2329-fix-tensorrt-gridsample branch from 30684c0 to c4f5bc2 Compare July 28, 2026 11:49
Base automatically changed from yutong-trn-2329-fix-onnx-verification to main July 28, 2026 12:46
yutong-xiang-97 and others added 3 commits July 28, 2026 15:01
The gather-based bilinear replacement for grid_sample removes the ONNX
GridSample op that TensorRT miscompiled, so weakly-typed TensorRT export is
now numerically correct for DINOv3 ViT-S/16 LT-DETR (verified on a T4 with
TensorRT 10.16: 100% top-class agreement and tight boxes vs PyTorch). Treat
this model like every other LT-DETR model instead of forcing a strongly-typed
network.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@yutong-xiang-97
yutong-xiang-97 force-pushed the yutong-trn-2329-fix-tensorrt-gridsample branch from a12afee to ac6500e Compare July 28, 2026 13:01

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ac6500e1c0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/lightly_train/_task_models/ltdetr_object_detection/task_model.py Outdated
Comment thread src/lightly_train/_export/tensorrt_helpers.py Outdated
@yutong-xiang-97
yutong-xiang-97 enabled auto-merge (squash) July 28, 2026 14:30

@gabrielfruet gabrielfruet left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@yutong-xiang-97
yutong-xiang-97 merged commit 7fa5b05 into main Jul 28, 2026
13 checks passed
@yutong-xiang-97
yutong-xiang-97 deleted the yutong-trn-2329-fix-tensorrt-gridsample branch July 28, 2026 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants