Repository navigation
Conversation
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.
What has been done
L2 postprocessing converts each nonzero Python embedding list to a NumPy array twice: once implicitly inside
np.linalg.norm, and again before division. This also happens for every row of the model output passed byrepresentation.represent(..., l2_normalize=True).Create the array once and reuse it for the norm and division. The change preserves the existing row-by-row behavior, output values and list layout, including zero vectors, empty rows, unequal row lengths and unchanged caller input. It does not change the normalization formula or batch allocation strategy.
Validation
Seven model-independent regression tests pass against both the base and the patch. They cover scalar-vector and batch results, integer-valued inputs, zero and signed-zero values, empty/unequal rows, input ownership, and 128/512/4096-dimensional vectors with element-for-element reference equality.
The included benchmark imports the actual baseline and patched normalization modules. It alternates their order, uses two warm-up runs followed by ten measured runs per version, and checks output equality before timing.
Measured on Linux x86_64, Python 3.12.14 and NumPy 2.3.5, using base
8cec026045be164e14b510c55c1264e743dc4999. These measurements cover L2 postprocessing of already computed embeddings; they are not end-to-end model inference results.git show 8cec026045be164e14b510c55c1264e743dc4999:deepface/modules/normalization.py > /tmp/normalization-before.py PYTHONPATH=. python experiments/benchmark_l2_normalization.py \ --baseline /tmp/normalization-before.py --output /tmp/l2-results.jsonThe benchmark writes all individual timings and environment details to the requested JSON file. Full model inference tests and the repository-wide lint suite were not run locally.