Repository navigation
Preserve Polygraphy cosine similarity under rescaling - #4869
Open
sylvesterkaczmarek wants to merge 1 commit into
Open
sylvesterkaczmarek wants to merge 1 commit into
sylvesterkaczmarek wants to merge 1 commit into
Conversation
Signed-off-by: Sylvester Kaczmarek <16242628+sylvesterkaczmarek@users.noreply.github.com>
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.
Fixes #4868.
Scale each nonzero vector by its maximum absolute component before calculating cosine products and norms. This avoids overflow/underflow changing the comparison verdict for rescaled finite outputs. Preserve the zero-vector convention and non-finite-result rejection.
The scale is obtained from the extrema without the general absolute-value helper, whose PyTorch implementation first converts to float32. Integer inputs are promoted before scaling so their minimum representable value can be handled safely.
Add NumPy/PyTorch regressions for independently scaled identical, opposite and orthogonal vectors, plus empty, zero and signed-integer controls. The controls also check that inputs are unchanged. Update Polygraphy's changelog.
Validation
From
tools/Polygraphy:283 passed, 4 existing skips on CPU. The 24 floating-point rescaling cases give 18 failures and 6 passes on unchanged upstream. Polygraphy's Black pre-commit hook and
git diff --checkpass.No TensorRT engine, CUDA execution, or model accuracy benchmark was run. The tests exercise comparison arithmetic and verdicts using controlled arrays.