Faster TensorRT Runtime for CellposeSAM#1356
Open
chaichontat wants to merge 1 commit intoMouseLand:mainfrom
Open
Faster TensorRT Runtime for CellposeSAM#1356chaichontat wants to merge 1 commit intoMouseLand:mainfrom
chaichontat wants to merge 1 commit intoMouseLand:mainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1356 +/- ##
==========================================
+ Coverage 42.19% 42.30% +0.10%
==========================================
Files 16 16
Lines 3773 3773
==========================================
+ Hits 1592 1596 +4
+ Misses 2181 2177 -4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
This PR introduces a TensorRT inference runtime for the CellposeSAM model targeting NVIDIA GPUs with native BF16 support (A100, H100, RTX 30/40/50 series). TensorRT is an inference optimizer and runtime that compiles a trained neural network into a highly optimized, hardware-specific engine.
This implementation achieves significant acceleration (1.7x-2.2x; see benchmarks below) by optimizing the computational graph without altering the model's architecture or its learned weights.
All additions are contained within the contrib/ directory, and is a drop-in replacement for the current
CellposeModel.Usage
First, build the optimized engine from the pretrained model.
To use the TensorRT runtime, replace
CellposeModelwithCellposeModelTRTand use the engine path forpretrained_model.Benchmarks
To run the benchmark script to compare the engine against the original PyTorch model.
Note on Batch Size 4: The engines are built with a dynamic batch dimension to handle image sets that are not perfectly divisible by the batch size. This dynamic scheduling incurs some overhead, resulting in a smaller relative speedup compared to a fixed batch size of 1.