Add Triton backend and basic functionality with Torch version#1375
Draft
ZephyrKeXiner wants to merge 7 commits into
Draft
Add Triton backend and basic functionality with Torch version#1375ZephyrKeXiner wants to merge 7 commits into
ZephyrKeXiner wants to merge 7 commits into
Conversation
Contributor
Author
|
The package triton is only available on Linux and Python >= 3.9, so the tests on Windows, macOS and Python 3.8 fails instead of the code error. |
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
This PR adds an experimental Triton packed-bitmask path for large
GreedyNMM + IOSpostprocessing workloads.The current torchvision backend computes a dense
N x NIoU/IoS matrix on GPU and copies the whole float32 matrix back to CPU before running the greedy merge loop. For large sliced-inference workloads with thousands of boxes, this GPU-to-CPU transfer can become expensive.And
For
GreedyNMM, the greedy loop only needs the thresholded pairwise match result:It does not need the exact float IOS value after the threshold check. This PR uses Triton to compute the thresholded IOS matches directly and packs them into a
uint32bitmask.What Changed
GreedyNMM + IOS.autodoes not select Triton by default.numpytorchvision_matrixtorch_masktritonWhy This Helps
The origin implement transfer the
N x NIoU/IoS matrix from GPU to CPU, it will cause huge memory bandwidth cost. So it comes out that whether we can only transfer a expression of the GPU result?The greedy algorithm itself is still executed sequentially on CPU. The speedup comes from avoiding dense matrix materialization/transfer and using a compact bitset representation.
Benchmark
Benchmark target:
The synthetic benchmark is model-free on purpose. It isolates the ndarray-level postprocess step after sliced inference has already produced many boxes.
Environment:
Median latency:
Parity with NumPy was preserved for all benchmark cases.
and on
It even has 10x improvement.
Notes
GreedyNMM + IOSworkloads.NMS + IOUis not the target here because torchvision already has a native optimized NMS kernel.