You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to run the grammar-structured generation example from here and it is failing due to what appears to be an undeclared dependency on sentencepiece.
Steps/code to reproduce the bug:
Create a new environment and install outlines[transformers] at version 0.2.1.
Then create a file with the example code taken straight from the docs:
fromoutlinesimportmodels, generatearithmetic_grammar=""" ?start: expression ?expression: term (("+" | "-") term)* ?term: factor (("*" | "/") factor)* ?factor: NUMBER | "-" factor | "(" expression ")" %import common.NUMBER"""model=models.transformers("WizardLM/WizardMath-7B-V1.1")
generator=generate.cfg(model, arithmetic_grammar)
sequence=generator(
"Alice had 4 apples and Bob ate 2. "+"Write an expression for Alice's apples:"
)
print(sequence)
# (8-2)
Expected result:
Running this should output some arithmetic expression.
Error message:
$ python example.py
Loading checkpoint shards: 100%|████████████████████████████| 2/2 [00:40<00:00, 20.10s/it]
Traceback (most recent call last):
File ".../.venv/lib/python3.11/site-packages/transformers/utils/import_utils.py", line 1863, in _get_module
return importlib.import_module("." + module_name, self.__name__)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".../.pyenv/versions/3.11.11/lib/python3.11/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 940, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File ".../.venv/lib/python3.11/site-packages/transformers/models/llama/tokenization_llama.py", line 27, in<module>
import sentencepiece as spm
ModuleNotFoundError: No module named 'sentencepiece'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File ".../example.py", line 17, in<module>
model = models.transformers("WizardLM/WizardMath-7B-V1.1")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".../.venv/lib/python3.11/site-packages/outlines/models/transformers.py", line 435, in transformers
return Transformers(model, tokenizer)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".../.venv/lib/python3.11/site-packages/outlines/models/transformers.py", line 138, in __init__
self.tokenizer = TransformerTokenizer(tokenizer)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".../.venv/lib/python3.11/site-packages/outlines/models/transformers.py", line 80, in __init__
self.is_llama = isinstance(self.tokenizer, get_llama_tokenizer_types())
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".../.venv/lib/python3.11/site-packages/outlines/models/transformers.py", line 27, in get_llama_tokenizer_types
from transformers.models.llama import LlamaTokenizer
File "<frozen importlib._bootstrap>", line 1229, in _handle_fromlist
File ".../.venv/lib/python3.11/site-packages/transformers/utils/import_utils.py", line 1851, in __getattr__
module = self._get_module(self._class_to_module[name])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".../.venv/lib/python3.11/site-packages/transformers/utils/import_utils.py", line 1865, in _get_module
raise RuntimeError(
RuntimeError: Failed to import transformers.models.llama.tokenization_llama because of the following error (look up to see its traceback):
No module named 'sentencepiece'
It's easy enough to manually install sentencepiece and fix this, but if outlines depends on this library then it should declare that dependency properly so pip/poetry/uv/etc. do the right thing automatically.
The text was updated successfully, but these errors were encountered:
Describe the issue as clearly as possible:
I am trying to run the grammar-structured generation example from here and it is failing due to what appears to be an undeclared dependency on
sentencepiece
.Steps/code to reproduce the bug:
Create a new environment and install
outlines[transformers]
at version 0.2.1.Then create a file with the example code taken straight from the docs:
Expected result:
Running this should output some arithmetic expression.
Error message:
Outlines/Python version information:
Version information
Context for the issue:
It's easy enough to manually install
sentencepiece
and fix this, but if outlines depends on this library then it should declare that dependency properly so pip/poetry/uv/etc. do the right thing automatically.The text was updated successfully, but these errors were encountered: