prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  使用 generate_sequence_by_rnn_lm 进行train的时候报错
  在 generate_sequence_by_rnn_lm 这个模型下运行 train.py 的时候，当测试文件的路径不存在的时候会报错。错误的原因是把conf写成了config。错误行数是train.py 的112行
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `generate_sequence_by_rnn_lm/train.py`
  Content:
  ```
  1 import os
  2 import sys
  3 import gzip
  4 
  5 import paddle.v2 as paddle
  6 import config as conf
  7 import reader
  8 from network_conf import rnn_lm
  9 from utils import logger, build_dict, load_dict
  10 
  11 
  12 def train(topology,
  13           train_reader,
  14           test_reader,
  15           model_save_dir="models",
  16           num_passes=10):
  17     """
  18     train model.
  19 
  20     :param topology: cost layer of the model to train.
  21     :type topology: LayerOuput
  22     :param train_reader: train data reader.
  23     :type trainer_reader: collections.Iterable
  24     :param test_reader: test data reader.
  25     :type test_reader: collections.Iterable
  26     :param model_save_dir: path to save the trained model
  27     :type model_save_dir: str
  28     :param num_passes: number of epoch
  29     :type num_passes: int
  30     """
  31     if not os.path.exists(model_save_dir):
  32         os.mkdir(model_save_dir)
  33 
  34     # initialize PaddlePaddle
  35     paddle.init(use_gpu=conf.use_gpu, trainer_count=conf.trainer_count)
  36 
  37     # create optimizer
  38     adam_optimizer = paddle.optimizer.Adam(
  39         learning_rate=1e-3,
  40         regularization=paddle.optimizer.L2Regularization(rate=1e-3),
  41         model_average=paddle.optimizer.ModelAverage(
  42             average_window=0.5, max_average_window=10000))
  43 
  44     # create parameters
  45     parameters = paddle.parameters.create(topology)
  46     # create trainer
  47     trainer = paddle.trainer.SGD(
  48         cost=topology, parameters=parameters, update_equation=adam_optimizer)
  49 
  50     # define the event_handler callback
  51     def event_handler(event):
  52         if isinstance(event, paddle.event.EndIteration):
  53             if not event.batch_id % conf.log_period:
  54                 logger.info("Pass %d, Batch %d, Cost %f, %s" % (
  55                     event.pass_id, event.batch_id, event.cost, event.metrics))
  56 
  57             if (not event.batch_id %
  58                     conf.save_period_by_batches) and event.batch_id:
  59                 save_name = os.path.join(model_save_dir,
  60                                          "rnn_lm_pass_%05d_batch_%03d.tar.gz" %
  61                                          (event.pass_id, event.batch_id))
  62                 with gzip.open(save_name, "w") as f:
  63                     trainer.save_parameter_to_tar(f)
  64 
  65         if isinstance(event, paddle.event.EndPass):
  66             if test_reader is not None:
  67                 result = trainer.test(reader=test_reader)
  68                 logger.info("Test with Pass %d, %s" %
  69                             (event.pass_id, result.metrics))
  70             save_name = os.path.join(model_save_dir, "rnn_lm_pass_%05d.tar.gz" %
  71                                      (event.pass_id))
  72             with gzip.open(save_name, "w") as f:
  73                 trainer.save_parameter_to_tar(f)
  74 
  75     logger.info("start training...")
  76     trainer.train(
  77         reader=train_reader, event_handler=event_handler, num_passes=num_passes)
  78 
  79     logger.info("Training is finished.")
  80 
  81 
  82 def main():
  83     # prepare vocab
  84     if not (os.path.exists(conf.vocab_file) and
  85             os.path.getsize(conf.vocab_file)):
  86         logger.info(("word dictionary does not exist, "
  87                      "build it from the training data"))
  88         build_dict(conf.train_file, conf.vocab_file, conf.max_word_num,
  89                    conf.cutoff_word_fre)
  90     logger.info("load word dictionary.")
  91     word_dict = load_dict(conf.vocab_file)
  92     logger.info("dictionay size = %d" % (len(word_dict)))
  93 
  94     cost = rnn_lm(
  95         len(word_dict), conf.emb_dim, conf.hidden_size, conf.stacked_rnn_num,
  96         conf.rnn_type)
  97 
  98     # define reader
  99     reader_args = {
  100         "file_name": conf.train_file,
  101         "word_dict": word_dict,
  102     }
  103     train_reader = paddle.batch(
  104         paddle.reader.shuffle(
  105             reader.rnn_reader(**reader_args), buf_size=102400),
  106         batch_size=conf.batch_size)
  107     test_reader = None
  108     if os.path.exists(conf.test_file) and os.path.getsize(conf.test_file):
  109         test_reader = paddle.batch(
  110             paddle.reader.shuffle(
  111                 reader.rnn_reader(**reader_args), buf_size=65536),
  112             batch_size=config.batch_size)
  113 
  114     train(
  115         topology=cost,
  116         train_reader=train_reader,
  117         test_reader=test_reader,
  118         model_save_dir=conf.model_save_dir,
  119         num_passes=conf.num_passes)
  120 
  121 
  122 if __name__ == "__main__":
  123     main()
  124
  ```
  --- 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()
  
  ```
  
golden_diff: diff --git a/generate_sequence_by_rnn_lm/train.py b/generate_sequence_by_rnn_lm/train.py
  --- a/generate_sequence_by_rnn_lm/train.py
  +++ b/generate_sequence_by_rnn_lm/train.py
  @@ -109,7 +109,7 @@
           test_reader = paddle.batch(
               paddle.reader.shuffle(
                   reader.rnn_reader(**reader_args), buf_size=65536),
  -            batch_size=config.batch_size)
  +            batch_size=conf.batch_size)
   
       train(
           topology=cost,
  
verification_info: {"golden_diff": "diff --git a/generate_sequence_by_rnn_lm/train.py b/generate_sequence_by_rnn_lm/train.py\n--- a/generate_sequence_by_rnn_lm/train.py\n+++ b/generate_sequence_by_rnn_lm/train.py\n@@ -109,7 +109,7 @@\n         test_reader = paddle.batch(\n             paddle.reader.shuffle(\n                 reader.rnn_reader(**reader_args), buf_size=65536),\n-            batch_size=config.batch_size)\n+            batch_size=conf.batch_size)\n \n     train(\n         topology=cost,\n", "issue": "\u4f7f\u7528 generate_sequence_by_rnn_lm \u8fdb\u884ctrain\u7684\u65f6\u5019\u62a5\u9519\n\u5728 generate_sequence_by_rnn_lm \u8fd9\u4e2a\u6a21\u578b\u4e0b\u8fd0\u884c train.py \u7684\u65f6\u5019\uff0c\u5f53\u6d4b\u8bd5\u6587\u4ef6\u7684\u8def\u5f84\u4e0d\u5b58\u5728\u7684\u65f6\u5019\u4f1a\u62a5\u9519\u3002\u9519\u8bef\u7684\u539f\u56e0\u662f\u628aconf\u5199\u6210\u4e86config\u3002\u9519\u8bef\u884c\u6570\u662ftrain.py \u7684112\u884c\n", "before_files": [{"content": "import os\nimport sys\nimport gzip\n\nimport paddle.v2 as paddle\nimport config as conf\nimport reader\nfrom network_conf import rnn_lm\nfrom utils import logger, build_dict, load_dict\n\n\ndef train(topology,\n          train_reader,\n          test_reader,\n          model_save_dir=\"models\",\n          num_passes=10):\n    \"\"\"\n    train model.\n\n    :param topology: cost layer of the model to train.\n    :type topology: LayerOuput\n    :param train_reader: train data reader.\n    :type trainer_reader: collections.Iterable\n    :param test_reader: test data reader.\n    :type test_reader: collections.Iterable\n    :param model_save_dir: path to save the trained model\n    :type model_save_dir: str\n    :param num_passes: number of epoch\n    :type num_passes: int\n    \"\"\"\n    if not os.path.exists(model_save_dir):\n        os.mkdir(model_save_dir)\n\n    # initialize PaddlePaddle\n    paddle.init(use_gpu=conf.use_gpu, trainer_count=conf.trainer_count)\n\n    # create optimizer\n    adam_optimizer = paddle.optimizer.Adam(\n        learning_rate=1e-3,\n        regularization=paddle.optimizer.L2Regularization(rate=1e-3),\n        model_average=paddle.optimizer.ModelAverage(\n            average_window=0.5, max_average_window=10000))\n\n    # create parameters\n    parameters = paddle.parameters.create(topology)\n    # create trainer\n    trainer = paddle.trainer.SGD(\n        cost=topology, parameters=parameters, update_equation=adam_optimizer)\n\n    # define the event_handler callback\n    def event_handler(event):\n        if isinstance(event, paddle.event.EndIteration):\n            if not event.batch_id % conf.log_period:\n                logger.info(\"Pass %d, Batch %d, Cost %f, %s\" % (\n                    event.pass_id, event.batch_id, event.cost, event.metrics))\n\n            if (not event.batch_id %\n                    conf.save_period_by_batches) and event.batch_id:\n                save_name = os.path.join(model_save_dir,\n                                         \"rnn_lm_pass_%05d_batch_%03d.tar.gz\" %\n                                         (event.pass_id, event.batch_id))\n                with gzip.open(save_name, \"w\") as f:\n                    trainer.save_parameter_to_tar(f)\n\n        if isinstance(event, paddle.event.EndPass):\n            if test_reader is not None:\n                result = trainer.test(reader=test_reader)\n                logger.info(\"Test with Pass %d, %s\" %\n                            (event.pass_id, result.metrics))\n            save_name = os.path.join(model_save_dir, \"rnn_lm_pass_%05d.tar.gz\" %\n                                     (event.pass_id))\n            with gzip.open(save_name, \"w\") as f:\n                trainer.save_parameter_to_tar(f)\n\n    logger.info(\"start training...\")\n    trainer.train(\n        reader=train_reader, event_handler=event_handler, num_passes=num_passes)\n\n    logger.info(\"Training is finished.\")\n\n\ndef main():\n    # prepare vocab\n    if not (os.path.exists(conf.vocab_file) and\n            os.path.getsize(conf.vocab_file)):\n        logger.info((\"word dictionary does not exist, \"\n                     \"build it from the training data\"))\n        build_dict(conf.train_file, conf.vocab_file, conf.max_word_num,\n                   conf.cutoff_word_fre)\n    logger.info(\"load word dictionary.\")\n    word_dict = load_dict(conf.vocab_file)\n    logger.info(\"dictionay size = %d\" % (len(word_dict)))\n\n    cost = rnn_lm(\n        len(word_dict), conf.emb_dim, conf.hidden_size, conf.stacked_rnn_num,\n        conf.rnn_type)\n\n    # define reader\n    reader_args = {\n        \"file_name\": conf.train_file,\n        \"word_dict\": word_dict,\n    }\n    train_reader = paddle.batch(\n        paddle.reader.shuffle(\n            reader.rnn_reader(**reader_args), buf_size=102400),\n        batch_size=conf.batch_size)\n    test_reader = None\n    if os.path.exists(conf.test_file) and os.path.getsize(conf.test_file):\n        test_reader = paddle.batch(\n            paddle.reader.shuffle(\n                reader.rnn_reader(**reader_args), buf_size=65536),\n            batch_size=config.batch_size)\n\n    train(\n        topology=cost,\n        train_reader=train_reader,\n        test_reader=test_reader,\n        model_save_dir=conf.model_save_dir,\n        num_passes=conf.num_passes)\n\n\nif __name__ == \"__main__\":\n    main()\n", "path": "generate_sequence_by_rnn_lm/train.py"}], "after_files": [{"content": "import os\nimport sys\nimport gzip\n\nimport paddle.v2 as paddle\nimport config as conf\nimport reader\nfrom network_conf import rnn_lm\nfrom utils import logger, build_dict, load_dict\n\n\ndef train(topology,\n          train_reader,\n          test_reader,\n          model_save_dir=\"models\",\n          num_passes=10):\n    \"\"\"\n    train model.\n\n    :param topology: cost layer of the model to train.\n    :type topology: LayerOuput\n    :param train_reader: train data reader.\n    :type trainer_reader: collections.Iterable\n    :param test_reader: test data reader.\n    :type test_reader: collections.Iterable\n    :param model_save_dir: path to save the trained model\n    :type model_save_dir: str\n    :param num_passes: number of epoch\n    :type num_passes: int\n    \"\"\"\n    if not os.path.exists(model_save_dir):\n        os.mkdir(model_save_dir)\n\n    # initialize PaddlePaddle\n    paddle.init(use_gpu=conf.use_gpu, trainer_count=conf.trainer_count)\n\n    # create optimizer\n    adam_optimizer = paddle.optimizer.Adam(\n        learning_rate=1e-3,\n        regularization=paddle.optimizer.L2Regularization(rate=1e-3),\n        model_average=paddle.optimizer.ModelAverage(\n            average_window=0.5, max_average_window=10000))\n\n    # create parameters\n    parameters = paddle.parameters.create(topology)\n    # create trainer\n    trainer = paddle.trainer.SGD(\n        cost=topology, parameters=parameters, update_equation=adam_optimizer)\n\n    # define the event_handler callback\n    def event_handler(event):\n        if isinstance(event, paddle.event.EndIteration):\n            if not event.batch_id % conf.log_period:\n                logger.info(\"Pass %d, Batch %d, Cost %f, %s\" % (\n                    event.pass_id, event.batch_id, event.cost, event.metrics))\n\n            if (not event.batch_id %\n                    conf.save_period_by_batches) and event.batch_id:\n                save_name = os.path.join(model_save_dir,\n                                         \"rnn_lm_pass_%05d_batch_%03d.tar.gz\" %\n                                         (event.pass_id, event.batch_id))\n                with gzip.open(save_name, \"w\") as f:\n                    trainer.save_parameter_to_tar(f)\n\n        if isinstance(event, paddle.event.EndPass):\n            if test_reader is not None:\n                result = trainer.test(reader=test_reader)\n                logger.info(\"Test with Pass %d, %s\" %\n                            (event.pass_id, result.metrics))\n            save_name = os.path.join(model_save_dir, \"rnn_lm_pass_%05d.tar.gz\" %\n                                     (event.pass_id))\n            with gzip.open(save_name, \"w\") as f:\n                trainer.save_parameter_to_tar(f)\n\n    logger.info(\"start training...\")\n    trainer.train(\n        reader=train_reader, event_handler=event_handler, num_passes=num_passes)\n\n    logger.info(\"Training is finished.\")\n\n\ndef main():\n    # prepare vocab\n    if not (os.path.exists(conf.vocab_file) and\n            os.path.getsize(conf.vocab_file)):\n        logger.info((\"word dictionary does not exist, \"\n                     \"build it from the training data\"))\n        build_dict(conf.train_file, conf.vocab_file, conf.max_word_num,\n                   conf.cutoff_word_fre)\n    logger.info(\"load word dictionary.\")\n    word_dict = load_dict(conf.vocab_file)\n    logger.info(\"dictionay size = %d\" % (len(word_dict)))\n\n    cost = rnn_lm(\n        len(word_dict), conf.emb_dim, conf.hidden_size, conf.stacked_rnn_num,\n        conf.rnn_type)\n\n    # define reader\n    reader_args = {\n        \"file_name\": conf.train_file,\n        \"word_dict\": word_dict,\n    }\n    train_reader = paddle.batch(\n        paddle.reader.shuffle(\n            reader.rnn_reader(**reader_args), buf_size=102400),\n        batch_size=conf.batch_size)\n    test_reader = None\n    if os.path.exists(conf.test_file) and os.path.getsize(conf.test_file):\n        test_reader = paddle.batch(\n            paddle.reader.shuffle(\n                reader.rnn_reader(**reader_args), buf_size=65536),\n            batch_size=conf.batch_size)\n\n    train(\n        topology=cost,\n        train_reader=train_reader,\n        test_reader=test_reader,\n        model_save_dir=conf.model_save_dir,\n        num_passes=conf.num_passes)\n\n\nif __name__ == \"__main__\":\n    main()\n", "path": "generate_sequence_by_rnn_lm/train.py"}]}