[RLlib] Allow for more than 2^31 policy timesteps. (#11301)

This commit is contained in:
Sven Mika
2020-10-12 13:49:11 -07:00
committed by GitHub
parent f5e2cda68a
commit 8ea1bc5ff9
11 changed files with 96 additions and 14 deletions
+7 -2
View File
@@ -1,4 +1,5 @@
import logging
import numpy as np
import os
import sys
from typing import Any, Optional
@@ -185,6 +186,7 @@ def get_variable(value,
does not have any (e.g. if it's an initializer w/o explicit value).
dtype (Optional[TensorType]): An optional dtype to use iff `value` does
not have any (e.g. if it's an initializer w/o explicit value).
This should always be a numpy dtype (e.g. np.float32, np.int64).
Returns:
any: A framework-specific variable (tf.Variable, torch.tensor, or
@@ -207,10 +209,13 @@ def get_variable(value,
elif framework == "torch" and torch_tensor is True:
torch, _ = try_import_torch()
var_ = torch.from_numpy(value)
if dtype == torch.float32:
if dtype in [torch.float32, np.float32]:
var_ = var_.float()
elif dtype == torch.int32:
elif dtype in [torch.int32, np.int32]:
var_ = var_.int()
elif dtype in [torch.float64, np.float64]:
var_ = var_.double()
if device:
var_ = var_.to(device)
var_.requires_grad = trainable