Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BugFix] Gracefully handle C++ import error in TorchRL #1640

Merged
merged 1 commit into from
Oct 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
amend
vmoens committed Oct 23, 2023
commit f2ce4a3b19cfd47adb6d22e7102ea97dc878dcfe
7 changes: 7 additions & 0 deletions torchrl/_extension.py
Original file line number Diff line number Diff line change
@@ -23,3 +23,10 @@ def _init_extension():
if not is_module_available("torchrl._torchrl"):
warnings.warn("torchrl C++ extension is not available.")
return


EXTENSION_WARNING = (
"Failed to import torchrl C++ binaries. Some modules (eg, prioritized replay buffers) may not work with your installation. "
"If you installed TorchRL from PyPI, please report the bug on TorchRL github. "
"If you installed TorchRL locally and/or in development mode, check that you have all the required compiling packages."
)
19 changes: 12 additions & 7 deletions torchrl/data/replay_buffers/samplers.py
Original file line number Diff line number Diff line change
@@ -2,20 +2,25 @@
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

import warnings
from abc import ABC, abstractmethod
from copy import deepcopy
from typing import Any, Dict, Tuple, Union

import numpy as np
import torch

from torchrl._torchrl import (
MinSegmentTreeFp32,
MinSegmentTreeFp64,
SumSegmentTreeFp32,
SumSegmentTreeFp64,
)
from ..._extension import EXTENSION_WARNING

try:
from torchrl._torchrl import (
MinSegmentTreeFp32,
MinSegmentTreeFp64,
SumSegmentTreeFp32,
SumSegmentTreeFp64,
)
except ImportError:
warnings.warn(EXTENSION_WARNING)

from .storages import Storage
from .utils import _to_numpy, INT_CLASSES
1 change: 0 additions & 1 deletion torchrl/modules/distributions/continuous.py
Original file line number Diff line number Diff line change
@@ -15,7 +15,6 @@
TruncatedNormal as _TruncatedNormal,
)

# from torchrl._torchrl import safeatanh, safetanh
from torchrl.modules.distributions.utils import (
_cast_device,
FasterTransformedDistribution,