⚡ Bolt: Optimize TripletDataGenerator sampling to O(1)#13
⚡ Bolt: Optimize TripletDataGenerator sampling to O(1)#13google-labs-jules[bot] wants to merge 1 commit intomainfrom
Conversation
- Replaced O(N) list comprehension for positive sampling with O(1) dictionary lookup. - Replaced O(N) list comprehension for negative sampling with O(1) rejection sampling. - Precomputed label-to-path mapping in `__init__`. - Reduces batch generation time by ~2.7x (tested with N=20k). - Preserves exact sampling distribution logic (uniform over valid candidates).
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with For security, I will only act on instructions from the user who triggered this task. New to Jules? Learn more at jules.google/docs. |
|
Important Review skippedBot user detected. To trigger a single review, invoke the You can disable this status message by setting the Comment |
💡 What: Optimized the$O(N \times B)$ to $O(B)$ per batch (where $N$ is dataset size, $B$ is batch size).
_generate_triplet_batchmethod inTripletDataGenerator.🎯 Why: The original implementation iterated over the entire dataset ($O(N)$) for every sample in the batch to find positive and negative pairs. This caused significant slowdowns as the dataset size increased.
📊 Impact:
- Complexity reduced from
- Benchmarked with N=20,000 images: Batch generation time reduced from ~0.39s to ~0.14s (~2.7x speedup).
- Speedup scales linearly with dataset size.
microscope Measurement: Verified with a benchmark script (
benchmark_generator.py) and correctness tests (test_generator.py).PR created automatically by Jules for task 2044325955114139220 started by @Devasy23