We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
bug in tally_parameters
Hi - there's a bug in _tally_parameters because `elif 'decoder' or 'generator' in name:` will always evaluate to True, since a string is True.  I'd submit the fix, but I've already got a fork with some unrelated changes on the file I don't want to submit :)

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `onmt/train_single.py`
Content:
```
1 #!/usr/bin/env python
2 """
3     Training on a single process
4 """
5 
6 import configargparse
7 
8 import os
9 import random
10 import torch
11 
12 import onmt.opts as opts
13 
14 from onmt.inputters.inputter import build_dataset_iter, lazily_load_dataset, \
15     _load_fields, _collect_report_features
16 from onmt.model_builder import build_model
17 from onmt.utils.optimizers import build_optim
18 from onmt.trainer import build_trainer
19 from onmt.models import build_model_saver
20 from onmt.utils.logging import init_logger, logger
21 
22 
23 def _check_save_model_path(opt):
24     save_model_path = os.path.abspath(opt.save_model)
25     model_dirname = os.path.dirname(save_model_path)
26     if not os.path.exists(model_dirname):
27         os.makedirs(model_dirname)
28 
29 
30 def _tally_parameters(model):
31     n_params = sum([p.nelement() for p in model.parameters()])
32     enc = 0
33     dec = 0
34     for name, param in model.named_parameters():
35         if 'encoder' in name:
36             enc += param.nelement()
37         elif 'decoder' or 'generator' in name:
38             dec += param.nelement()
39     return n_params, enc, dec
40 
41 
42 def training_opt_postprocessing(opt, device_id):
43     if opt.word_vec_size != -1:
44         opt.src_word_vec_size = opt.word_vec_size
45         opt.tgt_word_vec_size = opt.word_vec_size
46 
47     if opt.layers != -1:
48         opt.enc_layers = opt.layers
49         opt.dec_layers = opt.layers
50 
51     if opt.rnn_size != -1:
52         opt.enc_rnn_size = opt.rnn_size
53         opt.dec_rnn_size = opt.rnn_size
54         if opt.model_type == 'text' and opt.enc_rnn_size != opt.dec_rnn_size:
55             raise AssertionError("""We do not support different encoder and
56                                  decoder rnn sizes for translation now.""")
57 
58     opt.brnn = (opt.encoder_type == "brnn")
59 
60     if opt.rnn_type == "SRU" and not opt.gpu_ranks:
61         raise AssertionError("Using SRU requires -gpu_ranks set.")
62 
63     if torch.cuda.is_available() and not opt.gpu_ranks:
64         logger.info("WARNING: You have a CUDA device, \
65                     should run with -gpu_ranks")
66 
67     if opt.seed > 0:
68         torch.manual_seed(opt.seed)
69         # this one is needed for torchtext random call (shuffled iterator)
70         # in multi gpu it ensures datasets are read in the same order
71         random.seed(opt.seed)
72         # some cudnn methods can be random even after fixing the seed
73         # unless you tell it to be deterministic
74         torch.backends.cudnn.deterministic = True
75 
76     if device_id >= 0:
77         torch.cuda.set_device(device_id)
78         if opt.seed > 0:
79             # These ensure same initialization in multi gpu mode
80             torch.cuda.manual_seed(opt.seed)
81 
82     return opt
83 
84 
85 def main(opt, device_id):
86     opt = training_opt_postprocessing(opt, device_id)
87     init_logger(opt.log_file)
88     # Load checkpoint if we resume from a previous training.
89     if opt.train_from:
90         logger.info('Loading checkpoint from %s' % opt.train_from)
91         checkpoint = torch.load(opt.train_from,
92                                 map_location=lambda storage, loc: storage)
93 
94         # Load default opts values then overwrite it with opts from
95         # the checkpoint. It's usefull in order to re-train a model
96         # after adding a new option (not set in checkpoint)
97         dummy_parser = configargparse.ArgumentParser()
98         opts.model_opts(dummy_parser)
99         default_opt = dummy_parser.parse_known_args([])[0]
100 
101         model_opt = default_opt
102         model_opt.__dict__.update(checkpoint['opt'].__dict__)
103     else:
104         checkpoint = None
105         model_opt = opt
106 
107     # Peek the first dataset to determine the data_type.
108     # (All datasets have the same data_type).
109     first_dataset = next(lazily_load_dataset("train", opt))
110     data_type = first_dataset.data_type
111 
112     # Load fields generated from preprocess phase.
113     fields = _load_fields(first_dataset, data_type, opt, checkpoint)
114 
115     # Report src/tgt features.
116 
117     src_features, tgt_features = _collect_report_features(fields)
118     for j, feat in enumerate(src_features):
119         logger.info(' * src feature %d size = %d'
120                     % (j, len(fields[feat].vocab)))
121     for j, feat in enumerate(tgt_features):
122         logger.info(' * tgt feature %d size = %d'
123                     % (j, len(fields[feat].vocab)))
124 
125     # Build model.
126     model = build_model(model_opt, opt, fields, checkpoint)
127     n_params, enc, dec = _tally_parameters(model)
128     logger.info('encoder: %d' % enc)
129     logger.info('decoder: %d' % dec)
130     logger.info('* number of parameters: %d' % n_params)
131     _check_save_model_path(opt)
132 
133     # Build optimizer.
134     optim = build_optim(model, opt, checkpoint)
135 
136     # Build model saver
137     model_saver = build_model_saver(model_opt, opt, model, fields, optim)
138 
139     trainer = build_trainer(opt, device_id, model, fields,
140                             optim, data_type, model_saver=model_saver)
141 
142     def train_iter_fct(): return build_dataset_iter(
143         lazily_load_dataset("train", opt), fields, opt)
144 
145     def valid_iter_fct(): return build_dataset_iter(
146         lazily_load_dataset("valid", opt), fields, opt, is_train=False)
147 
148     # Do training.
149     if len(opt.gpu_ranks):
150         logger.info('Starting training on GPU: %s' % opt.gpu_ranks)
151     else:
152         logger.info('Starting training on CPU, could be very slow')
153     trainer.train(train_iter_fct, valid_iter_fct, opt.train_steps,
154                   opt.valid_steps)
155 
156     if opt.tensorboard:
157         trainer.report_manager.tensorboard_writer.close()
158 
159 
160 if __name__ == "__main__":
161     parser = configargparse.ArgumentParser(
162         description='train.py',
163         formatter_class=configargparse.ArgumentDefaultsHelpFormatter)
164 
165     opts.add_md_help_argument(parser)
166     opts.model_opts(parser)
167     opts.train_opts(parser)
168 
169     opt = parser.parse_args()
170     main(opt)
171
```
--- 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/onmt/train_single.py b/onmt/train_single.py
--- a/onmt/train_single.py
+++ b/onmt/train_single.py
@@ -34,7 +34,7 @@
     for name, param in model.named_parameters():
         if 'encoder' in name:
             enc += param.nelement()
-        elif 'decoder' or 'generator' in name:
+        elif ('decoder' or 'generator') in name:
             dec += param.nelement()
     return n_params, enc, dec

{"golden_diff": "diff --git a/onmt/train_single.py b/onmt/train_single.py\n--- a/onmt/train_single.py\n+++ b/onmt/train_single.py\n@@ -34,7 +34,7 @@\n     for name, param in model.named_parameters():\n         if 'encoder' in name:\n             enc += param.nelement()\n-        elif 'decoder' or 'generator' in name:\n+        elif ('decoder' or 'generator') in name:\n             dec += param.nelement()\n     return n_params, enc, dec\n", "issue": "bug in tally_parameters\nHi - there's a bug in _tally_parameters because `elif 'decoder' or 'generator' in name:` will always evaluate to True, since a string is True.  I'd submit the fix, but I've already got a fork with some unrelated changes on the file I don't want to submit :)\n", "before_files": [{"content": "#!/usr/bin/env python\n\"\"\"\n    Training on a single process\n\"\"\"\n\nimport configargparse\n\nimport os\nimport random\nimport torch\n\nimport onmt.opts as opts\n\nfrom onmt.inputters.inputter import build_dataset_iter, lazily_load_dataset, \\\n    _load_fields, _collect_report_features\nfrom onmt.model_builder import build_model\nfrom onmt.utils.optimizers import build_optim\nfrom onmt.trainer import build_trainer\nfrom onmt.models import build_model_saver\nfrom onmt.utils.logging import init_logger, logger\n\n\ndef _check_save_model_path(opt):\n    save_model_path = os.path.abspath(opt.save_model)\n    model_dirname = os.path.dirname(save_model_path)\n    if not os.path.exists(model_dirname):\n        os.makedirs(model_dirname)\n\n\ndef _tally_parameters(model):\n    n_params = sum([p.nelement() for p in model.parameters()])\n    enc = 0\n    dec = 0\n    for name, param in model.named_parameters():\n        if 'encoder' in name:\n            enc += param.nelement()\n        elif 'decoder' or 'generator' in name:\n            dec += param.nelement()\n    return n_params, enc, dec\n\n\ndef training_opt_postprocessing(opt, device_id):\n    if opt.word_vec_size != -1:\n        opt.src_word_vec_size = opt.word_vec_size\n        opt.tgt_word_vec_size = opt.word_vec_size\n\n    if opt.layers != -1:\n        opt.enc_layers = opt.layers\n        opt.dec_layers = opt.layers\n\n    if opt.rnn_size != -1:\n        opt.enc_rnn_size = opt.rnn_size\n        opt.dec_rnn_size = opt.rnn_size\n        if opt.model_type == 'text' and opt.enc_rnn_size != opt.dec_rnn_size:\n            raise AssertionError(\"\"\"We do not support different encoder and\n                                 decoder rnn sizes for translation now.\"\"\")\n\n    opt.brnn = (opt.encoder_type == \"brnn\")\n\n    if opt.rnn_type == \"SRU\" and not opt.gpu_ranks:\n        raise AssertionError(\"Using SRU requires -gpu_ranks set.\")\n\n    if torch.cuda.is_available() and not opt.gpu_ranks:\n        logger.info(\"WARNING: You have a CUDA device, \\\n                    should run with -gpu_ranks\")\n\n    if opt.seed > 0:\n        torch.manual_seed(opt.seed)\n        # this one is needed for torchtext random call (shuffled iterator)\n        # in multi gpu it ensures datasets are read in the same order\n        random.seed(opt.seed)\n        # some cudnn methods can be random even after fixing the seed\n        # unless you tell it to be deterministic\n        torch.backends.cudnn.deterministic = True\n\n    if device_id >= 0:\n        torch.cuda.set_device(device_id)\n        if opt.seed > 0:\n            # These ensure same initialization in multi gpu mode\n            torch.cuda.manual_seed(opt.seed)\n\n    return opt\n\n\ndef main(opt, device_id):\n    opt = training_opt_postprocessing(opt, device_id)\n    init_logger(opt.log_file)\n    # Load checkpoint if we resume from a previous training.\n    if opt.train_from:\n        logger.info('Loading checkpoint from %s' % opt.train_from)\n        checkpoint = torch.load(opt.train_from,\n                                map_location=lambda storage, loc: storage)\n\n        # Load default opts values then overwrite it with opts from\n        # the checkpoint. It's usefull in order to re-train a model\n        # after adding a new option (not set in checkpoint)\n        dummy_parser = configargparse.ArgumentParser()\n        opts.model_opts(dummy_parser)\n        default_opt = dummy_parser.parse_known_args([])[0]\n\n        model_opt = default_opt\n        model_opt.__dict__.update(checkpoint['opt'].__dict__)\n    else:\n        checkpoint = None\n        model_opt = opt\n\n    # Peek the first dataset to determine the data_type.\n    # (All datasets have the same data_type).\n    first_dataset = next(lazily_load_dataset(\"train\", opt))\n    data_type = first_dataset.data_type\n\n    # Load fields generated from preprocess phase.\n    fields = _load_fields(first_dataset, data_type, opt, checkpoint)\n\n    # Report src/tgt features.\n\n    src_features, tgt_features = _collect_report_features(fields)\n    for j, feat in enumerate(src_features):\n        logger.info(' * src feature %d size = %d'\n                    % (j, len(fields[feat].vocab)))\n    for j, feat in enumerate(tgt_features):\n        logger.info(' * tgt feature %d size = %d'\n                    % (j, len(fields[feat].vocab)))\n\n    # Build model.\n    model = build_model(model_opt, opt, fields, checkpoint)\n    n_params, enc, dec = _tally_parameters(model)\n    logger.info('encoder: %d' % enc)\n    logger.info('decoder: %d' % dec)\n    logger.info('* number of parameters: %d' % n_params)\n    _check_save_model_path(opt)\n\n    # Build optimizer.\n    optim = build_optim(model, opt, checkpoint)\n\n    # Build model saver\n    model_saver = build_model_saver(model_opt, opt, model, fields, optim)\n\n    trainer = build_trainer(opt, device_id, model, fields,\n                            optim, data_type, model_saver=model_saver)\n\n    def train_iter_fct(): return build_dataset_iter(\n        lazily_load_dataset(\"train\", opt), fields, opt)\n\n    def valid_iter_fct(): return build_dataset_iter(\n        lazily_load_dataset(\"valid\", opt), fields, opt, is_train=False)\n\n    # Do training.\n    if len(opt.gpu_ranks):\n        logger.info('Starting training on GPU: %s' % opt.gpu_ranks)\n    else:\n        logger.info('Starting training on CPU, could be very slow')\n    trainer.train(train_iter_fct, valid_iter_fct, opt.train_steps,\n                  opt.valid_steps)\n\n    if opt.tensorboard:\n        trainer.report_manager.tensorboard_writer.close()\n\n\nif __name__ == \"__main__\":\n    parser = configargparse.ArgumentParser(\n        description='train.py',\n        formatter_class=configargparse.ArgumentDefaultsHelpFormatter)\n\n    opts.add_md_help_argument(parser)\n    opts.model_opts(parser)\n    opts.train_opts(parser)\n\n    opt = parser.parse_args()\n    main(opt)\n", "path": "onmt/train_single.py"}], "after_files": [{"content": "#!/usr/bin/env python\n\"\"\"\n    Training on a single process\n\"\"\"\n\nimport configargparse\n\nimport os\nimport random\nimport torch\n\nimport onmt.opts as opts\n\nfrom onmt.inputters.inputter import build_dataset_iter, lazily_load_dataset, \\\n    _load_fields, _collect_report_features\nfrom onmt.model_builder import build_model\nfrom onmt.utils.optimizers import build_optim\nfrom onmt.trainer import build_trainer\nfrom onmt.models import build_model_saver\nfrom onmt.utils.logging import init_logger, logger\n\n\ndef _check_save_model_path(opt):\n    save_model_path = os.path.abspath(opt.save_model)\n    model_dirname = os.path.dirname(save_model_path)\n    if not os.path.exists(model_dirname):\n        os.makedirs(model_dirname)\n\n\ndef _tally_parameters(model):\n    n_params = sum([p.nelement() for p in model.parameters()])\n    enc = 0\n    dec = 0\n    for name, param in model.named_parameters():\n        if 'encoder' in name:\n            enc += param.nelement()\n        elif ('decoder' or 'generator') in name:\n            dec += param.nelement()\n    return n_params, enc, dec\n\n\ndef training_opt_postprocessing(opt, device_id):\n    if opt.word_vec_size != -1:\n        opt.src_word_vec_size = opt.word_vec_size\n        opt.tgt_word_vec_size = opt.word_vec_size\n\n    if opt.layers != -1:\n        opt.enc_layers = opt.layers\n        opt.dec_layers = opt.layers\n\n    if opt.rnn_size != -1:\n        opt.enc_rnn_size = opt.rnn_size\n        opt.dec_rnn_size = opt.rnn_size\n        if opt.model_type == 'text' and opt.enc_rnn_size != opt.dec_rnn_size:\n            raise AssertionError(\"\"\"We do not support different encoder and\n                                 decoder rnn sizes for translation now.\"\"\")\n\n    opt.brnn = (opt.encoder_type == \"brnn\")\n\n    if opt.rnn_type == \"SRU\" and not opt.gpu_ranks:\n        raise AssertionError(\"Using SRU requires -gpu_ranks set.\")\n\n    if torch.cuda.is_available() and not opt.gpu_ranks:\n        logger.info(\"WARNING: You have a CUDA device, \\\n                    should run with -gpu_ranks\")\n\n    if opt.seed > 0:\n        torch.manual_seed(opt.seed)\n        # this one is needed for torchtext random call (shuffled iterator)\n        # in multi gpu it ensures datasets are read in the same order\n        random.seed(opt.seed)\n        # some cudnn methods can be random even after fixing the seed\n        # unless you tell it to be deterministic\n        torch.backends.cudnn.deterministic = True\n\n    if device_id >= 0:\n        torch.cuda.set_device(device_id)\n        if opt.seed > 0:\n            # These ensure same initialization in multi gpu mode\n            torch.cuda.manual_seed(opt.seed)\n\n    return opt\n\n\ndef main(opt, device_id):\n    opt = training_opt_postprocessing(opt, device_id)\n    init_logger(opt.log_file)\n    # Load checkpoint if we resume from a previous training.\n    if opt.train_from:\n        logger.info('Loading checkpoint from %s' % opt.train_from)\n        checkpoint = torch.load(opt.train_from,\n                                map_location=lambda storage, loc: storage)\n\n        # Load default opts values then overwrite it with opts from\n        # the checkpoint. It's usefull in order to re-train a model\n        # after adding a new option (not set in checkpoint)\n        dummy_parser = configargparse.ArgumentParser()\n        opts.model_opts(dummy_parser)\n        default_opt = dummy_parser.parse_known_args([])[0]\n\n        model_opt = default_opt\n        model_opt.__dict__.update(checkpoint['opt'].__dict__)\n    else:\n        checkpoint = None\n        model_opt = opt\n\n    # Peek the first dataset to determine the data_type.\n    # (All datasets have the same data_type).\n    first_dataset = next(lazily_load_dataset(\"train\", opt))\n    data_type = first_dataset.data_type\n\n    # Load fields generated from preprocess phase.\n    fields = _load_fields(first_dataset, data_type, opt, checkpoint)\n\n    # Report src/tgt features.\n\n    src_features, tgt_features = _collect_report_features(fields)\n    for j, feat in enumerate(src_features):\n        logger.info(' * src feature %d size = %d'\n                    % (j, len(fields[feat].vocab)))\n    for j, feat in enumerate(tgt_features):\n        logger.info(' * tgt feature %d size = %d'\n                    % (j, len(fields[feat].vocab)))\n\n    # Build model.\n    model = build_model(model_opt, opt, fields, checkpoint)\n    n_params, enc, dec = _tally_parameters(model)\n    logger.info('encoder: %d' % enc)\n    logger.info('decoder: %d' % dec)\n    logger.info('* number of parameters: %d' % n_params)\n    _check_save_model_path(opt)\n\n    # Build optimizer.\n    optim = build_optim(model, opt, checkpoint)\n\n    # Build model saver\n    model_saver = build_model_saver(model_opt, opt, model, fields, optim)\n\n    trainer = build_trainer(opt, device_id, model, fields,\n                            optim, data_type, model_saver=model_saver)\n\n    def train_iter_fct(): return build_dataset_iter(\n        lazily_load_dataset(\"train\", opt), fields, opt)\n\n    def valid_iter_fct(): return build_dataset_iter(\n        lazily_load_dataset(\"valid\", opt), fields, opt, is_train=False)\n\n    # Do training.\n    if len(opt.gpu_ranks):\n        logger.info('Starting training on GPU: %s' % opt.gpu_ranks)\n    else:\n        logger.info('Starting training on CPU, could be very slow')\n    trainer.train(train_iter_fct, valid_iter_fct, opt.train_steps,\n                  opt.valid_steps)\n\n    if opt.tensorboard:\n        trainer.report_manager.tensorboard_writer.close()\n\n\nif __name__ == \"__main__\":\n    parser = configargparse.ArgumentParser(\n        description='train.py',\n        formatter_class=configargparse.ArgumentDefaultsHelpFormatter)\n\n    opts.add_md_help_argument(parser)\n    opts.model_opts(parser)\n    opts.train_opts(parser)\n\n    opt = parser.parse_args()\n    main(opt)\n", "path": "onmt/train_single.py"}]}