Repository navigation
fix(FlexGlue): fix TensorRT zero-match engines; store descriptors as FP16 - #261
Merged
Merged
Conversation
…utputs The stronglyTyped FP16 matcher engine lets TensorRT fuse each 4096-token attention into one FP16 kernel that sporadically emits NaN. The NaN reaches covisibility_score and every match is dropped: ~20% of wide-baseline / revisit pairs and ~4% of adjacent keyframes on Looper bags returned zero matches, while ONNX Runtime on the same inputs was fine. make flexglue now patches the ONNX so the attention cores (MatMul, Softmax, MatMul) run in BF16 before building the engine (workspace raised to 3 GB). Matches equal ONNX Runtime; matcher time 198 -> 214 ms on an RTX 3060 laptop. Adds onnx as a dependency for the patch script. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
match_keypoints hard-coded 848x480 (RealSense), so Looper (544x640) keypoints were normalized with the wrong size. Take width/height from camera_info. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On Jetson (TensorRT 10.3) the FlexGlue matcher still returned zero matches on some pairs after the BF16 attention patch: CumSum fused with the ops that feed it is miscomputed, the soft-argmax denominators become zero, and every mutual check fails. ONNX Runtime and TRT 10.13 are fine on the same input. patch_flexglue_matcher.py (renamed from patch_flexglue_attention.py) now also replaces each last-axis CumSum by a MatMul with a constant upper-triangular matrix. On the saved failing inputs both the RTX 3060 (TRT 10.13) and Orin Nano (TRT 10.3) engines now match ONNX Runtime; Orin matcher time is unchanged (~0.5 s). The unpatched engine on Orin returns NaN/zero matches on 6 of the 8 inputs, like on desktop. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
This reverts commit 53f1b73 so the PR only carries the FlexGlue TensorRT fix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The dev container's default python3 may lack onnx (seen on Jetson), while uv sync installs it into .venv. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The descriptor engine runs in FP16, so its FP32 output is normally exact in FP16. Store it as FP16 in that case (4.2 MB -> 2.1 MB per keyframe), keep FP32 otherwise, and convert back to FP32 before matching. Maps saved before this change (FP32) load unchanged. Matches are identical for live, FP16-stored and FP32-stored features. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
xiaolefang-dm
marked this pull request as ready for review
November 10, 2026 07:35
…cisions Instead of rewriting the attention blocks in the ONNX, build the matcher without --stronglyTyped and pin the attention layers (QK^T, Softmax, PV) to BF16 with --precisionConstraints=obey --layerPrecisions. The ONNX patch now only replaces CumSum, which TensorRT 10.3 on Jetson still miscomputes. On the saved failing inputs: no NaN on RTX 3060 (TRT 10.13) or Orin Nano (TRT 10.3); matcher time unchanged. Because the rest of the network may now run in FP16, match counts are 1-2% lower on 3060 and 5-10% lower on Orin than with ONNX Runtime. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The quality check runs the latest ruff through uvx; ruff 0.17 enables many more rules by default and fails on 90 existing findings (main has failed since October). Selecting E4/E7/E9/F keeps the check stable across ruff releases and matches what the dev container's ruff 0.15 enforces. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
hitomi-krgr
added a commit
that referenced
this pull request
Nov 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
FlexGlue TensorRT matcher engines built by
make flexgluesilently return zero matches on some image pairs. ONNX Runtime on the same inputs is fine.covisibility_score, so every match is dropped. On Looper bags this hit ~20% of wide-baseline / revisit pairs and ~4% of adjacent keyframes. Fix: build without--stronglyTypedand pin the attention layers (QK^T, Softmax, PV) to BF16 with--precisionConstraints=obey --layerPrecisions=....tinynav/models/patch_flexglue_matcher.pyreplaces the 4 CumSum ops with an equivalent MatMul against a constant upper-triangular matrix, beforetrtexec. This needsonnx;makeprefers the repo.venvPython.Verification
Saved matcher inputs from Looper bags: 6 pairs that fail with the shipped engine, plus 2 control pairs. ONNX Runtime reference:
275, 264, 148, 185, 239, 244, 265, 229.275, 264, 148, 185, 239, 244, 265, 2290, 0, 0, 0, 0, 0, 266, 229272, 265, 150, 185, 239, 244, 266, 2300, 0, 0, 0, 0, 0, 266, 230263, 241, 141, 0, 228, 224, 253, 224261, 238, 140, 169, 228, 224, 247, 221--stronglyTypedTensorRT may run other layers in FP16.Notes
make -C tinynav/models flexglue.🤖 Generated with Claude Code