We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
polyphony_rnn_train: Incpomatible shapes (InvalidArgumentError)
Hi all,

I was wondering what output would a polyphony_rnn give when trained on some jazzy tunes, so I gathered some midi files from [The Jazz Page](http://www.thejazzpage.de/) and generated dataset, but when attempting to train, I get `Incompatible shapes`:

> InvalidArgumentError (see above for traceback): Incompatible shapes: [27776] vs. [28416]

I am attaching full error traceback [Here](https://gist.github.com/Nimeas/2e8c3cc641c82dc575f39bfe54da6dfc#file-terminal_executions-log), including output from dataset preparation.

I use tensorflow-gpu r0.12 (in order to workaround #538 as suggested by @brannondorsey)

Any hints would be highly appreciated.

Thanks!

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `magenta/models/polyphony_rnn/polyphony_rnn_train.py`
Content:
```
1 # Copyright 2016 Google Inc. All Rights Reserved.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #    http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 """Train and evaluate a polyphony RNN model."""
15 
16 import os
17 
18 # internal imports
19 import tensorflow as tf
20 
21 from magenta.models.polyphony_rnn import polyphony_model
22 from magenta.models.shared import events_rnn_graph
23 from magenta.models.shared import events_rnn_train
24 
25 FLAGS = tf.app.flags.FLAGS
26 tf.app.flags.DEFINE_string('run_dir', '/tmp/polyphony_rnn/logdir/run1',
27                            'Path to the directory where checkpoints and '
28                            'summary events will be saved during training and '
29                            'evaluation. Separate subdirectories for training '
30                            'events and eval events will be created within '
31                            '`run_dir`. Multiple runs can be stored within the '
32                            'parent directory of `run_dir`. Point TensorBoard '
33                            'to the parent directory of `run_dir` to see all '
34                            'your runs.')
35 tf.app.flags.DEFINE_string('config', 'polyphony', 'The config to use')
36 tf.app.flags.DEFINE_string('sequence_example_file', '',
37                            'Path to TFRecord file containing '
38                            'tf.SequenceExample records for training or '
39                            'evaluation.')
40 tf.app.flags.DEFINE_integer('num_training_steps', 0,
41                             'The the number of global training steps your '
42                             'model should take before exiting training. '
43                             'During evaluation, the eval loop will run until '
44                             'the `global_step` Variable of the model being '
45                             'evaluated has reached `num_training_steps`. '
46                             'Leave as 0 to run until terminated manually.')
47 tf.app.flags.DEFINE_integer('summary_frequency', 10,
48                             'A summary statement will be logged every '
49                             '`summary_frequency` steps during training or '
50                             'every `summary_frequency` seconds during '
51                             'evaluation.')
52 tf.app.flags.DEFINE_boolean('eval', False,
53                             'If True, this process only evaluates the model '
54                             'and does not update weights.')
55 tf.app.flags.DEFINE_string('log', 'INFO',
56                            'The threshold for what messages will be logged '
57                            'DEBUG, INFO, WARN, ERROR, or FATAL.')
58 
59 
60 def main(unused_argv):
61   tf.logging.set_verbosity(FLAGS.log)
62 
63   if not FLAGS.run_dir:
64     tf.logging.fatal('--run_dir required')
65     return
66   if not FLAGS.sequence_example_file:
67     tf.logging.fatal('--sequence_example_file required')
68     return
69 
70   sequence_example_file = tf.gfile.Glob(
71       os.path.expanduser(FLAGS.sequence_example_file))
72   run_dir = os.path.expanduser(FLAGS.run_dir)
73 
74   config = polyphony_model.default_configs[FLAGS.config]
75 
76   mode = 'eval' if FLAGS.eval else 'train'
77   graph = events_rnn_graph.build_graph(
78       mode, config, sequence_example_file)
79 
80   train_dir = os.path.join(run_dir, 'train')
81   tf.gfile.MakeDirs(train_dir)
82   tf.logging.info('Train dir: %s', train_dir)
83 
84   if FLAGS.eval:
85     eval_dir = os.path.join(run_dir, 'eval')
86     tf.gfile.MakeDirs(eval_dir)
87     tf.logging.info('Eval dir: %s', eval_dir)
88     events_rnn_train.run_eval(graph, train_dir, eval_dir,
89                               FLAGS.num_training_steps, FLAGS.summary_frequency)
90 
91   else:
92     events_rnn_train.run_training(graph, train_dir, FLAGS.num_training_steps,
93                                   FLAGS.summary_frequency)
94 
95 
96 def console_entry_point():
97   tf.app.run(main)
98 
99 
100 if __name__ == '__main__':
101   console_entry_point()
102
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/magenta/models/polyphony_rnn/polyphony_rnn_train.py b/magenta/models/polyphony_rnn/polyphony_rnn_train.py
--- a/magenta/models/polyphony_rnn/polyphony_rnn_train.py
+++ b/magenta/models/polyphony_rnn/polyphony_rnn_train.py
@@ -55,6 +55,11 @@
 tf.app.flags.DEFINE_string('log', 'INFO',
                            'The threshold for what messages will be logged '
                            'DEBUG, INFO, WARN, ERROR, or FATAL.')
+tf.app.flags.DEFINE_string(
+    'hparams', '{}',
+    'String representation of a Python dictionary containing hyperparameter '
+    'to value mapping. This mapping is merged with the default '
+    'hyperparameters.')
 
 
 def main(unused_argv):
@@ -72,6 +77,7 @@
   run_dir = os.path.expanduser(FLAGS.run_dir)
 
   config = polyphony_model.default_configs[FLAGS.config]
+  config.hparams.parse(FLAGS.hparams)
 
   mode = 'eval' if FLAGS.eval else 'train'
   graph = events_rnn_graph.build_graph(

{"golden_diff": "diff --git a/magenta/models/polyphony_rnn/polyphony_rnn_train.py b/magenta/models/polyphony_rnn/polyphony_rnn_train.py\n--- a/magenta/models/polyphony_rnn/polyphony_rnn_train.py\n+++ b/magenta/models/polyphony_rnn/polyphony_rnn_train.py\n@@ -55,6 +55,11 @@\n tf.app.flags.DEFINE_string('log', 'INFO',\n                            'The threshold for what messages will be logged '\n                            'DEBUG, INFO, WARN, ERROR, or FATAL.')\n+tf.app.flags.DEFINE_string(\n+    'hparams', '{}',\n+    'String representation of a Python dictionary containing hyperparameter '\n+    'to value mapping. This mapping is merged with the default '\n+    'hyperparameters.')\n \n \n def main(unused_argv):\n@@ -72,6 +77,7 @@\n   run_dir = os.path.expanduser(FLAGS.run_dir)\n \n   config = polyphony_model.default_configs[FLAGS.config]\n+  config.hparams.parse(FLAGS.hparams)\n \n   mode = 'eval' if FLAGS.eval else 'train'\n   graph = events_rnn_graph.build_graph(\n", "issue": "polyphony_rnn_train: Incpomatible shapes (InvalidArgumentError)\nHi all,\r\n\r\nI was wondering what output would a polyphony_rnn give when trained on some jazzy tunes, so I gathered some midi files from [The Jazz Page](http://www.thejazzpage.de/) and generated dataset, but when attempting to train, I get `Incompatible shapes`:\r\n\r\n> InvalidArgumentError (see above for traceback): Incompatible shapes: [27776] vs. [28416]\r\n\r\nI am attaching full error traceback [Here](https://gist.github.com/Nimeas/2e8c3cc641c82dc575f39bfe54da6dfc#file-terminal_executions-log), including output from dataset preparation.\r\n\r\nI use tensorflow-gpu r0.12 (in order to workaround #538 as suggested by @brannondorsey)\r\n\r\nAny hints would be highly appreciated.\r\n\r\nThanks!\n", "before_files": [{"content": "# Copyright 2016 Google Inc. All Rights Reserved.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#    http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\"\"\"Train and evaluate a polyphony RNN model.\"\"\"\n\nimport os\n\n# internal imports\nimport tensorflow as tf\n\nfrom magenta.models.polyphony_rnn import polyphony_model\nfrom magenta.models.shared import events_rnn_graph\nfrom magenta.models.shared import events_rnn_train\n\nFLAGS = tf.app.flags.FLAGS\ntf.app.flags.DEFINE_string('run_dir', '/tmp/polyphony_rnn/logdir/run1',\n                           'Path to the directory where checkpoints and '\n                           'summary events will be saved during training and '\n                           'evaluation. Separate subdirectories for training '\n                           'events and eval events will be created within '\n                           '`run_dir`. Multiple runs can be stored within the '\n                           'parent directory of `run_dir`. Point TensorBoard '\n                           'to the parent directory of `run_dir` to see all '\n                           'your runs.')\ntf.app.flags.DEFINE_string('config', 'polyphony', 'The config to use')\ntf.app.flags.DEFINE_string('sequence_example_file', '',\n                           'Path to TFRecord file containing '\n                           'tf.SequenceExample records for training or '\n                           'evaluation.')\ntf.app.flags.DEFINE_integer('num_training_steps', 0,\n                            'The the number of global training steps your '\n                            'model should take before exiting training. '\n                            'During evaluation, the eval loop will run until '\n                            'the `global_step` Variable of the model being '\n                            'evaluated has reached `num_training_steps`. '\n                            'Leave as 0 to run until terminated manually.')\ntf.app.flags.DEFINE_integer('summary_frequency', 10,\n                            'A summary statement will be logged every '\n                            '`summary_frequency` steps during training or '\n                            'every `summary_frequency` seconds during '\n                            'evaluation.')\ntf.app.flags.DEFINE_boolean('eval', False,\n                            'If True, this process only evaluates the model '\n                            'and does not update weights.')\ntf.app.flags.DEFINE_string('log', 'INFO',\n                           'The threshold for what messages will be logged '\n                           'DEBUG, INFO, WARN, ERROR, or FATAL.')\n\n\ndef main(unused_argv):\n  tf.logging.set_verbosity(FLAGS.log)\n\n  if not FLAGS.run_dir:\n    tf.logging.fatal('--run_dir required')\n    return\n  if not FLAGS.sequence_example_file:\n    tf.logging.fatal('--sequence_example_file required')\n    return\n\n  sequence_example_file = tf.gfile.Glob(\n      os.path.expanduser(FLAGS.sequence_example_file))\n  run_dir = os.path.expanduser(FLAGS.run_dir)\n\n  config = polyphony_model.default_configs[FLAGS.config]\n\n  mode = 'eval' if FLAGS.eval else 'train'\n  graph = events_rnn_graph.build_graph(\n      mode, config, sequence_example_file)\n\n  train_dir = os.path.join(run_dir, 'train')\n  tf.gfile.MakeDirs(train_dir)\n  tf.logging.info('Train dir: %s', train_dir)\n\n  if FLAGS.eval:\n    eval_dir = os.path.join(run_dir, 'eval')\n    tf.gfile.MakeDirs(eval_dir)\n    tf.logging.info('Eval dir: %s', eval_dir)\n    events_rnn_train.run_eval(graph, train_dir, eval_dir,\n                              FLAGS.num_training_steps, FLAGS.summary_frequency)\n\n  else:\n    events_rnn_train.run_training(graph, train_dir, FLAGS.num_training_steps,\n                                  FLAGS.summary_frequency)\n\n\ndef console_entry_point():\n  tf.app.run(main)\n\n\nif __name__ == '__main__':\n  console_entry_point()\n", "path": "magenta/models/polyphony_rnn/polyphony_rnn_train.py"}], "after_files": [{"content": "# Copyright 2016 Google Inc. All Rights Reserved.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#    http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\"\"\"Train and evaluate a polyphony RNN model.\"\"\"\n\nimport os\n\n# internal imports\nimport tensorflow as tf\n\nfrom magenta.models.polyphony_rnn import polyphony_model\nfrom magenta.models.shared import events_rnn_graph\nfrom magenta.models.shared import events_rnn_train\n\nFLAGS = tf.app.flags.FLAGS\ntf.app.flags.DEFINE_string('run_dir', '/tmp/polyphony_rnn/logdir/run1',\n                           'Path to the directory where checkpoints and '\n                           'summary events will be saved during training and '\n                           'evaluation. Separate subdirectories for training '\n                           'events and eval events will be created within '\n                           '`run_dir`. Multiple runs can be stored within the '\n                           'parent directory of `run_dir`. Point TensorBoard '\n                           'to the parent directory of `run_dir` to see all '\n                           'your runs.')\ntf.app.flags.DEFINE_string('config', 'polyphony', 'The config to use')\ntf.app.flags.DEFINE_string('sequence_example_file', '',\n                           'Path to TFRecord file containing '\n                           'tf.SequenceExample records for training or '\n                           'evaluation.')\ntf.app.flags.DEFINE_integer('num_training_steps', 0,\n                            'The the number of global training steps your '\n                            'model should take before exiting training. '\n                            'During evaluation, the eval loop will run until '\n                            'the `global_step` Variable of the model being '\n                            'evaluated has reached `num_training_steps`. '\n                            'Leave as 0 to run until terminated manually.')\ntf.app.flags.DEFINE_integer('summary_frequency', 10,\n                            'A summary statement will be logged every '\n                            '`summary_frequency` steps during training or '\n                            'every `summary_frequency` seconds during '\n                            'evaluation.')\ntf.app.flags.DEFINE_boolean('eval', False,\n                            'If True, this process only evaluates the model '\n                            'and does not update weights.')\ntf.app.flags.DEFINE_string('log', 'INFO',\n                           'The threshold for what messages will be logged '\n                           'DEBUG, INFO, WARN, ERROR, or FATAL.')\ntf.app.flags.DEFINE_string(\n    'hparams', '{}',\n    'String representation of a Python dictionary containing hyperparameter '\n    'to value mapping. This mapping is merged with the default '\n    'hyperparameters.')\n\n\ndef main(unused_argv):\n  tf.logging.set_verbosity(FLAGS.log)\n\n  if not FLAGS.run_dir:\n    tf.logging.fatal('--run_dir required')\n    return\n  if not FLAGS.sequence_example_file:\n    tf.logging.fatal('--sequence_example_file required')\n    return\n\n  sequence_example_file = tf.gfile.Glob(\n      os.path.expanduser(FLAGS.sequence_example_file))\n  run_dir = os.path.expanduser(FLAGS.run_dir)\n\n  config = polyphony_model.default_configs[FLAGS.config]\n  config.hparams.parse(FLAGS.hparams)\n\n  mode = 'eval' if FLAGS.eval else 'train'\n  graph = events_rnn_graph.build_graph(\n      mode, config, sequence_example_file)\n\n  train_dir = os.path.join(run_dir, 'train')\n  tf.gfile.MakeDirs(train_dir)\n  tf.logging.info('Train dir: %s', train_dir)\n\n  if FLAGS.eval:\n    eval_dir = os.path.join(run_dir, 'eval')\n    tf.gfile.MakeDirs(eval_dir)\n    tf.logging.info('Eval dir: %s', eval_dir)\n    events_rnn_train.run_eval(graph, train_dir, eval_dir,\n                              FLAGS.num_training_steps, FLAGS.summary_frequency)\n\n  else:\n    events_rnn_train.run_training(graph, train_dir, FLAGS.num_training_steps,\n                                  FLAGS.summary_frequency)\n\n\ndef console_entry_point():\n  tf.app.run(main)\n\n\nif __name__ == '__main__':\n  console_entry_point()\n", "path": "magenta/models/polyphony_rnn/polyphony_rnn_train.py"}]}