Using R and the reticulate
package I am trying to use a pre-trained model from Huggingface. This partcular model requires PyTorch and transformers. Both are available in R via reticulate, however even though I can install and load both, the transformers package can't find the PyTorch installation.
use_virtualenv("r-reticulate")
reticulate::py_install('transformers', pip = TRUE)
reticulate::py_install("PyTorch")
transformer = reticulate::import('transformers')
torch = reticulate::import('torch')
tokenizer = transformer$AutoTokenizer$from_pretrained("gagan3012/keytotext-small")
model = transformer$AutoModel$from_pretrained("gagan3012/keytotext-small")
and the error:
Error in py_call_impl(callable, dots$args, dots$keywords): ImportError:
AutoModel requires the PyTorch library but it was not found in your environment. Checkout the instructions on the
installation page: https://pytorch.org/get-started/locally/ and follow the ones that match your environment.
Detailed traceback:
File "/miniconda/envs/r-reticulate/lib/python3.7/site-packages/transformers/utils/dummy_pt_objects.py", line 364, in from_pretrained
requires_backends(cls, ["torch"])
File "/miniconda/envs/r-reticulate/lib/python3.7/site-packages/transformers/file_utils.py", line 683, in requires_backends
raise ImportError("".join([BACKENDS_MAPPING[backend][1].format(name) for backend in backends]))
Traceback:
1. transformer$AutoModel$from_pretrained("gagan3012/keytotext-small")
2. py_call_impl(callable, dots$args, dots$keywords)
but PyTorch is definitely installed - I can call methods i.e torch$cudnn_convolution_add_relu
so how can I tell the transformers package where torch is?