⚡ Bolt: vectorize BasicEstimator.predict#50
Conversation
Vectorized the distance calculation in BasicEstimator.predict using NumPy matrix operations and the Euclidean distance expansion formula. This eliminates the per-embedding Python loop and provides a ~12x speedup for batch predictions. - Updated fit() and load() to pre-calculate fitted embedding norms. - Updated predict() to use vectorized matrix operations. - Added np.maximum(dists_sq, 0) to handle floating-point precision issues. - Ensured backward compatibility for models loaded from older versions. - Added a benchmark script in extra/benchmark_estimator.py. Co-authored-by: guesswh0 <10531675+guesswh0@users.noreply.github.com>
|
👋 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
⚡ Bolt: Vectorize BasicEstimator.predict
💡 What
Vectorized the$||a-b||^2 = ||a||^2 + ||b||^2 - 2ab$ ) to calculate distances between all query embeddings and all fitted embeddings in a single pass.
predictmethod inBasicEstimatorusing NumPy matrix operations. The implementation now uses the Euclidean distance expansion formula (🎯 Why
The original implementation used a Python loop to iterate over each query embedding and calculated distances to fitted embeddings one by one using
np.linalg.norm. This introduced significant Python-level overhead, especially as the number of queries or fitted faces increased.📊 Impact
Measurable performance improvement:
🔬 Measurement
Run the included benchmark script:
This script compares the original loop-based logic with the new vectorized implementation and reports the speedup.
PR created automatically by Jules for task 2340906720226119016 started by @guesswh0