Issue SAM3 remote requests concurrently instead of one frame at a time - #2886
Issue SAM3 remote requests concurrently instead of one frame at a time#2886rafel-roboflow wants to merge 1 commit into
Conversation
The SAM3 concept-segmentation blocks received a batch of frames but looped over it, blocking on one HTTP round trip per frame. A staging video preview run showed the cost: 264 serverless calls for a 264-frame job, 244ms median each, with the whole 67.8s of wall clock spent inside those calls (3.9 fps). A detection workflow on the same worker issued its requests in parallel and managed 31ms/frame. Hand the whole batch to the SDK in a single call so it fans the per-image requests out concurrently, and hoist the image-independent prompt building out of the loop. The loop now only maps responses back onto their images. max_batch_size stays pinned at 1: the /sam3/concept_segment endpoint takes a single `image`, and a larger batch size would make the SDK put a list in that field. Concurrency is the part that is safe to raise, and it is what the serial loop was giving up. Applies to all six variants (v1/v2/v3, plain and tensor). run_via_request has the same serial shape but a different transport, and is only reachable with SAM3_EXEC_MODE=remote; left alone here.
|
👋 Thanks for the pull request! Here is how automated Claude review works here, so you spend credits (and reviewer time) wisely. 🚧 Right now this is a draft, so automated Claude review is paused — nothing is being spent yet. Mark it Ready for review to trigger it. Warning 💸 The Claude reviewer bills in credits, not vibesAutomated review spins up a real agent that reads real code and spends real credits on every pass. It is glad to help — but it is not a rubber duck, a linter you poke in a loop, or a substitute for reading the contributing guide. Treat it like an expensive senior reviewer whose time you booked, and show up prepared. Draft when unsure, Ready when you mean it:
However you get there, arrive prepared:
Reviews are not free. A draft costs nothing to review; a Ready PR is a promise that it is worth reviewing.
|
|
🤖 Claude review started at commit New commits are not auto-reviewed. Add the |
What does this PR do?
The SAM3 concept-segmentation blocks receive a batch of frames for remote execution, then loop over it and block on one HTTP round trip per frame. Video preview runs pay that serially for the whole video.
Measured on a staging video-preview run (
sam3+ mask/label visualization, 264 frames):1 request(s) with 1 frame(s)each)A detection workflow on the same worker, same endpoint, issued its requests in parallel and got 31ms/frame.
This PR hands the whole batch to the SDK in a single call, so
execute_requests_packagesfans the per-image requests out concurrently instead of the block awaiting them one by one. The image-independent prompt building moves out of the loop; the loop now only maps responses back onto their images.max_batch_sizestays pinned at 1 deliberately./sam3/concept_segmenttakes a singleimage(Sam3SegmentationRequest.image: InferenceRequestImage), and any larger batch size makes the SDK'sinject_images_into_payloadput a list into that field, which the endpoint would reject. Concurrency is the safe lever here, and it is exactly what the serial loop was giving up.Applies to all six variants —
v1/v2/v3, plain and_tensor— sinceENABLE_TENSOR_DATA_REPRESENTATIONdecides which pair loads.Related Issue(s): Found while investigating slow video previews in the streaming preview worker.
Type of Change
Testing
Test details:
New
tests/workflows/unit_tests/core_steps/models/foundation/test_segment_anything3_remote_concurrency.py, parametrized over all six block variants (24 tests):max_batch_size == 1andmax_concurrent_requests > 1Every test fails on
mainfor the right reason and passes here. Also run: the wholetests/workflows/unit_testssuite (5996 passed) andtests/workflows/unit_tests/core_steps/dependent_resources(225 passed), plus a block-loader import check with the tensor flag both off and on (235 blocks each). The 17 failures in that suite (zone geometry, rle compact, detections mismatch/stitch, semantic segmentation) reproduce unchanged on the base commit and are untouched by this change.blackandisortare clean.Checklist
Additional Context
What this does not change: the 244ms per call itself. That is one SAM3 forward pass plus network, plus an extra proxy hop on the hosted path. What changes is that independent frames no longer wait in line for each other — expected gain is roughly the concurrency factor (
WORKFLOWS_REMOTE_EXECUTION_MAX_STEP_CONCURRENT_REQUESTS, 8 in the streaming preview deployment), bounded in practice by how the serverless GPU fleet handles the parallelism. Worth watching fleet behaviour when this ships.Left alone deliberately:
run_via_requesthas the same serial shape, but it posts directly withrequestsrather than through the SDK, so making it concurrent needs its own thread pool. It is only reachable withSAM3_EXEC_MODE=remote(default islocal), and it is not the path the measurements above came from. Happy to do it as a follow-up.