Unable to convert output to PyTorch tensors format, PyTorch is not installed

Hello,

I installed torch in MacOS in my Macbook Pro. It is Apple M2 Pro. ACAYCI-mac 23.2.0 Darwin Kernel Version 23.2.0: Wed Nov 15 21:55:06 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T6020 arm64

I installed it using pip3.

(base) bash-3.2$ pip3 show torch
Name: torch
Version: 2.1.2
Summary: Tensors and Dynamic neural networks in Python with strong GPU acceleration
Home-page: https://pytorch.org/
Author: PyTorch Team
Author-email: packages@pytorch.org
License: BSD-3
Location: /Users/ACAYCI/anaconda3/lib/python3.11/site-packages
Requires: filelock, fsspec, jinja2, networkx, sympy, typing-extensions
Required-by: torchaudio, torchvision

In my Jupyter notebook, I have the following code:

input_ids = tokenizer.encode(input_text, return_tensors=‘pt’)

During the execution, it is giving

File ~/anaconda3/lib/python3.11/site-packages/transformers/tokenization_utils_base.py:700, in BatchEncoding.convert_to_tensors(self, tensor_type, prepend_batch_axis)
698 elif tensor_type == TensorType.PYTORCH:
699 if not is_torch_available():
→ 700 raise ImportError(“Unable to convert output to PyTorch tensors format, PyTorch is not installed.”)
701 import torch
703 is_tensor = torch.is_tensor

ImportError: Unable to convert output to PyTorch tensors format, PyTorch is not installed.

Any help is much appreciated.

Mustafa

Hello,

I was able to fix this issue. I just restarted the Kernel. It took care of it.

Mustafa

1 Like