Reputation: 915
I am just getting started with using TPUs on kaggle with Pytorch and install it as follows -
!pip3 install mkl
!curl https://raw.githubusercontent.com/pytorch/xla/master/contrib/scripts/env-setup.py -o pytorch-xla-env-setup.py
!python3 pytorch-xla-env-setup.py --version nightly --apt-packages libomp5 libopenblas-dev
However, after installing Pytorch XLA, I am not able to use NumPy at all. Whenever I call functions like np.uint8
or even NumPy based functions from like torch.from_numpy
I get an error whose bottom line says - NumPy not Available
. Please note that I am able to import Numpy.
The whole stack trace is as follows -
RuntimeError Traceback (most recent call last)
<ipython-input-1-abfcbbc939b0> in <module>
1026 segmentation_Maps='/kaggle/input/pascal-voc/VOC2012/SegmentationClass/')
1027 dataloader = DataLoader(dataset, batch_size=5)
-> 1028 for _, data in enumerate(dataloader):
1029 i = data['image']
1030 gt = data['ground_truth']
/opt/conda/lib/python3.7/site-packages/torch/utils/data/dataloader.py in __next__(self)
519 if self._sampler_iter is None:
520 self._reset()
--> 521 data = self._next_data()
522 self._num_yielded += 1
523 if self._dataset_kind == _DatasetKind.Iterable and \
/opt/conda/lib/python3.7/site-packages/torch/utils/data/dataloader.py in _next_data(self)
559 def _next_data(self):
560 index = self._next_index() # may raise StopIteration
--> 561 data = self._dataset_fetcher.fetch(index) # may raise StopIteration
562 if self._pin_memory:
563 data = _utils.pin_memory.pin_memory(data)
/opt/conda/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py in fetch(self, possibly_batched_index)
42 def fetch(self, possibly_batched_index):
43 if self.auto_collation:
---> 44 data = [self.dataset[idx] for idx in possibly_batched_index]
45 else:
46 data = self.dataset[possibly_batched_index]
/opt/conda/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py in <listcomp>(.0)
42 def fetch(self, possibly_batched_index):
43 if self.auto_collation:
---> 44 data = [self.dataset[idx] for idx in possibly_batched_index]
45 else:
46 data = self.dataset[possibly_batched_index]
<ipython-input-1-abfcbbc939b0> in __getitem__(self, item)
939 print(mask.shape)
940 image = Image.fromarray(np.uint8(image)).convert('RGB')
--> 941 mask = torch.from_numpy(np.uint8(mask))
942
943 image = self.transforms(image)
RuntimeError: Numpy is not available
I have no clue what is going on. Could someone please Help.
PS - please note that pytorch xla updates pytorch to a nightly 1.9 version.
TIA
Upvotes: 3
Views: 5364
Reputation: 11
This is an issue with the version mismatch. Currently the pytorch version 1.12.1+cu113 is compatible with numpy version 1.21.6.
I don't know why this occurs. But keep checking the version in google colab and you can possibly make torch work locally.
Upvotes: 1
Reputation: 3813
At least in Google Colab I was able to solve this issue by running (after installing xla
):
!pip install -U numpy
Not completely sure it will help in any context
Upvotes: 4