⚡ Bolt: Vectorize BasicEstimator.predict for ~22x speedup#36
Conversation
💡 What: Replaced the Python loop in `BasicEstimator.predict` with a vectorized NumPy implementation using the squared distance expansion formula. Added pre-calculation of fitted embedding norms in the `fit` method. 🎯 Why: The previous implementation performed distance calculations in a loop, which is extremely inefficient for large batches of query or fitted embeddings (O(M*N*D) in Python). 📊 Impact: Reduces prediction time by ~95% (~22x speedup). Benchmarked at ~0.014s (down from ~0.32s) for 500 query vs 2000 fitted embeddings. 🔬 Measurement: Verified via `benchmark_basic_estimator_v2.py` (now deleted) comparing results and timing against the original implementation. Core tests in `tests/test_face_engine_models.py` pass. 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. |
Vectorized the
BasicEstimator.predictmethod inface_engine/models/basic_estimator.pyto significantly improve performance.Key changes:
__init__to initializefitted_norms_sq.fitto pre-calculate squared norms of the fitted embeddings.predictusing the formulaloadmethod update for backward compatibility with older serialized models.Performance improvement: ~22x speedup for 500 query embeddings against 2000 stored embeddings.
PR created automatically by Jules for task 6139538611339517072 started by @guesswh0