Skip to content

Commit

Permalink
[RLlib] Fix erroring our when tuning any algo without torch being ins…
Browse files Browse the repository at this point in the history
…talled. (ray-project#31177)
  • Loading branch information
ArturNiederfahrenhorst committed Dec 19, 2022
1 parent 98fef77 commit 70b0d03
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion rllib/algorithms/qmix/qmix_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from ray.rllib.utils.torch_utils import apply_grad_clipping

# Torch must be installed.
torch, nn = try_import_torch(error=True)
torch, nn = try_import_torch(error=False)

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -167,6 +167,12 @@ class QMixTorchPolicy(TorchPolicy):
"""

def __init__(self, obs_space, action_space, config):
# We want to error out on instantiation and not on import, because tune
# imports all RLlib algorithms when registering them
# TODO (Artur): Find a way to only import algorithms when needed
if not torch:
raise ImportError("Could not import PyTorch, which QMix requires.")

_validate(obs_space, action_space)
config = dict(ray.rllib.algorithms.qmix.qmix.DEFAULT_CONFIG, **config)
self.framework = "torch"
Expand Down

0 comments on commit 70b0d03

Please sign in to comment.