Ray not detecting PyTorch installation

How severe does this issue affect your experience of using Ray?

  • High: It blocks me to complete my task.

When running Tune (to launch rllib) I get the following error:
ImportError: PyTorch was specified as the framework to use (via config.framework('torch'))! However, no installation was found. You can install PyTorch via pip install torch.

But PyTorch is installed in my active Conda environment, specifically:
Pytorch 2.0.1 py3.10_cuda11.8_cudnn8.7.0_0
I am running v 2.4.0 of all Ray components on Linux (WSL).
Many thanks in advance. Here is the full error message:

Traceback (most recent call last):
File xxx line 39, in
tune.run(
File “/home/xxx/miniconda3/envs/wsl-ray-2/lib/python3.10/site-packages/ray/tune/tune.py”, line 904, in run
runner.step()
File “/home/xxx/miniconda3/envs/wsl-ray-2/lib/python3.10/site-packages/ray/tune/execution/trial_runner.py”, line 1338, in step
next_trial = self._update_trial_queue_and_get_next_trial()
File “/home/xxx/miniconda3/envs/wsl-ray-2/lib/python3.10/site-packages/ray/tune/execution/trial_runner.py”, line 1315, in _update_trial_queue_and_get_next_trial
if not self._update_trial_queue(blocking=wait_for_trial):
File “/home/xxx/miniconda3/envs/wsl-ray-2/lib/python3.10/site-packages/ray/tune/execution/trial_runner.py”, line 1068, in _update_trial_queue
self.add_trial(trial)
File “/home/xxx/miniconda3/envs/wsl-ray-2/lib/python3.10/site-packages/ray/tune/execution/trial_runner.py”, line 556, in add_trial
trial.create_placement_group_factory()
File “/home/xxx/miniconda3/envs/wsl-ray-2/lib/python3.10/site-packages/ray/tune/experiment/trial.py”, line 525, in create_placement_group_factory
default_resources = trainable_cls.default_resource_request(self.config)
File “/home/xxx/miniconda3/envs/wsl-ray-2/lib/python3.10/site-packages/ray/rllib/algorithms/algorithm.py”, line 2167, in default_resource_request
cf.validate()
File “/home/xxx/miniconda3/envs/wsl-ray-2/lib/python3.10/site-packages/ray/rllib/algorithms/ppo/ppo.py”, line 274, in validate
super().validate()
File “/home/xxx/miniconda3/envs/wsl-ray-2/lib/python3.10/site-packages/ray/rllib/algorithms/pg/pg.py”, line 99, in validate
super().validate()
File “/home/xxx/miniconda3/envs/wsl-ray-2/lib/python3.10/site-packages/ray/rllib/algorithms/algorithm_config.py”, line 768, in validate
self._check_if_correct_nn_framework_installed(_tf1, _tf, _torch)
File “/home/xxx/miniconda3/envs/wsl-ray-2/lib/python3.10/site-packages/ray/rllib/algorithms/algorithm_config.py”, line 3287, in _check_if_correct_nn_framework_installed
raise ImportError(
ImportError: PyTorch was specified as the framework to use (via config.framework('torch'))! However, no installation was found. You can install PyTorch via pip install torch.

I believe that the experimental support for PyTorch 2.0 is just launched in Ray 2.5? @arturn

I reinstalled PyTorch:
pytorch 2.0.1 py3.10_cuda11.8_cudnn8.7.0_0
Now seems to be running ok, but do you recommend I downgrade PyTorch to <2.0 ?

2.0 should be ok with the newest release of ray (2.5)

1 Like