I’m getting the following error when attempting to export a tf serving model using the checkpoint file. For context, I’m using action masking on a Tuple Action space and I wasn’t getting this error prior to using action masking so perhaps that is where the issue lies. The error message lists out a number of arrays but which ones have the shape mismatch?
Traceback (most recent call last):
File "train-ray.py", line 420, in <module>
MyLauncher().train_main()
File "/opt/ml/code/sagemaker_rl/ray_launcher.py", line 350, in train_main
launcher.launch()
File "train-ray.py", line 389, in launch
use_pytorch=use_pytorch)
File "/opt/ml/code/sagemaker_rl/ray_launcher.py", line 251, in save_checkpoint_and_serving_model
self.create_tf_serving_model(algorithm, env_string)
File "/opt/ml/code/sagemaker_rl/ray_launcher.py", line 240, in create_tf_serving_model
agent = cls(env=env_string, config=config)
File "/usr/local/lib/python3.6/dist-packages/ray/rllib/agents/trainer_template.py", line 90, in __init__
Trainer.__init__(self, config, env, logger_creator)
File "/usr/local/lib/python3.6/dist-packages/ray/rllib/agents/trainer.py", line 448, in __init__
super().__init__(config, logger_creator)
File "/usr/local/lib/python3.6/dist-packages/ray/tune/trainable.py", line 174, in __init__
self._setup(copy.deepcopy(self.config))
File "/usr/local/lib/python3.6/dist-packages/ray/rllib/agents/trainer.py", line 591, in _setup
self._init(self.config, self.env_creator)
File "/usr/local/lib/python3.6/dist-packages/ray/rllib/agents/trainer_template.py", line 117, in _init
self.config["num_workers"])
File "/usr/local/lib/python3.6/dist-packages/ray/rllib/agents/trainer.py", line 662, in _make_workers
logdir=self.logdir)
File "/usr/local/lib/python3.6/dist-packages/ray/rllib/evaluation/worker_set.py", line 61, in __init__
RolloutWorker, env_creator, policy, 0, self._local_config)
File "/usr/local/lib/python3.6/dist-packages/ray/rllib/evaluation/worker_set.py", line 279, in _make_worker
extra_python_environs=extra_python_environs)
File "/usr/local/lib/python3.6/dist-packages/ray/rllib/evaluation/rollout_worker.py", line 391, in __init__
policy_dict, policy_config)
File "/usr/local/lib/python3.6/dist-packages/ray/rllib/evaluation/rollout_worker.py", line 859, in _build_policy_map
policy_map[name] = cls(obs_space, act_space, merged_conf)
File "/usr/local/lib/python3.6/dist-packages/ray/rllib/policy/eager_tf_policy.py", line 258, in __init__
self._initialize_loss_with_dummy_batch()
File "/usr/local/lib/python3.6/dist-packages/ray/rllib/policy/eager_tf_policy.py", line 632, in _initialize_loss_with_dummy_batch
SampleBatch(dummy_batch))
File "/usr/local/lib/python3.6/dist-packages/ray/rllib/policy/sample_batch.py", line 62, in __init__
self.data, lengths)
AssertionError: ('data columns must be same length', {'obs': array([[-0.16753997, -0.8131003 , -0.3058182 , 0.2200041 , -0.8453412 ,
-0.2022055 , 0.85689116, 0.24618384, -0.7730741 , -0.11723867,
0.24153124, 0.06563056, -0.9881637 , 0.3914931 , -0.42937464,
-0.61651164, 0.16560812, 0.43424338, -0.48306796, -0.16379589,
0.6629045 , -0.83640736, 0.55711555, -0.99590707, 0.4565502 ,
0.5004547 , 0.09825385, -0.6208752 , 0.30217493, -0.95540255,
-0.9390568 , -0.15556492, 0.9635776 , -0.7789579 , -0.08081707,
-0.5235052 , 0.36796525, -0.2596724 , 0.2986152 , -0.9335729 ,
-0.8205236 , -0.07025883, -0.17298482, 0.59653604, 0.78505236,
-0.37407067, 0.3451196 , 0.8478205 , 0.6491549 , -0.3552222 ,
-0.9410455 , -0.19240941, 0.2433002 , 0.92845184, 0.13893473,
-0.46645886, 0.77974063, 0.9887864 , -0.5882755 , -0.16081837,
0.18821715, -0.48406398, -0.18187997, -0.26430282, -0.09947821,
-0.6070124 , -0.00425298, 0.60601455, 0.478472 , -0.73200834,
-0.9221117 , -0.57326376, 0.8292637 , -0.27201414, -0.49593267]],
dtype=float32), 'new_obs': array([[ 0.8084266 , 0.60376465, 0.78310597, 0.45286018, -0.5389207 ,
-0.26351827, -0.19457214, -0.45364273, -0.7939361 , -0.6026908 ,
-0.366684 , -0.26129752, 0.45846698, 0.9235534 , -0.6174818 ,
-0.27158985, -0.3849102 , -0.42492867, -0.01951972, -0.9497818 ,
0.6311238 , 0.3333413 , -0.8332515 , 0.5431858 , 0.65956146,
0.02491495, -0.12982146, 0.2892342 , -0.06229191, 0.21960628,
0.03798034, -0.8105211 , 0.45083812, 0.5011283 , 0.9295937 ,
-0.347093 , -0.2709405 , -0.40550342, 0.33635706, 0.6673113 ,
-0.81663233, -0.7930882 , -0.09971744, -0.982902 , 0.4535259 ,
0.67291045, -0.623508 , 0.7011699 , -0.65178597, -0.36389652,
0.48030367, 0.8339387 , -0.29725808, -0.48181954, 0.9213085 ,
0.332354 , -0.75827074, 0.78023595, -0.2888754 , -0.3171853 ,
0.10102597, 0.48887405, 0.7183128 , 0.9172779 , -0.13899948,
0.06689885, 0.05988894, 0.9012435 , -0.5165003 , 0.7978972 ,
0.65684813, -0.3593439 , 0.2804876 , -0.96951115, -0.4018025 ]],
dtype=float32), 'dones': array([False]), 'actions': array([[4],
[5],
[0],
[0]]), 'rewards': array([0.], dtype=float32), 'prev_actions': array([[4],
[5],
[0],
[0]]), 'prev_rewards': array([0.], dtype=float32), 'action_prob': array([1.], dtype=float32), 'action_logp': array([0.], dtype=float32), 'action_dist_inputs': array([[-1.8790666e-03, -1.2569092e-03, 8.0820790e-04, 1.5254925e-03,
3.0071309e-03, -6.0335770e-03, 1.9848817e-03, -5.2638206e-05,
-1.4693772e-03, -1.6271004e-03, -6.9682496e-03, -2.8726761e-03,
5.1925275e-03, 2.4756842e-04, -7.4656908e-03, 2.0904108e-03,
8.5534025e-03, -6.3283751e-03, -5.6225746e-03, 2.0334723e-03,
8.9268445e-04, 2.4471004e-03, 3.7310375e-03, -1.2613479e-03,
-1.7964891e-03, -1.6982645e-03, -3.7542414e-03, -2.3088434e-03,
-4.4651306e-03, 3.2427113e-03, -6.2494841e-03, 1.1091821e-03]],
dtype=float32), 'vf_preds': array([-0.00676239], dtype=float32)}, [1, 1, 1, 4, 1, 4, 1, 1, 1, 1, 1])
I get this error after running the following:
if ray.__version__ >= "0.6.5":
from ray.rllib.agents.registry import get_agent_class
else:
from ray.rllib.agents.agent import get_agent_class
cls = get_agent_class(algorithm)
with open(os.path.join(MODEL_OUTPUT_DIR, "params.json")) as config_json:
config = json.load(config_json)
print("Loaded config for TensorFlow serving.")
config["monitor"] = False
config["num_workers"] = 1
config["num_gpus"] = 0
agent = cls(env=env_string, config=config)
checkpoint = os.path.join(MODEL_OUTPUT_DIR, "checkpoint")
agent.restore(checkpoint)
export_tf_serving(agent, MODEL_OUTPUT_DIR)