Closed jcntrl closed 1 year ago
@jcntrl Thanks for the detailed description.
The error should be indeed raised when importing sentence_transformers
Can you try again with?
pip install sentence-transformers torch
Interesting, I must have had a package conflict on my end; as in a new notebook with only:
!pip install sentence-transformers torch hf-hub-ctranslate2
and
from hf_hub_ctranslate2 import CT2SentenceTransformer
model_name_pytorch = "intfloat/e5-small"
model = CT2SentenceTransformer(
model_name_pytorch, compute_type="int8", device="cpu",
)
embeddings = model.encode(
["I like soccer", "I like tennis", "The eiffel tower is in Paris"],
batch_size=32,
convert_to_numpy=True,
normalize_embeddings=True,
)
print(embeddings.shape, embeddings)
scores = (embeddings @ embeddings.T) * 100
it works, and results in an apparently correct:
(3, 384) [[-0.03019609 -0.03029384 -0.09287093 ... -0.01719665 0.01654728
0.10151423]
[-0.02865791 -0.03035643 -0.12332754 ... -0.01281117 0.01556634
0.08893888]
[ 0.07090583 -0.05870947 -0.06741289 ... -0.01381944 -0.00529657
0.07468784]]
Thanks, I'll close the issue as it seems it's not one.
Exactly (but with slight modification
device='cpu'
per your example found here and here:Results in this confusing error:
I have previously installed and verified the installation of these packages:
!pip install hf-hub-ctranslate2 hf_hub_ctranslate2[sentence_transformers] torch sentence-transformers
Elsewhere in my notebook, I have installed and can assure torch, sentence_transformers, ctranslate2, transformers, numpy are all present and functioning as expected.
Compute environment is a google colab, cpu-based without a GPU. This error disappears when a T4 is available, even when
device='cpu'
is specified. The following output seems to be the expected result:Perhaps there is an implicit dependency on CUDA somewhere that's not checked conditionally based on what the specified compute flag indicates?
Thanks for your time and attention.