Optimize RF-DETR segmentation pipeline#46
Open
aseembits93 wants to merge 20 commits into
Open
Conversation
8b91f96 to
da0657d
Compare
5c506c4 to
aa7d849
Compare
da0657d to
0c1ebee
Compare
b1f2661 to
c4721f0
Compare
0c1ebee to
6ada7e9
Compare
c4721f0 to
954a8ab
Compare
422f348 to
b1dfd9b
Compare
cf0d80b to
9fdb0f0
Compare
b1dfd9b to
3fdba83
Compare
9fdb0f0 to
f1120b3
Compare
ad3b915 to
e240443
Compare
f1120b3 to
ed46063
Compare
e240443 to
6a5d576
Compare
e00a9fa to
3b9f51c
Compare
6a5d576 to
e4ea373
Compare
3b9f51c to
d319020
Compare
4733918 to
db13cd2
Compare
d300a67 to
c6be45f
Compare
db13cd2 to
257109b
Compare
c6be45f to
8b8b19c
Compare
5648520 to
54e10e6
Compare
8b8b19c to
097f743
Compare
7dfb80f to
3cb8a5c
Compare
3d2f3c1 to
ab811f2
Compare
85a94c6 to
b50192a
Compare
| depth: int | ||
|
|
||
|
|
||
| def run_workflow( |
There was a problem hiding this comment.
is this being used elsewhere? is this a breaking change?
| tradeoff_factor=tradeoff_factor, | ||
| ) | ||
| model = get_model(model_id=model_id, api_key=api_key) | ||
| on_video_frame = partial( |
There was a problem hiding this comment.
these changes are unncessary, can be removed to reduce diff. alongside the RoboflowModelHandler class
| ) | ||
|
|
||
| preproc_event = getattr(self, "_fast_preproc_event", None) | ||
| if preproc_event is not None: |
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.
What does this PR do?
This is the top PR in the RF-DETR optimization stack:
main <- opt-python-postproc <- opt-preprocess <- opt-pipeline-integrationIt integrates the optimized Triton postprocess and preprocess branches into the streaming workflow path and removes the remaining CPU/GPU scheduling bubbles visible in Nsight. End-to-end numbers for this PR represent the full stack: Triton postproc, Triton preproc, CUDA graph execution, depth-2 pipeline scheduling, sparse RLE-to-polygon conversion, and workflow response-path optimizations.
Key changes:
postprocess, before CPU response finalization.cv2.findContours.Type of Change
Testing
Test details:
Reference command on
main:Candidate command on
opt-pipeline-integration:ENABLE_AUTO_CUDA_GRAPHS_FOR_TRT_BACKEND=true \ INFERENCE_MODELS_RFDETR_TRITON_PREPROC_ENABLED=true \ INFERENCE_MODELS_RFDETR_TRITON_POSTPROC_ENABLED=true \ RFDETR_PIPELINE_DEPTH=2 \ PYTHONPATH=/app/helloworld/inference:/app/helloworld/inference/inference_models \ python development/stream_interface/rfdetr_nano_seg_trt_workflow.py \ --video_reference <video> \ --backend trtvehicles_312px.mp4 (538 frames, src 312x176):
vehicles_720p.mp4 (538 frames, src 1280x720):
vehicles_1080p.mp4 (538 frames, src 1920x1080):
mainflags-offenv PARITY_MODEL_PATH=/app/helloworld/inference/rfdetr-seg-nano-orin-trt-package \ PYTHONPATH=/app/helloworld/inference:/app/helloworld/inference/inference_models \ python development/stream_interface/rfdetr_coco_same_shape_parity.py \ --base-ref main \ --candidate-ref opt-pipeline-integration \ --height 480 \ --width 640 \ --image-count 1000mainflags-offenv PARITY_MODEL_PATH=/app/helloworld/inference/rfdetr-seg-nano-orin-trt-package \ PYTHONPATH=/app/helloworld/inference:/app/helloworld/inference/inference_models \ python development/stream_interface/rfdetr_workflow_video_parity.py \ --video_reference vehicles_1080p.mp4 \ --base-ref main \ --candidate-ref opt-pipeline-integrationThis compares serialized workflow sink outputs frame by frame, ignoring generated detection IDs and matching detections by same class and box IoU > 0.5.
env PYTHONPATH=/app/helloworld/inference:/app/helloworld/inference/inference_models \ python development/stream_interface/rfdetr_rle_to_poly_microbenchmark.py \ --mode replay \ --cases-dir <captured-cases-dir> \ --repeats 3 \ --warmup-repeats 1Each row uses 100 captured calls and 300 timed replays.
PYTHONPATH=/app/helloworld/inference:/app/helloworld/inference/inference_models \ python -m pytest -q \ tests/inference/unit_tests/core/interfaces/stream/test_workflows.py \ tests/inference/unit_tests/core/interfaces/stream/test_interface_pipeline.py::test_inference_pipeline_drain_enqueues_flush_results_with_bound_frames \ tests/inference/unit_tests/core/interfaces/stream/test_interface_pipeline.py::test_resolve_prediction_futures_recursively_resolves_nested_values \ tests/inference/unit_tests/core/interfaces/stream/test_interface_pipeline.py::test_inference_pipeline_close_calls_handler_close_hook \ tests/inference/unit_tests/core/models/test_inference_models_adapters.py \ tests/inference/unit_tests/core/utils/test_rle_to_polygon.pyResult:
17 passed.PYTHONPATH=/app/helloworld/inference/inference_models:/app/helloworld/inference \ python -m pytest -q tests/unit_tests/test_configuration.py \ tests/unit_tests/models/test_instance_segmentation_future.pyResult:
16 passed.Latest 1080p review-cleanup verification:
ENABLE_AUTO_CUDA_GRAPHS_FOR_TRT_BACKEND=true \ INFERENCE_MODELS_RFDETR_TRITON_PREPROC_ENABLED=true \ INFERENCE_MODELS_RFDETR_TRITON_POSTPROC_ENABLED=true \ RFDETR_PIPELINE_DEPTH=2 \ PYTHONPATH=/app/helloworld/inference/inference_models:/app/helloworld/inference \ python development/stream_interface/rfdetr_nano_seg_trt_workflow.py \ --video_reference vehicles_1080p.mp4 \ --backend trtResult:
frames=538 elapsed=6.50s fps=82.72.Note: after rebasing onto newer
main, the workflow benchmark explicitly setsenforce_dense_masks_in_inference_models=Falseso the optimized sparse/RLE postprocess path is measured instead of the newer dense-mask workflow default.How It Works
Pipeline scheduling
With
RFDETR_PIPELINE_DEPTH=2, depth means one CPU stage and one GPU stage in flight. CPU prepares frameN, submits GPU work for frameN, immediately prepares/submits frameN+1, and only then finalizes the older response. The key ordering fix is submitting postprocess GPU work before releasing an older response for CPU finalization.Sparse RLE to polygon
The old response path decoded each COCO RLE into a full
H x Wdense mask before callingcv2.findContours. The new path parses uncompressed RLE counts into foreground intervals, materializes only the tight foreground crop, and calls OpenCV with an offset so output polygon coordinates match the legacy dense path.Checklist
Additional Context
This PR intentionally does not introduce new Triton preproc/postproc kernels; those are in the two lower PRs. This branch wires them into the stream pipeline and optimizes the remaining CPU response path so the GPU queue stays close to full.