fix: support quantization ranges for int8/uint8 sentence-transformers…#3543
Open
DebadityaHait wants to merge 2 commits into
Open
fix: support quantization ranges for int8/uint8 sentence-transformers…#3543DebadityaHait wants to merge 2 commits into
DebadityaHait wants to merge 2 commits into
Conversation
Contributor
|
Heads-up for maintainers This PR is from a fork and touches integrations whose integration tests require API keys. Affected integrations:
Please run the integration tests locally ( |
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.
Related Issues
Proposed Changes:
With
precision="int8"or"uint8", sentence-transformers calibrates the scalar-quantization min/max range from the batch being encoded. For a single text (as inSentenceTransformersTextEmbedder.run) the range is degenerate (min == max), producing meaningless all-equal embeddings (e.g. all zeros).SentenceTransformersTextEmbedderandSentenceTransformersDocumentEmbedderaccept a new optionalquantization_rangesinit parameter — explicit calibration ranges with shape(2, embedding_dim)(mins in first row, maxs in second)._SentenceTransformersEmbeddingBackend.embedencodes in float32 and forwards the ranges tosentence_transformers.quantize_embeddingswhen a quantized precision is used with explicit ranges; behavior is unchanged whenquantization_rangesisNone.int8/uint8is used without ranges, pointing users at the parameter.quantization_rangesis included into_dict/from_dictserialization.How did you test it?
sentence-transformers-testing/stsb-bert-tiny-safetensors) with int8 + ranges produces a non-degenerate integer embedding.hatch run test:unit(162 passed),hatch run test:integration -k quantization(2 passed),hatch run test:typesandhatch run fmtclean.Notes for the reviewer
np.asarraybefore being passed toquantize_embeddings.Checklist
fix: