ml-agents icon indicating copy to clipboard operation
ml-agents copied to clipboard

About dynamic_partition and loss calculation

Open MengqiYe opened this issue 7 years ago • 5 comments

While reading into ppo_optimizer, I found that dynamic_partition is used to mask input by all loss calculation. My question is, what's this mask? I followed mini_batch feeding, it seems it's always full one. So is this dynamic_partition still meaningful? Is this mask affected by BP? Thanks for reading, any help appreciated.

MengqiYe avatar Apr 16 '19 07:04 MengqiYe

Hi @seaswander

We use the mask for when training LSTMs. This allows us to mask out the ends of trajectories which are of variable sizes, and "zeroed out."

awjuliani avatar Apr 16 '19 20:04 awjuliani

@awjuliani Thanks for your explanation! Actually I'm trying to rewrite trainers with Pytorch, and it confuses me that intermediate variables (v_opt_a , v_opt_b, r_theta ,p_opt_a ,p_opt_b ) seems not to be in the computation graph, therefore not affected by optimizer. I printed the computation graph, and the optimizer variables, totally 52 of them. And variables doubled for the Adam part. As followed: ppo_optimizer <tf.Variable 'ppo_optimizer/beta1_power:0' shape=() dtype=float32_ref> <tf.Variable 'ppo_optimizer/beta2_power:0' shape=() dtype=float32_ref> <tf.Variable 'ppo_optimizer/curiosity_forward_model/dense/bias/Adam:0' shape=(256,) dtype=float32_ref> <tf.Variable 'ppo_optimizer/curiosity_forward_model/dense/bias/Adam_1:0' shape=(256,) dtype=float32_ref> <tf.Variable 'ppo_optimizer/curiosity_forward_model/dense/kernel/Adam:0' shape=(130, 256) dtype=float32_ref> <tf.Variable 'ppo_optimizer/curiosity_forward_model/dense/kernel/Adam_1:0' shape=(130, 256) dtype=float32_ref> <tf.Variable 'ppo_optimizer/curiosity_forward_model/dense_1/bias/Adam:0' shape=(128,) dtype=float32_ref> <tf.Variable 'ppo_optimizer/curiosity_forward_model/dense_1/bias/Adam_1:0' shape=(128,) dtype=float32_ref> <tf.Variable 'ppo_optimizer/curiosity_forward_model/dense_1/kernel/Adam:0' shape=(256, 128) dtype=float32_ref> <tf.Variable 'ppo_optimizer/curiosity_forward_model/dense_1/kernel/Adam_1:0' shape=(256, 128) dtype=float32_ref> <tf.Variable 'ppo_optimizer/curiosity_inverse_model/dense/bias/Adam:0' shape=(256,) dtype=float32_ref> <tf.Variable 'ppo_optimizer/curiosity_inverse_model/dense/bias/Adam_1:0' shape=(256,) dtype=float32_ref> <tf.Variable 'ppo_optimizer/curiosity_inverse_model/dense/kernel/Adam:0' shape=(256, 256) dtype=float32_ref> <tf.Variable 'ppo_optimizer/curiosity_inverse_model/dense/kernel/Adam_1:0' shape=(256, 256) dtype=float32_ref> <tf.Variable 'ppo_optimizer/curiosity_inverse_model/dense_1/bias/Adam:0' shape=(2,) dtype=float32_ref> <tf.Variable 'ppo_optimizer/curiosity_inverse_model/dense_1/bias/Adam_1:0' shape=(2,) dtype=float32_ref> <tf.Variable 'ppo_optimizer/curiosity_inverse_model/dense_1/kernel/Adam:0' shape=(256, 2) dtype=float32_ref> <tf.Variable 'ppo_optimizer/curiosity_inverse_model/dense_1/kernel/Adam_1:0' shape=(256, 2) dtype=float32_ref> <tf.Variable 'ppo_optimizer/dense/bias/Adam:0' shape=(1,) dtype=float32_ref> <tf.Variable 'ppo_optimizer/dense/bias/Adam_1:0' shape=(1,) dtype=float32_ref> <tf.Variable 'ppo_optimizer/dense/kernel/Adam:0' shape=(128, 1) dtype=float32_ref> <tf.Variable 'ppo_optimizer/dense/kernel/Adam_1:0' shape=(128, 1) dtype=float32_ref> <tf.Variable 'ppo_optimizer/log_sigma_squared/Adam:0' shape=(2,) dtype=float32_ref> <tf.Variable 'ppo_optimizer/log_sigma_squared/Adam_1:0' shape=(2,) dtype=float32_ref> <tf.Variable 'ppo_optimizer/mu/dense/bias/Adam:0' shape=(2,) dtype=float32_ref> <tf.Variable 'ppo_optimizer/mu/dense/bias/Adam_1:0' shape=(2,) dtype=float32_ref> <tf.Variable 'ppo_optimizer/mu/dense/kernel/Adam:0' shape=(128, 2) dtype=float32_ref> <tf.Variable 'ppo_optimizer/mu/dense/kernel/Adam_1:0' shape=(128, 2) dtype=float32_ref> <tf.Variable 'ppo_optimizer/observation_streams/main_graph_0/hidden_0/bias/Adam:0' shape=(128,) dtype=float32_ref> <tf.Variable 'ppo_optimizer/observation_streams/main_graph_0/hidden_0/bias/Adam_1:0' shape=(128,) dtype=float32_ref> <tf.Variable 'ppo_optimizer/observation_streams/main_graph_0/hidden_0/kernel/Adam:0' shape=(8, 128) dtype=float32_ref> <tf.Variable 'ppo_optimizer/observation_streams/main_graph_0/hidden_0/kernel/Adam_1:0' shape=(8, 128) dtype=float32_ref> <tf.Variable 'ppo_optimizer/observation_streams/main_graph_0/hidden_1/bias/Adam:0' shape=(128,) dtype=float32_ref> <tf.Variable 'ppo_optimizer/observation_streams/main_graph_0/hidden_1/bias/Adam_1:0' shape=(128,) dtype=float32_ref> <tf.Variable 'ppo_optimizer/observation_streams/main_graph_0/hidden_1/kernel/Adam:0' shape=(128, 128) dtype=float32_ref> <tf.Variable 'ppo_optimizer/observation_streams/main_graph_0/hidden_1/kernel/Adam_1:0' shape=(128, 128) dtype=float32_ref> <tf.Variable 'ppo_optimizer/observation_streams/main_graph_1/hidden_0/bias/Adam:0' shape=(128,) dtype=float32_ref> <tf.Variable 'ppo_optimizer/observation_streams/main_graph_1/hidden_0/bias/Adam_1:0' shape=(128,) dtype=float32_ref> <tf.Variable 'ppo_optimizer/observation_streams/main_graph_1/hidden_0/kernel/Adam:0' shape=(8, 128) dtype=float32_ref> <tf.Variable 'ppo_optimizer/observation_streams/main_graph_1/hidden_0/kernel/Adam_1:0' shape=(8, 128) dtype=float32_ref> <tf.Variable 'ppo_optimizer/observation_streams/main_graph_1/hidden_1/bias/Adam:0' shape=(128,) dtype=float32_ref> <tf.Variable 'ppo_optimizer/observation_streams/main_graph_1/hidden_1/bias/Adam_1:0' shape=(128,) dtype=float32_ref> <tf.Variable 'ppo_optimizer/observation_streams/main_graph_1/hidden_1/kernel/Adam:0' shape=(128, 128) dtype=float32_ref> <tf.Variable 'ppo_optimizer/observation_streams/main_graph_1/hidden_1/kernel/Adam_1:0' shape=(128, 128) dtype=float32_ref> <tf.Variable 'ppo_optimizer/vector_obs_encoder/hidden_0/bias/Adam:0' shape=(128,) dtype=float32_ref> <tf.Variable 'ppo_optimizer/vector_obs_encoder/hidden_0/bias/Adam_1:0' shape=(128,) dtype=float32_ref> <tf.Variable 'ppo_optimizer/vector_obs_encoder/hidden_0/kernel/Adam:0' shape=(8, 128) dtype=float32_ref> <tf.Variable 'ppo_optimizer/vector_obs_encoder/hidden_0/kernel/Adam_1:0' shape=(8, 128) dtype=float32_ref> <tf.Variable 'ppo_optimizer/vector_obs_encoder/hidden_1/bias/Adam:0' shape=(128,) dtype=float32_ref> <tf.Variable 'ppo_optimizer/vector_obs_encoder/hidden_1/bias/Adam_1:0' shape=(128,) dtype=float32_ref> <tf.Variable 'ppo_optimizer/vector_obs_encoder/hidden_1/kernel/Adam:0' shape=(128, 128) dtype=float32_ref> <tf.Variable 'ppo_optimizer/vector_obs_encoder/hidden_1/kernel/Adam_1:0' shape=(128, 128) dtype=float32_ref> Would you reveal the chain of BP, for the basic 3DBallLearning example? And is there a way to inspect tensors variation properly? Thank you.

MengqiYe avatar Apr 17 '19 10:04 MengqiYe

Hello @seaswander These are definitely part of the computation graph, as they are used to compute the loss. Unfortunately I cannot help you with specifics of repurposing our code for Pytorch. That being said, I am aware of some high quality implementations written in pytorch which may be worth taking a look at, such as https://github.com/kengz/SLM-Lab

awjuliani avatar Apr 17 '19 17:04 awjuliani

@awjuliani Thanks for your help!

MengqiYe avatar Apr 18 '19 01:04 MengqiYe

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

lock[bot] avatar Apr 17 '20 12:04 lock[bot]