Open BBC-Esq opened 4 months ago
Can you provide a minimal code using just huggingface transformers and sentence-transformers? What does it take to run forward passes with them?
The instructor models and the package are slightly outdated - I would consider accepting a PR if this is easy to maintain & does not come with extra dependencies.
Can you provide a minimal code using just huggingface transformers and sentence-transformers? What does it take to run forward passes with them?
The instructor models and the package are slightly outdated - I would consider accepting a PR if this is easy to maintain & does not come with extra dependencies.
I don't use huggingface transformers nor sentence-transformers directly, but rather the "instructor" integration with Langchain. I can give specific examples of that if you wanted? At any rate, the source code clearly uses transformers and sentence-transformers libraries.
Wheel is here, open with 7-zip, and look at instructor.py
:
"Instructor-xl" is better than any of the sentence-transformers and/or huggingface models IMHO, although I haven't tried the recent ones mixing Mistral, etc. with embedding models...I'm referring to the traditional "gtr" etc.
Instructor does also have instructions on their github on how to quantize it...perhaps this is a viable alternative if we can't get it implemented in straight-transformers/sentence-transformers/flash-attention2 and all that stuff...Here's how they say to do it, BUT I'VE NEVER AFTER SPENDING HOURS figured out how to get it working!
To [Quantize](https://pytorch.org/docs/stable/quantization.html) the Instructor embedding model, run the following code:
# imports
import torch
from InstructorEmbedding import INSTRUCTOR
# load the model
model = INSTRUCTOR('hkunlp/instructor-large', device='cpu') # you can use GPU
# quantize the model
qmodel = torch.quantization.quantize_dynamic(
model, {torch.nn.Linear}, dtype=torch.qint8)
# Inference
sentence = "3D ActionSLAM: wearable person tracking in multi-floor environments"
instruction = "Represent the Science title:"
embeddings = qmodel.encode([[instruction,sentence]])
# you can also normalize the embeddings: normalize_embeddings=True
print(f"Quantized Embeddings:\n {embeddings}")
Taken from: https://github.com/xlang-ai/instructor-embedding?tab=readme-ov-file#quantization
If would actually pay someone if they could convert instructor (all three sizes) to ctranslate2...that's how much respect I have for it.
With that being said, I love your repository and appreciate your working on hf-hub-translate before that...Here's where I'm contemplating using all ctranslate2 embedding models in my program:
https://github.com/BBC-Esq/ChromaDB-Plugin-for-LM-Studio/issues/143
It's fun to include multiple models, all of which can be seen here:
https://github.com/BBC-Esq/ChromaDB-Plugin-for-LM-Studio/blob/main/src/constants.py
If I do move to Infinity in the near future...it'll be lopsided to have all other embedding models incredibly efficient with ctranslate2, basically, except instructor...
I just tried to do this PR but don't know what I'm doing at all...please help. I noticed that you've done converters before.
BTW, I think that sentence transformers just started supporting instructor models recently!!!
https://www.sbert.net/docs/pretrained_models.html#instructor-models
But "reportedly" they're only supported up to sentence-transformers 2.2.2
, but I haven't had a chance to test this yet...
https://github.com/UKPLab/sentence-transformers/issues/2474#issuecomment-1930707429
Facing this issue now. Is there any way to work around this if using the instructor
from Langchain?
I finally resolved it myself but haven't had a chance to upload the script to any fork of any repo.
Here's the modified script. Let me know if it works for you as I'd appreciate the shout out. ;-)
name the script "instructor" and replace the "instructor.py" script in the package that's normally pip installed.
Awesome, thank you, will check this out.
Can you please support the instructor models here?
https://github.com/xlang-ai/instructor-embedding
These are arguably the best models for their sizes.