Faster TensorRT Runtime for CellposeSAM #1356
Open
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.