mirror of
https://github.com/wassname/ray.git
synced 2026-09-12 12:51:15 +08:00
[RLlib] TorchPolicies: Accessing "infos" dict in train_batch causes TypeError. (#13039)
This commit is contained in:
@@ -63,11 +63,20 @@ def convert_to_torch_tensor(x, device=None):
|
||||
return RepeatedValues(
|
||||
tree.map_structure(mapping, item.values), item.lengths,
|
||||
item.max_len)
|
||||
# Non-writable numpy-arrays will cause PyTorch warning.
|
||||
if isinstance(item, np.ndarray) and item.flags.writeable is False:
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore")
|
||||
# Numpy arrays.
|
||||
if isinstance(item, np.ndarray):
|
||||
# np.object_ type (e.g. info dicts in train batch): leave as-is.
|
||||
if item.dtype == np.object_:
|
||||
return item
|
||||
# Non-writable numpy-arrays will cause PyTorch warning.
|
||||
elif item.flags.writeable is False:
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore")
|
||||
tensor = torch.from_numpy(item)
|
||||
# Already numpy: Wrap as torch tensor.
|
||||
else:
|
||||
tensor = torch.from_numpy(item)
|
||||
# Everything else: Convert to numpy, then wrap as torch tensor.
|
||||
else:
|
||||
tensor = torch.from_numpy(np.asarray(item))
|
||||
# Floatify all float64 tensors.
|
||||
|
||||
Reference in New Issue
Block a user