feat(sn-da-image-caption): parallelize caption_batch via --concurrency - #98
Open
gangbangxie wants to merge 1 commit into
Open
feat(sn-da-image-caption): parallelize caption_batch via --concurrency#98gangbangxie wants to merge 1 commit into
gangbangxie wants to merge 1 commit into
Conversation
…oning caption_batch() currently processes images one at a time, while the sister caption_images.py in sn-ppt-entry already uses ThreadPoolExecutor. Add a --concurrency / -j flag (default 1, clamped to 1-16) that runs caption calls in parallel when set above 1; result order is preserved regardless of completion order. Closes OpenSenseNova#92
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.
Problem
caption_batch()inskills/sn-da-image-caption/scripts/caption.pyloops through a directory one image at a time:Meanwhile the sister script
skills/sn-ppt-entry/scripts/caption_images.pyalready parallelizes its VLM calls withThreadPoolExecutor. For a directory of 50 images at ~2-4s each, the standalone path costs 100-200s end-to-end — which is what most people hit when running large batches.Issue: #92.
Change
--concurrency / -jflag, default1, clamped to1-16(matches the bounds used incaption_images.py).concurrency > 1, calls go through aThreadPoolExecutorand results are written back into a pre-sized list by index, so the returned order matches the sorted file order regardless of completion order.concurrency == 1(default), behavior is byte-for-byte the same as before: same loop, samecaption_imagecalls. The serial output line still prints index + filename + status.caption_image()is already thread-safe — each invocation builds its ownOpenAIclient, the cache writes are keyed by<md5>_<prompt_hash>.txtso different threads write to different files, andos.makedirs(..., exist_ok=True)is race-safe.Diff is +33/-8 in one file.
Testing
Local smoke test against a mocked
caption_imagethat sleeps 50-200ms per call:-j 1: ~0.80s, original output style preserved-j 4: ~0.33s (≈2.4× speedup)-j 0and-j 999clamp safely to 1 and 16[]python3 caption.py --helpstill parses cleanlyHappy to adjust the default (e.g. raise to 4 to match
caption_images.py) if you'd prefer — left at 1 so this is a pure opt-in change.Closes #92