spaCy
spaCy copied to clipboard
Running `init config --gpu` without spacy-transformers doesn't exit gracefully
Although it is expected that spacy-transformers should be installed when creating a GPU-based config, the command itself won't exit gracefully.
How to reproduce the behaviour
python3 -m venv venv
source venv/bin/activate
# Install spacy 3.2.3
venv/bin/pip3 install spacy==3.2.3
# Do not install spacy-transformers
venv/bin/spacy init config --gpu sample.cfg
Traceback shows a jinja2.exceptions.UndefinedError
⚠ To generate a more effective transformer-based config (GPU-only),
install the spacy-transformers package and re-run this command. The config
generated now does not use transformers.
Traceback (most recent call last):
File "venv/bin/spacy", line 8, in <module>
sys.exit(setup_cli())
File "/home/lj/Explosion/spaCy/venv/lib/python3.8/site-packages/spacy/cli/_util.py", line 71, in setup_cli
command(prog_name=COMMAND)
File "/home/lj/Explosion/spaCy/venv/lib/python3.8/site-packages/click/core.py", line 1128, in __call__
return self.main(*args, **kwargs)
File "/home/lj/Explosion/spaCy/venv/lib/python3.8/site-packages/click/core.py", line 1053, in main
rv = self.invoke(ctx)
File "/home/lj/Explosion/spaCy/venv/lib/python3.8/site-packages/click/core.py", line 1659, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/lj/Explosion/spaCy/venv/lib/python3.8/site-packages/click/core.py", line 1659, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/lj/Explosion/spaCy/venv/lib/python3.8/site-packages/click/core.py", line 1395, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/lj/Explosion/spaCy/venv/lib/python3.8/site-packages/click/core.py", line 754, in invoke
return __callback(*args, **kwargs)
File "/home/lj/Explosion/spaCy/venv/lib/python3.8/site-packages/typer/main.py", line 500, in wrapper
return callback(**use_params) # type: ignore
File "/home/lj/Explosion/spaCy/venv/lib/python3.8/site-packages/spacy/cli/init_config.py", line 55, in init_config_cli
config = init_config(
File "/home/lj/Explosion/spaCy/venv/lib/python3.8/site-packages/spacy/cli/init_config.py", line 166, in init_config
base_template = template.render(variables).strip()
File "/home/lj/Explosion/spaCy/venv/lib/python3.8/site-packages/jinja2/environment.py", line 1291, in render
self.environment.handle_exception()
File "/home/lj/Explosion/spaCy/venv/lib/python3.8/site-packages/jinja2/environment.py", line 925, in handle_exception
raise rewrite_traceback_stack(source=source)
File "<template>", line 44, in top-level template code
File "/home/lj/Explosion/spaCy/venv/lib/python3.8/site-packages/jinja2/environment.py", line 455, in getitem
return obj[argument]
jinja2.exceptions.UndefinedError: 'None' has no attribute 'efficiency'
Line 165 of spacy/cli/init_config
sets variables["transformer_data"] = None
, and it causes a problem in the next line when we attempt to render the template (because None
doesn't have the accuracy
or efficiency
attributes).
My top-of-head solution could be to keep the transformer recommendation (reco["transformer"]
) and rewrite the warning into something like "...a config was generated but this won't work unless you have spacy-transformers..."
--although I'm fine with anything 👍 , I can help make a PR!
Info about spaCy
- spaCy version: 3.2.3
- Platform: Linux-5.10.16.3-microsoft-standard-WSL2-x86_64-with-glibc2.29
- Python version: 3.8.10
Yes it would definitely be a good idea to improve the UX for this case!
I just got this error too. @ljvmiranda921 were you making a PR for this? Otherwise I'm happy to make one too:)
Hi @jfainberg , sure have a go with the PR :)
Fixed by #11899.
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.