Segfault on example sentencetransformers code:

#45
by marksverdhei - opened
in [1]: # requires transformers>=4.51.0
   ...: # requires sentence-transformers>=2.7.0
   ...: 
   ...: from sentence_transformers import sentencetransformer
   ...: 
   ...: # load the model
   ...: model = sentencetransformer("qwen/qwen3-embedding-0.6b")
   ...: 
   ...: # we recommend enabling flash_attention_2 for better acceleration and memory saving,
   ...: # together with setting `padding_side` to "left":
   ...: # model = sentencetransformer(
   ...: #     "qwen/qwen3-embedding-0.6b",
   ...: #     model_kwargs={"attn_implementation": "flash_attention_2", "device_map": "auto"},
   ...: #     tokenizer_kwargs={"padding_side": "left"},
   ...: # )
   ...: 
   ...: # the queries and documents to embed
   ...: queries = [
   ...:     "what is the capital of china?",
   ...:     "explain gravity",
   ...: ]
   ...: documents = [
   ...:     "the capital of china is beijing.",
   ...:     "gravity is a force that attracts two bodies towards each other. it gives weight to physical objects and is responsible for the movement of planets around the sun.",
   ...: ]
   ...: 
   ...: # encode the queries and documents. note that queries benefit from using a prompt
   ...: # here we use the prompt called "query" stored under `model.prompts`, but you can
   ...: # also pass your own prompt via the `prompt` argument
   ...: query_embeddings = model.encode(queries, prompt_name="query")
   ...: document_embeddings = model.encode(documents)
   ...: 
   ...: # compute the (cosine) similarity between the query and document embeddings
   ...: similarity = model.similarity(query_embeddings, document_embeddings)
   ...: print(similarity)
   ...: # tensor([[0.7646, 0.1414],
   ...: #         [0.1355, 0.6000]])

terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc
aborted (core dumped)

terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
Aborted (core dumped)

pip freeze:

aiohappyeyeballs==2.6.1
aiohttp==3.13.2
aiosignal==1.4.0
annotated-types==0.7.0
anyio==4.11.0
asttokens==3.0.0
attrs==25.4.0
certifi==2025.10.5
charset-normalizer==3.4.4
datasets==4.4.1
decorator==5.2.1
dill==0.4.0
executing==2.2.1
filelock==3.20.0
frozenlist==1.8.0
fsspec==2025.10.0
h11==0.16.0
hf-xet==1.2.0
httpcore==1.0.9
httpx==0.28.1
huggingface-hub==0.36.0
idna==3.11
ipython==9.7.0
ipython-pygments-lexers==1.1.1
jedi==0.19.2
jinja2==3.1.6
joblib==1.5.2
markdown-it-py==4.0.0
markupsafe==3.0.3
matplotlib-inline==0.2.1
mdurl==0.1.2
mpmath==1.3.0
-e file:///home/me/Repos/mteb
multidict==6.7.0
multiprocess==0.70.18
networkx==3.5
numpy==2.3.4
nvidia-cublas-cu12==12.8.4.1
nvidia-cuda-cupti-cu12==12.8.90
nvidia-cuda-nvrtc-cu12==12.8.93
nvidia-cuda-runtime-cu12==12.8.90
nvidia-cudnn-cu12==9.10.2.21
nvidia-cufft-cu12==11.3.3.83
nvidia-cufile-cu12==1.13.1.3
nvidia-curand-cu12==10.3.9.90
nvidia-cusolver-cu12==11.7.3.90
nvidia-cusparse-cu12==12.5.8.93
nvidia-cusparselt-cu12==0.7.1
nvidia-nccl-cu12==2.27.5
nvidia-nvjitlink-cu12==12.8.93
nvidia-nvshmem-cu12==3.3.20
nvidia-nvtx-cu12==12.8.90
packaging==25.0
pandas==2.3.3
parso==0.8.5
pexpect==4.9.0
pillow==12.0.0
polars==1.35.2
polars-runtime-32==1.35.2
prompt-toolkit==3.0.52
propcache==0.4.1
ptyprocess==0.7.0
pure-eval==0.2.3
pyarrow==22.0.0
pydantic==2.12.4
pydantic-core==2.41.5
pygments==2.19.2
python-dateutil==2.9.0.post0
pytrec-eval-terrier==0.5.10
pytz==2025.2
pyyaml==6.0.3
regex==2025.11.3
requests==2.32.5
rich==14.2.0
safetensors==0.6.2
scikit-learn==1.7.2
scipy==1.16.3
sentence-transformers==5.1.2
setuptools==80.9.0
six==1.17.0
sniffio==1.3.1
stack-data==0.6.3
sympy==1.14.0
threadpoolctl==3.6.0
tokenizers==0.22.1
torch==2.9.0
tqdm==4.67.1
traitlets==5.14.3
transformers==4.57.1
triton==3.5.0
typing-extensions==4.15.0
typing-inspection==0.4.2
tzdata==2025.2
urllib3==2.5.0
wcwidth==0.2.14
xxhash==3.6.0
yarl==1.22.0

Sign up or log in to comment