I am getting the following error when trying to execute code (in [10] section "Interpretable Drift Detection on the Wine Quality Dataset" from github.com/SeldonIO/alibi-detect/blob/d89ba819d87dcb7848f8e96445c554668449fcc4/doc/source/examples/cd_spot_the_diff_mnist_wine.ipynb:
```
RuntimeError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_3564/2414863533.py in
10 )
11
---> 12 preds_h0 = cd.predict(x_h0)
13 preds_corr = cd.predict(x_corr)
~\AppData\Roaming\Python\Python39\site-packages\alibi_detect\cd\spot_the_diff.py in predict(self, x, return_p_val, return_distance, return_probs, return_model)
173 data, and the trained model.
174 """
--> 175 return self._detector.predict(x, return_p_val, return_distance, return_probs, return_model)
~\AppData\Roaming\Python\Python39\site-packages\alibi_detect\cd\pytorch\spot_the_diff.py in predict(self, x, return_p_val, return_distance, return_probs, return_model)
212 data, and the trained model.
213 """
--> 214 preds = self._detector.predict(x, return_p_val, return_distance, return_probs, return_model=True)
215 preds['data']['diffs'] = preds['data']['model'].diffs.detach().cpu().numpy() # type: ignore
216 preds['data']['diff_coeffs'] = preds['data']['model'].coeffs.detach().cpu().numpy() # type: ignore
~\AppData\Roaming\Python\Python39\site-packages\alibi_detect\cd\base.py in predict(self, x, return_p_val, return_distance, return_probs, return_model)
241 """
242 # compute drift scores
--> 243 p_val, dist, probs_ref, probs_test = self.score(x)
244 drift_pred = int(p_val < self.p_val)
245
~\AppData\Roaming\Python\Python39\site-packages\alibi_detect\cd\pytorch\classifier.py in score(self, x)
182 self.model = self.model.to(self.device)
183 train_args = [self.model, self.loss_fn, dl_tr, self.device]
--> 184 trainer(*train_args, **self.train_kwargs) # type: ignore
185 preds = self.predict_fn(x_te, self.model.eval())
186 preds_oof_list.append(preds)
~\AppData\Roaming\Python\Python39\site-packages\alibi_detect\models\pytorch\trainer.py in trainer(model, loss_fn, dataloader, device, optimizer, learning_rate, preprocess_fn, epochs, reg_loss_fn, verbose)
53 y_hat = model(x)
54 optimizer.zero_grad() # type: ignore
---> 55 loss = loss_fn(y_hat, y) + reg_loss_fn(model)
56 loss.backward()
57 optimizer.step() # type: ignore
~\anaconda3\lib\site-packages\torch\nn\modules\module.py in _call_impl(self, *input, **kwargs)
1100 if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks
1101 or _global_forward_hooks or _global_forward_pre_hooks):
-> 1102 return forward_call(*input, **kwargs)
1103 # Do not call functions when jit is used
1104 full_backward_hooks, non_full_backward_hooks = [], []
~\anaconda3\lib\site-packages\torch\nn\modules\loss.py in forward(self, input, target)
1148
1149 def forward(self, input: Tensor, target: Tensor) -> Tensor:
-> 1150 return F.cross_entropy(input, target, weight=self.weight,
1151 ignore_index=self.ignore_index, reduction=self.reduction,
1152 label_smoothing=self.label_smoothing)
~\anaconda3\lib\site-packages\torch\nn\functional.py in cross_entropy(input, target, weight, size_average, ignore_index, reduce, reduction, label_smoothing)
2844 if size_average is not None or reduce is not None:
2845 reduction = _Reduction.legacy_get_string(size_average, reduce)
-> 2846 return torch._C._nn.cross_entropy_loss(input, target, weight, _Reduction.get_enum(reduction), ignore_index, label_smoothing)
2847
2848
RuntimeError: expected scalar type Long but found Int
I use Python 3.8.8 (Intel CPU) or 3.9.7 (AMD CPU)/ Win10. PyTorch version: 1.10.1
EDIT: Recently I have performed some tests as follows:
Testing on CUDA free system (CPU AMD Ryzen 5-4500U with Radeon Graphics – driver no. 27.20.21020.4003 _2021):
The output of the code (import torch // torch.cuda.is_available()): False
I checked my PyTorch installation according to https://docs.microsoft.com/en-us/windows/ai/windows-ml/tutorials/pytorch-installation (that followed PyTorch official instruction). At this level of inquiry, it is ok.
I ran code from this link (https://docs.microsoft.com/en-us/windows/ai/windows-ml/tutorials/pytorch-data) and next tutorial pages to test PyTorch execution flow on my computer. After removing the error - a known issue #37 - it produced an expected result using Jupyter Notebook tool and Visual Studio 2019. The model gave info that “The model will be running on cpu device”.
I again executed the "Interpretable Drift Detection on the Wine Quality Dataset" - I obtained the same runtime error in the Jupyter notebook and info that "No GPU detected, fall back on CPU". Btw, the execution of the first code lines on Visual Studio failed and gave this output:
W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'nvcuda.dll'; dlerror: nvcuda.dll not found
W tensorflow/stream_executor/cuda/cuda_driver.cc:269] failed call to cuInit: UNKNOWN ERROR (303)
I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:169] retrieving CUDA diagnostic information for host: DESKTOP-8J5K8HK
I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:176] hostname: DESKTOP-8J5K8HK
I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
Testing on CPU Intel Core i5 and GPU NVIDIA GTX460 (336 CUDA cores, 32 ROPs, and 56 texture units; driver no. 23.21.13.8813 _2017):
The output of the code (import torch // torch.cuda.is_available()): False
PyTorch installation checking as above; result: ok
a tutorial script executed as above (the CIFAR10 dataset); result: 2 x ok, but computation was slower. The model gave info that “The model will be running on cpu device”.
a tutorial script executed as above (the Wine dataset); a result on the Jupyter Notebook: RuntimeError: expected scalar type Long but found Int; a result on the Visual Studio: failed and gave this output:
Traceback (most recent call last):
File "…\anaconda3\lib\runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "…\anaconda3\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "…\microsoft visual studio\2019\community\common7\ide\extensions\microsoft\python\core\debugpy\__main__.py", line 45, in <module>
cli.main()
File "…\microsoft visual studio\2019\community\common7\ide\extensions\microsoft\python\core\debugpy/..\debugpy\server\cli.py", line 430, in main
run()
File "…\microsoft visual studio\2019\community\common7\ide\extensions\microsoft\python\core\debugpy/..\debugpy\server\cli.py", line 267, in run_file
runpy.run_path(options.target, run_name=compat.force_str("__main__"))
File "…\anaconda3\lib\runpy.py", line 265, in run_path
return _run_module_code(code, init_globals, run_name,
File "…\anaconda3\lib\runpy.py", line 97, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "…\anaconda3\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "…\source\repos\Python_Interpretable_drift_Wine\Python_Interpretable_drift_Wine.py", line 41, in <module>
preds_h0 = cd.predict(x_h0)
File "…\anaconda3\lib\site-packages\alibi_detect\cd\spot_the_diff.py", line 175, in predict
return self._detector.predict(x, return_p_val, return_distance, return_probs, return_model)
File "…\anaconda3\lib\site-packages\alibi_detect\cd\pytorch\spot_the_diff.py", line 214, in predict
preds = self._detector.predict(x, return_p_val, return_distance, return_probs, return_model=True)
File "…\anaconda3\lib\site-packages\alibi_detect\cd\base.py", line 243, in predict
p_val, dist, probs_ref, probs_test = self.score(x)
File "…\anaconda3\lib\site-packages\alibi_detect\cd\pytorch\classifier.py", line 184, in score
trainer(*train_args, **self.train_kwargs) # type: ignore
File "…\anaconda3\lib\site-packages\alibi_detect\models\pytorch\trainer.py", line 55, in trainer
loss = loss_fn(y_hat, y) + reg_loss_fn(model)
File "…\anaconda3\lib\site-packages\torch\nn\modules\module.py", line 1102, in _call_impl
return forward_call(*input, **kwargs)
File "…\anaconda3\lib\site-packages\torch\nn\modules\loss.py", line 1150, in forward
return F.cross_entropy(input, target, weight=self.weight,
File "…\anaconda3\lib\site-packages\torch\nn\functional.py", line 2846, in cross_entropy
return torch._C._nn.cross_entropy_loss(input, target, weight, _Reduction.get_enum(reduction), ignore_index, label_smoothing)
RuntimeError: expected scalar type Long but found Int
Testing on CPU Intel Core i5 and GPU NVIDIA GTX460 (336 CUDA cores, 32 ROPs, and 56 texture units; updated driver no. 23.21.13.9135 _2018):
The output of the code:
import torch
torch.cuda.is_available()
False
The output of the code:
print(torch.rand(3,3).cuda())
AssertionError: Torch not compiled with CUDA enabled
As mentioned on https://discuss.pytorch.org/t/pytorch-nvidia-gtx460-version/62461 GTX 460 is too weak for PyTorch. The output of the code
conda install cuda -c nvidia
All requested packages already installed.
It seems that installation TensorFlow and Pytorch in the same environment results in some issues.