-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Spacy-LLM fails with storage not allocated on MPS device #13096
Comments
Hi @rkatriel, which version of |
Hi @rmitsch, it is 4.34.1. I upgraded to the latest (4.35.0) but it made no difference. This issue is mentioned in the following discussion: One suggestion is to check out the following: https://pytorch.org/docs/master/notes/mps.html Perhaps incorporating this into Spacy-LLM will resolve the error. |
If you run this snippet from the linked PyTorch docs site, what's your output? if not torch.backends.mps.is_available():
if not torch.backends.mps.is_built():
print("MPS not available because the current PyTorch install was not "
"built with MPS enabled.")
else:
print("MPS not available because the current MacOS version is not 12.3+ "
"and/or you do not have an MPS-enabled device on this machine.") |
Nothing. This is because the first test fails. Here are the values of the function calls:
Both are False when the 'not' is added in the conditions. |
Two approaches here:
|
Thanks for the suggestions. Downgrading transformers doesn't help. I got the same error with transformers-4.28.0, while transformers-4.27.0 causes the following error:
For your second suggestion, see the script below. The Huggingface model is documented here: https://huggingface.co/emilyalsentzer/Bio_ClinicalBERT The code works well when the model is not moved to my MPS device, that is, the following line is commented out
But when uncommented I get the same error as with Spacy-LLM:
The error occurs inside torch (I can share the traceback if helpful). Ron
|
Try passing I should have been more specific w.r.t. point 2. I meant to instantiate the model you're using in |
In reverse order, I couldn't figure out how to modify the code snippet you referenced to use my MPS device. Can you provide more explicit instructions? Specifically, which function accepts the device. However, I was able to pass the MPS device in my original code as follows and it seemed to work (output produced and no errors):
However, the strange thing is that the code is significantly faster when not using the MPS device (0.000060 seconds) than when using it (0.256201 seconds). This doesn't make any sense to me... |
Offloading data/model to a device comes with an overhead. It should be faster in the long run (i. e. for many calls).
(1) Copy-paste the linked snippet. (2) Do |
That doesn't work. I get the same error
Here is the code I'm running
|
Ok, this helps in narrowing down the issue - it doesn't seem to be in
We'll also look into this, but seeing that this is an upstream issue, there's probably not much we can do to fix this from our side. |
Thanks, Raphael. I solved the mystery by following advice found on the pytorch discussion group at Specifically, one must make sure - in addition to moving the model to the mps device - to also move the input to the mps device
Here is the updated code snippet
The code now runs cleanly and produces the following output
Note that prior to this I reinstalled torch using the following to take advantage of the Apple Silicon (M2 chip/GPU)
It may be part of the solution but I'm not sure (it wasn't enough by itself to make the error go away). Question: How does one apply this to using spacy-llm with Llama 2 on a Mac with Apple silicon? Torch is internal to spacy-llm, that is, it's called under the covers by the nlp pipeline. |
Thanks for the update! |
Thanks, that did the trick! Just the following warning which I have been getting all along
However, no entities were found by the code example listed above, which is unexpected. |
Feel free to open another issue for this, we'll look into it. |
Done. See issue #13132 ("Spacy-LLM code sample produces no output"). |
This issue has been automatically closed because it was answered and there was no follow-up discussion. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Hi,
The code example listed below fails with the following error:
I'm running it on a MacBook Air with Apple Silicon (M2, 2022) under macOS Monterey (Version 12.6). Additional details below.
The full traceback is listed below the code.
Note: This is a continuation of Issue #12987 (Unknown function registry: 'llm_backends').
How to reproduce the behaviour
Here is the code, based on the example provided in Matthew Honnibal's blog "Against LLM maximalism" (https://explosion.ai/blog/against-llm-maximalism):
Here is the traceback:
File "/Users/ron.katriel/PycharmProjects/Transformer/test-spacy-llm.py", line 19, in
doc = nlp("There's no PyTorch bindings for Go. We just use Microsoft Cognitive Services.")
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/spacy/language.py", line 1054, in call
error_handler(name, proc, [doc], e)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/spacy/util.py", line 1704, in raise_error
raise e
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/spacy/language.py", line 1049, in call
doc = proc(doc, **component_cfg.get(name, {})) # type: ignore[call-arg]
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/spacy_llm/pipeline/llm.py", line 156, in call
docs = self._process_docs([doc])
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/spacy_llm/pipeline/llm.py", line 210, in _process_docs
responses_iters = tee(self._model(prompts_iters[0]), n_iters)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/spacy_llm/models/hf/openllama.py", line 55, in call
return [
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/spacy_llm/models/hf/openllama.py", line 57, in
self._model.generate(input_ids=tii, **self._config_run)[
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
return func(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/transformers/generation/utils.py", line 1606, in generate
return self.greedy_search(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/transformers/generation/utils.py", line 2454, in greedy_search
outputs = self(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
return forward_call(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/transformers/models/llama/modeling_llama.py", line 1038, in forward
outputs = self.model(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
return forward_call(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/transformers/models/llama/modeling_llama.py", line 875, in forward
inputs_embeds = self.embed_tokens(input_ids)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
return forward_call(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/torch/nn/modules/sparse.py", line 162, in forward
return F.embedding(
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/torch/nn/functional.py", line 2210, in embedding
return torch.embedding(weight, input, padding_idx, scale_grad_by_freq, sparse)
RuntimeError: Placeholder storage has not been allocated on MPS device!
Your Environment
The text was updated successfully, but these errors were encountered: