Skip to content
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

Ensure that torch is not used unless it is available #467

Merged
merged 1 commit into from
May 17, 2024
Merged

Conversation

svlandeg
Copy link
Member

@svlandeg svlandeg commented May 17, 2024

Description

Bugfix. If you had transformers installed but not torch, you would get an ugly error upon importing spacy_llm:

Traceback (most recent call last):
  File "...\spacy-llm\spacy_llm\__init__.py", line 1, in <module>
    from . import cache  # noqa: F401
  File "...\spacy-llm\spacy_llm\cache.py", line 11, in <module>
    from .ty import PromptTemplateProvider, ShardingLLMTask
  File "...\spacy-llm\spacy_llm\ty.py", line 14, in <module>
    from .models import langchain
  File "...\spacy-llm\spacy_llm\models\__init__.py", line 1, in <module>
    from .hf import dolly_hf, openllama_hf, stablelm_hf
  File "...\spacy-llm\spacy_llm\models\hf\__init__.py", line 7, in <module>
    from .registry import huggingface_v1
  File "...\spacy-llm\spacy_llm\models\hf\registry.py", line 12, in <module>
    from .stablelm import StableLM
  File "...\spacy-llm\spacy_llm\models\hf\stablelm.py", line 11, in <module>
    class _StopOnTokens(transformers.StoppingCriteria):
  File "...\spacy-llm\spacy_llm\models\hf\stablelm.py", line 13, in _StopOnTokens
    self, input_ids: torch.LongTensor, scores: torch.FloatTensor, **kwargs
AttributeError: 'NoneType' object has no attribute 'LongTensor'

Types of change

bug fix

Checklist

  • I confirm that I have the right to submit this contribution under the project's MIT license.
  • I ran all tests in tests and usage_examples/tests, and all new and existing tests passed. This includes
    • all external tests (i. e. pytest ran with --external)
    • all tests requiring a GPU (i. e. pytest ran with --gpu)
  • My changes don't require a change to the documentation, or if they do, I've added all required information.

@svlandeg svlandeg added the bug Something isn't working label May 17, 2024
@svlandeg svlandeg merged commit 5f7e529 into main May 17, 2024
21 checks passed
@svlandeg svlandeg deleted the fix/has_torch branch May 17, 2024 08:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant