[rllib] fix clip by value issue as TF upgraded (#4697)

*  fix clip_by_value issue

*  fix typo
This commit is contained in:
Jones Wong 2019-05-14 06:39:25 +08:00 committed by Eric Liang
parent 1622fc21fc
commit c5161a2c4d
2 changed files with 11 additions and 5 deletions

View file

@ -166,8 +166,9 @@ class DDPGPolicyGraph(DDPGPostprocessing, TFPolicyGraph):
stddev=self.config["target_noise"]), stddev=self.config["target_noise"]),
-target_noise_clip, target_noise_clip) -target_noise_clip, target_noise_clip)
policy_tp1_smoothed = tf.clip_by_value( policy_tp1_smoothed = tf.clip_by_value(
policy_tp1 + clipped_normal_sample, action_space.low, policy_tp1 + clipped_normal_sample,
action_space.high) action_space.low * tf.ones_like(policy_tp1),
action_space.high * tf.ones_like(policy_tp1))
else: else:
# no smoothing, just use deterministic actions # no smoothing, just use deterministic actions
policy_tp1_smoothed = policy_tp1 policy_tp1_smoothed = policy_tp1
@ -473,8 +474,9 @@ class DDPGPolicyGraph(DDPGPostprocessing, TFPolicyGraph):
tf.shape(deterministic_actions), tf.shape(deterministic_actions),
stddev=self.config["exploration_gaussian_sigma"]) stddev=self.config["exploration_gaussian_sigma"])
stochastic_actions = tf.clip_by_value( stochastic_actions = tf.clip_by_value(
deterministic_actions + normal_sample, action_low, deterministic_actions + normal_sample,
action_high) action_low * tf.ones_like(deterministic_actions),
action_high * tf.ones_like(deterministic_actions))
elif noise_type == "ou": elif noise_type == "ou":
# add OU noise for exploration, DDPG-style # add OU noise for exploration, DDPG-style
zero_acts = action_low.size * [.0] zero_acts = action_low.size * [.0]
@ -494,7 +496,9 @@ class DDPGPolicyGraph(DDPGPostprocessing, TFPolicyGraph):
noise = noise_scale * base_scale \ noise = noise_scale * base_scale \
* exploration_value * action_range * exploration_value * action_range
stochastic_actions = tf.clip_by_value( stochastic_actions = tf.clip_by_value(
deterministic_actions + noise, action_low, action_high) deterministic_actions + noise,
action_low * tf.ones_like(deterministic_actions),
action_high * tf.ones_like(deterministic_actions))
else: else:
raise ValueError( raise ValueError(
"Unknown noise type '%s' (try 'ou' or 'gaussian')" % "Unknown noise type '%s' (try 'ou' or 'gaussian')" %

View file

@ -47,6 +47,8 @@ class TFRunBuilder(object):
self.session, self.fetches, self.debug_name, self.session, self.fetches, self.debug_name,
self.feed_dict, os.environ.get("TF_TIMELINE_DIR")) self.feed_dict, os.environ.get("TF_TIMELINE_DIR"))
except Exception: except Exception:
logger.exception("Error fetching: {}, feed_dict={}".format(
self.fetches, self.feed_dict))
raise ValueError("Error fetching: {}, feed_dict={}".format( raise ValueError("Error fetching: {}, feed_dict={}".format(
self.fetches, self.feed_dict)) self.fetches, self.feed_dict))
if isinstance(to_fetch, int): if isinstance(to_fetch, int):