-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
test_dependency_torch.py
executable file
·43 lines (32 loc) · 1.16 KB
/
test_dependency_torch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
# Do not import torch for testing purposes.
os.environ["RLLIB_TEST_NO_TORCH_IMPORT"] = "1"
# Test registering (includes importing) all Algorithms.
from ray.rllib import _register_all
# This should surface any dependency on torch, e.g. inside function
# signatures/typehints.
_register_all()
from ray.rllib.algorithms.ppo import PPOConfig
assert "torch" not in sys.modules, "`torch` initially present, when it shouldn't!"
# Note: No ray.init(), to test it works without Ray
config = (
PPOConfig()
.environment("CartPole-v1")
.framework("tf")
.env_runners(num_env_runners=0)
# Disable the logger due to a sort-import attempt of torch
# inside the tensorboardX.SummaryWriter class.
.debugging(logger_config={"type": "ray.tune.logger.NoopLogger"})
)
algo = config.build()
algo.train()
assert (
"torch" not in sys.modules
), "`torch` should not be imported after creating and training A3C!"
# Clean up.
del os.environ["RLLIB_TEST_NO_TORCH_IMPORT"]
algo.stop()
print("ok")