[RLlib] TFPolicy.export_model: Add timestep placeholder to model's signature, if needed. (#13988)

This commit is contained in:
Sven Mika
2021-02-10 15:21:46 +01:00
committed by GitHub
parent 37c7daa3c0
commit 81e7434091
2 changed files with 13 additions and 0 deletions
+5
View File
@@ -709,9 +709,14 @@ class TFPolicy(Policy):
input_signature["prev_reward"] = \
tf1.saved_model.utils.build_tensor_info(
self._prev_reward_input)
input_signature["is_training"] = \
tf1.saved_model.utils.build_tensor_info(self._is_training)
if self._timestep is not None:
input_signature["timestep"] = \
tf1.saved_model.utils.build_tensor_info(self._timestep)
for state_input in self._state_inputs:
input_signature[state_input.name] = \
tf1.saved_model.utils.build_tensor_info(state_input)
+8
View File
@@ -6,8 +6,11 @@ import unittest
import ray
from ray.rllib.agents.registry import get_trainer_class
from ray.rllib.utils.framework import try_import_tf
from ray.tune.trial import ExportFormat
tf1, tf, tfv = try_import_tf()
CONFIGS = {
"A3C": {
"explore": False,
@@ -105,6 +108,11 @@ def export_test(alg_name, failures):
or not valid_tf_checkpoint(os.path.join(export_dir,
ExportFormat.CHECKPOINT)):
failures.append(alg_name)
# Test loading the exported model.
model = tf.saved_model.load(os.path.join(export_dir, ExportFormat.MODEL))
assert model
shutil.rmtree(export_dir)