title: TF - ValueError: The two structures don't have the same number of elements
body: <p>I am trying to run the <a href="https://github.com/tensorflow/models/tree/master/research/learned_optimizer" rel="nofollow noreferrer">code</a> for a research paper <strong>Learned Optimizers that Scale and Generalize</strong>
  When I run the <code>metarun.py</code> file (which is the main file), I get the following error:</p>
  
  <pre><code>Traceback (most recent call last):
  File "metarun.py", line 394, in
  tf.app.run()
  File "/home/rvl224/anaconda3/lib/python3.5/site-packages/tensorflow/python/platform/app.py", line 48, in run
  _sys.exit(main(_sys.argv[:1] + flags_passthrough))
  File "metarun.py", line 388, in main
  callbacks=[])
  File "/home/rvl224/models/research/metaopt.py", line 184, in train_optimizer
  train_output = opt.train(problem, dataset)
  File "/home/rvl224/models/research/learned_optimizer/optimizer/trainable_optimizer.py", line 347, in train
  swap_memory=True, shape_invariants=invariants)
  File "/home/rvl224/anaconda3/lib/python3.5/site-packages/tensorflow/python/ops/control_flow_ops.py", line 2816, in while_loop
  result = loop_context.BuildLoop(cond, body, loop_vars, shape_invariants)
  File "/home/rvl224/anaconda3/lib/python3.5/site-packages/tensorflow/python/ops/control_flow_ops.py", line 2640, in BuildLoop
  pred, body, original_loop_vars, loop_vars, shape_invariants)
  File "/home/rvl224/anaconda3/lib/python3.5/site-packages/tensorflow/python/ops/control_flow_ops.py", line 2597, in _BuildLoop
  nest.assert_same_structure(list(packed_vars_for_body), list(body_result))
  File "/home/rvl224/anaconda3/lib/python3.5/site-packages/tensorflow/python/util/nest.py", line 222, in assert_same_structure
  % (len_nest1, nest1, len_nest2, nest2))
  ValueError: The two structures don't have the same number of elements.
  
  First structure (120 elements): 
  [&lt;tf.Tensor 'while/Identity:0' shape=() dtype=int32&gt;, &lt;tf.Tensor 'while/Identity_1:0' shape=() dtype=float32&gt;, [&lt;tf.Tensor 'while/Identity_2:0' shape=(11, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_3:0' shape=(3, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_4:0' shape=(9, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_5:0' shape=(7, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_6:0' shape=(5, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_7:0' shape=(13, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_8:0' shape=(12, 1) dtype=float32&gt;], [&lt;tf.Tensor 'while/Identity_9:0' shape=(11, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_10:0' shape=(3, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_11:0' shape=(9, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_12:0' shape=(7, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_13:0' shape=(5, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_14:0' shape=(13, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_15:0' shape=(12, 1) dtype=float32&gt;], [[&lt;tf.Tensor 'while/Identity_16:0' shape=(11, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_17:0' shape=(11, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_18:0' shape=(11, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_19:0' shape=(11, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_20:0' shape=(11, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_21:0' shape=(1, 20) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_22:0' shape=(11, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_23:0' shape=(11, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_24:0' shape=(11, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_25:0' shape=(11, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_26:0' shape=(11, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_27:0' shape=(11, 10) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_28:0' shape=(11, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_29:0' shape=(11, 1) dtype=float32&gt;], [&lt;tf.Tensor 'while/Identity_30:0' shape=(3, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_31:0' shape=(3, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_32:0' shape=(3, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_33:0' shape=(3, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_34:0' shape=(3, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_35:0' shape=(1, 20) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_36:0' shape=(3, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_37:0' shape=(3, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_38:0' shape=(3, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_39:0' shape=(3, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_40:0' shape=(3, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_41:0' shape=(3, 10) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_42:0' shape=(3, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_43:0' shape=(3, 1) dtype=float32&gt;], [&lt;tf.Tensor 'while/Identity_44:0' shape=(9, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_45:0' shape=(9, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_46:0' shape=(9, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_47:0' shape=(9, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_48:0' shape=(9, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_49:0' shape=(1, 20) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_50:0' shape=(9, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_51:0' shape=(9, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_52:0' shape=(9, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_53:0' shape=(9, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_54:0' shape=(9, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_55:0' shape=(9, 10) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_56:0' shape=(9, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_57:0' shape=(9, 1) dtype=float32&gt;], [&lt;tf.Tensor 'while/Identity_58:0' shape=(7, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_59:0' shape=(7, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_60:0' shape=(7, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_61:0' shape=(7, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_62:0' shape=(7, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_63:0' shape=(1, 20) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_64:0' shape=(7, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_65:0' shape=(7, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_66:0' shape=(7, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_67:0' shape=(7, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_68:0' shape=(7, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_69:0' shape=(7, 10) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_70:0' shape=(7, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_71:0' shape=(7, 1) dtype=float32&gt;], [&lt;tf.Tensor 'while/Identity_72:0' shape=(5, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_73:0' shape=(5, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_74:0' shape=(5, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_75:0' shape=(5, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_76:0' shape=(5, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_77:0' shape=(1, 20) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_78:0' shape=(5, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_79:0' shape=(5, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_80:0' shape=(5, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_81:0' shape=(5, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_82:0' shape=(5, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_83:0' shape=(5, 10) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_84:0' shape=(5, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_85:0' shape=(5, 1) dtype=float32&gt;], [&lt;tf.Tensor 'while/Identity_86:0' shape=(13, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_87:0' shape=(13, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_88:0' shape=(13, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_89:0' shape=(13, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_90:0' shape=(13, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_91:0' shape=(1, 20) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_92:0' shape=(13, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_93:0' shape=(13, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_94:0' shape=(13, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_95:0' shape=(13, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_96:0' shape=(13, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_97:0' shape=(13, 10) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_98:0' shape=(13, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_99:0' shape=(13, 1) dtype=float32&gt;], [&lt;tf.Tensor 'while/Identity_100:0' shape=(12, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_101:0' shape=(12, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_102:0' shape=(12, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_103:0' shape=(12, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_104:0' shape=(12, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_105:0' shape=(1, 20) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_106:0' shape=(12, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_107:0' shape=(12, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_108:0' shape=(12, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_109:0' shape=(12, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_110:0' shape=(12, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_111:0' shape=(12, 10) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_112:0' shape=(12, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_113:0' shape=(12, 1) dtype=float32&gt;]], [&lt;tf.Tensor 'while/Identity_114:0' shape=(1, 20) dtype=float32&gt;], &lt;tf.Tensor 'while/Identity_115:0' shape=(?,) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_116:0' shape=() dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_117:0' shape= dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_118:0' shape= dtype=int32&gt;, &lt;tf.Tensor 'while/Identity_119:0' shape= dtype=int32&gt;]
  
  Second structure (23 elements): 
  [&lt;tf.Tensor 'while/add_21:0' shape=() dtype=int32&gt;, &lt;tf.Tensor 'while/Add:0' shape=() dtype=float32&gt;, [&lt;tf.Tensor 'while/LOL/PerTensor/sub_15:0' shape=(11, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/LOL/PerTensor_1/sub_15:0' shape=(3, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/LOL/PerTensor_2/sub_15:0' shape=(9, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/LOL/PerTensor_3/sub_15:0' shape=(7, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/LOL/PerTensor_4/sub_15:0' shape=(5, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/LOL/PerTensor_5/sub_15:0' shape=(13, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/LOL/PerTensor_6/sub_15:0' shape=(12, 1) dtype=float32&gt;], [&lt;tf.Tensor 'while/LOL/PerTensor/sub_15:0' shape=(11, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/LOL/PerTensor_1/sub_15:0' shape=(3, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/LOL/PerTensor_2/sub_15:0' shape=(9, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/LOL/PerTensor_3/sub_15:0' shape=(7, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/LOL/PerTensor_4/sub_15:0' shape=(5, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/LOL/PerTensor_5/sub_15:0' shape=(13, 1) dtype=float32&gt;, &lt;tf.Tensor 'while/LOL/PerTensor_6/sub_15:0' shape=(12, 1) dtype=float32&gt;], &lt;map object at 0x7f0a9b8f4be0&gt;, [&lt;tf.Tensor 'while/LOL/Layer2_RNN/BiasGRUCell/add:0' shape=(1, 20) dtype=float32&gt;], &lt;tf.Tensor 'while/concat:0' shape=(?,) dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_116:0' shape=() dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_117:0' shape= dtype=float32&gt;, &lt;tf.Tensor 'while/Identity_118:0' shape= dtype=int32&gt;, &lt;tf.Tensor 'while/Identity_119:0' shape= dtype=int32&gt;]
  </code></pre>
  
  <p>I tried following the solution as suggested <a href="https://stackoverflow.com/questions/42776980/valueerror-the-two-structures-dont-have-the-same-number-of-elements">here</a>, but I am not able to figure as to where to make changes in the code. It would be a big help if anyone can guide a way!</p>
  
  <p>Thanks in Advance :)</p>