We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
#layers for encoder equals #layers for decoder
I just noticed that for the default RNN encoder, the `enc_layers` parameter is ignored and the number of layers of the encoder is equal to the number of layers of the decoder (see [this line](https://github.com/OpenNMT/OpenNMT-py/blob/master/onmt/ModelConstructor.py#L70)).

Is there some reasoning behind this or is it an error?
#layers for encoder equals #layers for decoder
I just noticed that for the default RNN encoder, the `enc_layers` parameter is ignored and the number of layers of the encoder is equal to the number of layers of the decoder (see [this line](https://github.com/OpenNMT/OpenNMT-py/blob/master/onmt/ModelConstructor.py#L70)).

Is there some reasoning behind this or is it an error?

--- 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/ModelConstructor.py`
Content:
```
1 """
2 This file is for models creation, which consults options
3 and creates each encoder and decoder accordingly.
4 """
5 import torch.nn as nn
6 
7 import onmt
8 import onmt.Models
9 import onmt.modules
10 from onmt.IO import ONMTDataset
11 from onmt.Models import NMTModel, MeanEncoder, RNNEncoder, \
12                         StdRNNDecoder, InputFeedRNNDecoder
13 from onmt.modules import Embeddings, ImageEncoder, CopyGenerator, \
14                          TransformerEncoder, TransformerDecoder, \
15                          CNNEncoder, CNNDecoder
16 
17 
18 def make_embeddings(opt, word_dict, feature_dicts, for_encoder=True):
19     """
20     Make an Embeddings instance.
21     Args:
22         opt: the option in current environment.
23         word_dict(Vocab): words dictionary.
24         feature_dicts([Vocab], optional): a list of feature dictionary.
25         for_encoder(bool): make Embeddings for encoder or decoder?
26     """
27     if for_encoder:
28         embedding_dim = opt.src_word_vec_size
29     else:
30         embedding_dim = opt.tgt_word_vec_size
31 
32     word_padding_idx = word_dict.stoi[onmt.IO.PAD_WORD]
33     num_word_embeddings = len(word_dict)
34 
35     feats_padding_idx = [feat_dict.stoi[onmt.IO.PAD_WORD]
36                          for feat_dict in feature_dicts]
37     num_feat_embeddings = [len(feat_dict) for feat_dict in
38                            feature_dicts]
39 
40     return Embeddings(embedding_dim,
41                       opt.position_encoding,
42                       opt.feat_merge,
43                       opt.feat_vec_exponent,
44                       opt.feat_vec_size,
45                       opt.dropout,
46                       word_padding_idx,
47                       feats_padding_idx,
48                       num_word_embeddings,
49                       num_feat_embeddings)
50 
51 
52 def make_encoder(opt, embeddings):
53     """
54     Various encoder dispatcher function.
55     Args:
56         opt: the option in current environment.
57         embeddings (Embeddings): vocab embeddings for this encoder.
58     """
59     if opt.encoder_type == "transformer":
60         return TransformerEncoder(opt.enc_layers, opt.rnn_size,
61                                   opt.dropout, embeddings)
62     elif opt.encoder_type == "cnn":
63         return CNNEncoder(opt.enc_layers, opt.rnn_size,
64                           opt.cnn_kernel_width,
65                           opt.dropout, embeddings)
66     elif opt.encoder_type == "mean":
67         return MeanEncoder(opt.enc_layers, embeddings)
68     else:
69         # "rnn" or "brnn"
70         return RNNEncoder(opt.rnn_type, opt.brnn, opt.dec_layers,
71                           opt.rnn_size, opt.dropout, embeddings)
72 
73 
74 def make_decoder(opt, embeddings):
75     """
76     Various decoder dispatcher function.
77     Args:
78         opt: the option in current environment.
79         embeddings (Embeddings): vocab embeddings for this decoder.
80     """
81     if opt.decoder_type == "transformer":
82         return TransformerDecoder(opt.dec_layers, opt.rnn_size,
83                                   opt.global_attention, opt.copy_attn,
84                                   opt.dropout, embeddings)
85     elif opt.decoder_type == "cnn":
86         return CNNDecoder(opt.dec_layers, opt.rnn_size,
87                           opt.global_attention, opt.copy_attn,
88                           opt.cnn_kernel_width, opt.dropout,
89                           embeddings)
90     elif opt.input_feed:
91         return InputFeedRNNDecoder(opt.rnn_type, opt.brnn,
92                                    opt.dec_layers, opt.rnn_size,
93                                    opt.global_attention,
94                                    opt.coverage_attn,
95                                    opt.context_gate,
96                                    opt.copy_attn,
97                                    opt.dropout,
98                                    embeddings)
99     else:
100         return StdRNNDecoder(opt.rnn_type, opt.brnn,
101                              opt.dec_layers, opt.rnn_size,
102                              opt.global_attention,
103                              opt.coverage_attn,
104                              opt.context_gate,
105                              opt.copy_attn,
106                              opt.dropout,
107                              embeddings)
108 
109 
110 def make_base_model(model_opt, fields, gpu, checkpoint=None):
111     """
112     Args:
113         model_opt: the option loaded from checkpoint.
114         fields: `Field` objects for the model.
115         gpu(bool): whether to use gpu.
116         checkpoint: the model gnerated by train phase, or a resumed snapshot
117                     model from a stopped training.
118     Returns:
119         the NMTModel.
120     """
121     assert model_opt.model_type in ["text", "img"], \
122         ("Unsupported model type %s" % (model_opt.model_type))
123 
124     # Make encoder.
125     if model_opt.model_type == "text":
126         src_dict = fields["src"].vocab
127         feature_dicts = ONMTDataset.collect_feature_dicts(fields)
128         src_embeddings = make_embeddings(model_opt, src_dict,
129                                          feature_dicts)
130         encoder = make_encoder(model_opt, src_embeddings)
131     else:
132         encoder = ImageEncoder(model_opt.layers,
133                                model_opt.brnn,
134                                model_opt.rnn_size,
135                                model_opt.dropout)
136 
137     # Make decoder.
138     tgt_dict = fields["tgt"].vocab
139     # TODO: prepare for a future where tgt features are possible.
140     feature_dicts = []
141     tgt_embeddings = make_embeddings(model_opt, tgt_dict,
142                                      feature_dicts, for_encoder=False)
143 
144     # Share the embedding matrix - preprocess with share_vocab required
145     if model_opt.share_embeddings:
146         tgt_embeddings.word_lut.weight = src_embeddings.word_lut.weight
147 
148     decoder = make_decoder(model_opt, tgt_embeddings)
149 
150     # Make NMTModel(= encoder + decoder).
151     model = NMTModel(encoder, decoder)
152 
153     # Make Generator.
154     if not model_opt.copy_attn:
155         generator = nn.Sequential(
156             nn.Linear(model_opt.rnn_size, len(fields["tgt"].vocab)),
157             nn.LogSoftmax())
158         if model_opt.share_decoder_embeddings:
159             generator[0].weight = decoder.embeddings.word_lut.weight
160     else:
161         generator = CopyGenerator(model_opt, fields["src"].vocab,
162                                   fields["tgt"].vocab)
163 
164     # Load the model states from checkpoint or initialize them.
165     if checkpoint is not None:
166         print('Loading model parameters.')
167         model.load_state_dict(checkpoint['model'])
168         generator.load_state_dict(checkpoint['generator'])
169     else:
170         if model_opt.param_init != 0.0:
171             print('Intializing model parameters.')
172             for p in model.parameters():
173                 p.data.uniform_(-model_opt.param_init, model_opt.param_init)
174             for p in generator.parameters():
175                 p.data.uniform_(-model_opt.param_init, model_opt.param_init)
176         model.encoder.embeddings.load_pretrained_vectors(
177                 model_opt.pre_word_vecs_enc, model_opt.fix_word_vecs_enc)
178         model.decoder.embeddings.load_pretrained_vectors(
179                 model_opt.pre_word_vecs_dec, model_opt.fix_word_vecs_dec)
180 
181     # Add generator to model (this registers it as parameter of model).
182     model.generator = generator
183 
184     # Make the whole model leverage GPU if indicated to do so.
185     if gpu:
186         model.cuda()
187     else:
188         model.cpu()
189 
190     return model
191
```
--- 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/ModelConstructor.py b/onmt/ModelConstructor.py
--- a/onmt/ModelConstructor.py
+++ b/onmt/ModelConstructor.py
@@ -67,7 +67,7 @@
         return MeanEncoder(opt.enc_layers, embeddings)
     else:
         # "rnn" or "brnn"
-        return RNNEncoder(opt.rnn_type, opt.brnn, opt.dec_layers,
+        return RNNEncoder(opt.rnn_type, opt.brnn, opt.enc_layers,
                           opt.rnn_size, opt.dropout, embeddings)

{"golden_diff": "diff --git a/onmt/ModelConstructor.py b/onmt/ModelConstructor.py\n--- a/onmt/ModelConstructor.py\n+++ b/onmt/ModelConstructor.py\n@@ -67,7 +67,7 @@\n         return MeanEncoder(opt.enc_layers, embeddings)\n     else:\n         # \"rnn\" or \"brnn\"\n-        return RNNEncoder(opt.rnn_type, opt.brnn, opt.dec_layers,\n+        return RNNEncoder(opt.rnn_type, opt.brnn, opt.enc_layers,\n                           opt.rnn_size, opt.dropout, embeddings)\n", "issue": "#layers for encoder equals #layers for decoder\nI just noticed that for the default RNN encoder, the `enc_layers` parameter is ignored and the number of layers of the encoder is equal to the number of layers of the decoder (see [this line](https://github.com/OpenNMT/OpenNMT-py/blob/master/onmt/ModelConstructor.py#L70)).\r\n\r\nIs there some reasoning behind this or is it an error?\n#layers for encoder equals #layers for decoder\nI just noticed that for the default RNN encoder, the `enc_layers` parameter is ignored and the number of layers of the encoder is equal to the number of layers of the decoder (see [this line](https://github.com/OpenNMT/OpenNMT-py/blob/master/onmt/ModelConstructor.py#L70)).\r\n\r\nIs there some reasoning behind this or is it an error?\n", "before_files": [{"content": "\"\"\"\nThis file is for models creation, which consults options\nand creates each encoder and decoder accordingly.\n\"\"\"\nimport torch.nn as nn\n\nimport onmt\nimport onmt.Models\nimport onmt.modules\nfrom onmt.IO import ONMTDataset\nfrom onmt.Models import NMTModel, MeanEncoder, RNNEncoder, \\\n                        StdRNNDecoder, InputFeedRNNDecoder\nfrom onmt.modules import Embeddings, ImageEncoder, CopyGenerator, \\\n                         TransformerEncoder, TransformerDecoder, \\\n                         CNNEncoder, CNNDecoder\n\n\ndef make_embeddings(opt, word_dict, feature_dicts, for_encoder=True):\n    \"\"\"\n    Make an Embeddings instance.\n    Args:\n        opt: the option in current environment.\n        word_dict(Vocab): words dictionary.\n        feature_dicts([Vocab], optional): a list of feature dictionary.\n        for_encoder(bool): make Embeddings for encoder or decoder?\n    \"\"\"\n    if for_encoder:\n        embedding_dim = opt.src_word_vec_size\n    else:\n        embedding_dim = opt.tgt_word_vec_size\n\n    word_padding_idx = word_dict.stoi[onmt.IO.PAD_WORD]\n    num_word_embeddings = len(word_dict)\n\n    feats_padding_idx = [feat_dict.stoi[onmt.IO.PAD_WORD]\n                         for feat_dict in feature_dicts]\n    num_feat_embeddings = [len(feat_dict) for feat_dict in\n                           feature_dicts]\n\n    return Embeddings(embedding_dim,\n                      opt.position_encoding,\n                      opt.feat_merge,\n                      opt.feat_vec_exponent,\n                      opt.feat_vec_size,\n                      opt.dropout,\n                      word_padding_idx,\n                      feats_padding_idx,\n                      num_word_embeddings,\n                      num_feat_embeddings)\n\n\ndef make_encoder(opt, embeddings):\n    \"\"\"\n    Various encoder dispatcher function.\n    Args:\n        opt: the option in current environment.\n        embeddings (Embeddings): vocab embeddings for this encoder.\n    \"\"\"\n    if opt.encoder_type == \"transformer\":\n        return TransformerEncoder(opt.enc_layers, opt.rnn_size,\n                                  opt.dropout, embeddings)\n    elif opt.encoder_type == \"cnn\":\n        return CNNEncoder(opt.enc_layers, opt.rnn_size,\n                          opt.cnn_kernel_width,\n                          opt.dropout, embeddings)\n    elif opt.encoder_type == \"mean\":\n        return MeanEncoder(opt.enc_layers, embeddings)\n    else:\n        # \"rnn\" or \"brnn\"\n        return RNNEncoder(opt.rnn_type, opt.brnn, opt.dec_layers,\n                          opt.rnn_size, opt.dropout, embeddings)\n\n\ndef make_decoder(opt, embeddings):\n    \"\"\"\n    Various decoder dispatcher function.\n    Args:\n        opt: the option in current environment.\n        embeddings (Embeddings): vocab embeddings for this decoder.\n    \"\"\"\n    if opt.decoder_type == \"transformer\":\n        return TransformerDecoder(opt.dec_layers, opt.rnn_size,\n                                  opt.global_attention, opt.copy_attn,\n                                  opt.dropout, embeddings)\n    elif opt.decoder_type == \"cnn\":\n        return CNNDecoder(opt.dec_layers, opt.rnn_size,\n                          opt.global_attention, opt.copy_attn,\n                          opt.cnn_kernel_width, opt.dropout,\n                          embeddings)\n    elif opt.input_feed:\n        return InputFeedRNNDecoder(opt.rnn_type, opt.brnn,\n                                   opt.dec_layers, opt.rnn_size,\n                                   opt.global_attention,\n                                   opt.coverage_attn,\n                                   opt.context_gate,\n                                   opt.copy_attn,\n                                   opt.dropout,\n                                   embeddings)\n    else:\n        return StdRNNDecoder(opt.rnn_type, opt.brnn,\n                             opt.dec_layers, opt.rnn_size,\n                             opt.global_attention,\n                             opt.coverage_attn,\n                             opt.context_gate,\n                             opt.copy_attn,\n                             opt.dropout,\n                             embeddings)\n\n\ndef make_base_model(model_opt, fields, gpu, checkpoint=None):\n    \"\"\"\n    Args:\n        model_opt: the option loaded from checkpoint.\n        fields: `Field` objects for the model.\n        gpu(bool): whether to use gpu.\n        checkpoint: the model gnerated by train phase, or a resumed snapshot\n                    model from a stopped training.\n    Returns:\n        the NMTModel.\n    \"\"\"\n    assert model_opt.model_type in [\"text\", \"img\"], \\\n        (\"Unsupported model type %s\" % (model_opt.model_type))\n\n    # Make encoder.\n    if model_opt.model_type == \"text\":\n        src_dict = fields[\"src\"].vocab\n        feature_dicts = ONMTDataset.collect_feature_dicts(fields)\n        src_embeddings = make_embeddings(model_opt, src_dict,\n                                         feature_dicts)\n        encoder = make_encoder(model_opt, src_embeddings)\n    else:\n        encoder = ImageEncoder(model_opt.layers,\n                               model_opt.brnn,\n                               model_opt.rnn_size,\n                               model_opt.dropout)\n\n    # Make decoder.\n    tgt_dict = fields[\"tgt\"].vocab\n    # TODO: prepare for a future where tgt features are possible.\n    feature_dicts = []\n    tgt_embeddings = make_embeddings(model_opt, tgt_dict,\n                                     feature_dicts, for_encoder=False)\n\n    # Share the embedding matrix - preprocess with share_vocab required\n    if model_opt.share_embeddings:\n        tgt_embeddings.word_lut.weight = src_embeddings.word_lut.weight\n\n    decoder = make_decoder(model_opt, tgt_embeddings)\n\n    # Make NMTModel(= encoder + decoder).\n    model = NMTModel(encoder, decoder)\n\n    # Make Generator.\n    if not model_opt.copy_attn:\n        generator = nn.Sequential(\n            nn.Linear(model_opt.rnn_size, len(fields[\"tgt\"].vocab)),\n            nn.LogSoftmax())\n        if model_opt.share_decoder_embeddings:\n            generator[0].weight = decoder.embeddings.word_lut.weight\n    else:\n        generator = CopyGenerator(model_opt, fields[\"src\"].vocab,\n                                  fields[\"tgt\"].vocab)\n\n    # Load the model states from checkpoint or initialize them.\n    if checkpoint is not None:\n        print('Loading model parameters.')\n        model.load_state_dict(checkpoint['model'])\n        generator.load_state_dict(checkpoint['generator'])\n    else:\n        if model_opt.param_init != 0.0:\n            print('Intializing model parameters.')\n            for p in model.parameters():\n                p.data.uniform_(-model_opt.param_init, model_opt.param_init)\n            for p in generator.parameters():\n                p.data.uniform_(-model_opt.param_init, model_opt.param_init)\n        model.encoder.embeddings.load_pretrained_vectors(\n                model_opt.pre_word_vecs_enc, model_opt.fix_word_vecs_enc)\n        model.decoder.embeddings.load_pretrained_vectors(\n                model_opt.pre_word_vecs_dec, model_opt.fix_word_vecs_dec)\n\n    # Add generator to model (this registers it as parameter of model).\n    model.generator = generator\n\n    # Make the whole model leverage GPU if indicated to do so.\n    if gpu:\n        model.cuda()\n    else:\n        model.cpu()\n\n    return model\n", "path": "onmt/ModelConstructor.py"}], "after_files": [{"content": "\"\"\"\nThis file is for models creation, which consults options\nand creates each encoder and decoder accordingly.\n\"\"\"\nimport torch.nn as nn\n\nimport onmt\nimport onmt.Models\nimport onmt.modules\nfrom onmt.IO import ONMTDataset\nfrom onmt.Models import NMTModel, MeanEncoder, RNNEncoder, \\\n                        StdRNNDecoder, InputFeedRNNDecoder\nfrom onmt.modules import Embeddings, ImageEncoder, CopyGenerator, \\\n                         TransformerEncoder, TransformerDecoder, \\\n                         CNNEncoder, CNNDecoder\n\n\ndef make_embeddings(opt, word_dict, feature_dicts, for_encoder=True):\n    \"\"\"\n    Make an Embeddings instance.\n    Args:\n        opt: the option in current environment.\n        word_dict(Vocab): words dictionary.\n        feature_dicts([Vocab], optional): a list of feature dictionary.\n        for_encoder(bool): make Embeddings for encoder or decoder?\n    \"\"\"\n    if for_encoder:\n        embedding_dim = opt.src_word_vec_size\n    else:\n        embedding_dim = opt.tgt_word_vec_size\n\n    word_padding_idx = word_dict.stoi[onmt.IO.PAD_WORD]\n    num_word_embeddings = len(word_dict)\n\n    feats_padding_idx = [feat_dict.stoi[onmt.IO.PAD_WORD]\n                         for feat_dict in feature_dicts]\n    num_feat_embeddings = [len(feat_dict) for feat_dict in\n                           feature_dicts]\n\n    return Embeddings(embedding_dim,\n                      opt.position_encoding,\n                      opt.feat_merge,\n                      opt.feat_vec_exponent,\n                      opt.feat_vec_size,\n                      opt.dropout,\n                      word_padding_idx,\n                      feats_padding_idx,\n                      num_word_embeddings,\n                      num_feat_embeddings)\n\n\ndef make_encoder(opt, embeddings):\n    \"\"\"\n    Various encoder dispatcher function.\n    Args:\n        opt: the option in current environment.\n        embeddings (Embeddings): vocab embeddings for this encoder.\n    \"\"\"\n    if opt.encoder_type == \"transformer\":\n        return TransformerEncoder(opt.enc_layers, opt.rnn_size,\n                                  opt.dropout, embeddings)\n    elif opt.encoder_type == \"cnn\":\n        return CNNEncoder(opt.enc_layers, opt.rnn_size,\n                          opt.cnn_kernel_width,\n                          opt.dropout, embeddings)\n    elif opt.encoder_type == \"mean\":\n        return MeanEncoder(opt.enc_layers, embeddings)\n    else:\n        # \"rnn\" or \"brnn\"\n        return RNNEncoder(opt.rnn_type, opt.brnn, opt.enc_layers,\n                          opt.rnn_size, opt.dropout, embeddings)\n\n\ndef make_decoder(opt, embeddings):\n    \"\"\"\n    Various decoder dispatcher function.\n    Args:\n        opt: the option in current environment.\n        embeddings (Embeddings): vocab embeddings for this decoder.\n    \"\"\"\n    if opt.decoder_type == \"transformer\":\n        return TransformerDecoder(opt.dec_layers, opt.rnn_size,\n                                  opt.global_attention, opt.copy_attn,\n                                  opt.dropout, embeddings)\n    elif opt.decoder_type == \"cnn\":\n        return CNNDecoder(opt.dec_layers, opt.rnn_size,\n                          opt.global_attention, opt.copy_attn,\n                          opt.cnn_kernel_width, opt.dropout,\n                          embeddings)\n    elif opt.input_feed:\n        return InputFeedRNNDecoder(opt.rnn_type, opt.brnn,\n                                   opt.dec_layers, opt.rnn_size,\n                                   opt.global_attention,\n                                   opt.coverage_attn,\n                                   opt.context_gate,\n                                   opt.copy_attn,\n                                   opt.dropout,\n                                   embeddings)\n    else:\n        return StdRNNDecoder(opt.rnn_type, opt.brnn,\n                             opt.dec_layers, opt.rnn_size,\n                             opt.global_attention,\n                             opt.coverage_attn,\n                             opt.context_gate,\n                             opt.copy_attn,\n                             opt.dropout,\n                             embeddings)\n\n\ndef make_base_model(model_opt, fields, gpu, checkpoint=None):\n    \"\"\"\n    Args:\n        model_opt: the option loaded from checkpoint.\n        fields: `Field` objects for the model.\n        gpu(bool): whether to use gpu.\n        checkpoint: the model gnerated by train phase, or a resumed snapshot\n                    model from a stopped training.\n    Returns:\n        the NMTModel.\n    \"\"\"\n    assert model_opt.model_type in [\"text\", \"img\"], \\\n        (\"Unsupported model type %s\" % (model_opt.model_type))\n\n    # Make encoder.\n    if model_opt.model_type == \"text\":\n        src_dict = fields[\"src\"].vocab\n        feature_dicts = ONMTDataset.collect_feature_dicts(fields)\n        src_embeddings = make_embeddings(model_opt, src_dict,\n                                         feature_dicts)\n        encoder = make_encoder(model_opt, src_embeddings)\n    else:\n        encoder = ImageEncoder(model_opt.layers,\n                               model_opt.brnn,\n                               model_opt.rnn_size,\n                               model_opt.dropout)\n\n    # Make decoder.\n    tgt_dict = fields[\"tgt\"].vocab\n    # TODO: prepare for a future where tgt features are possible.\n    feature_dicts = []\n    tgt_embeddings = make_embeddings(model_opt, tgt_dict,\n                                     feature_dicts, for_encoder=False)\n\n    # Share the embedding matrix - preprocess with share_vocab required\n    if model_opt.share_embeddings:\n        tgt_embeddings.word_lut.weight = src_embeddings.word_lut.weight\n\n    decoder = make_decoder(model_opt, tgt_embeddings)\n\n    # Make NMTModel(= encoder + decoder).\n    model = NMTModel(encoder, decoder)\n\n    # Make Generator.\n    if not model_opt.copy_attn:\n        generator = nn.Sequential(\n            nn.Linear(model_opt.rnn_size, len(fields[\"tgt\"].vocab)),\n            nn.LogSoftmax())\n        if model_opt.share_decoder_embeddings:\n            generator[0].weight = decoder.embeddings.word_lut.weight\n    else:\n        generator = CopyGenerator(model_opt, fields[\"src\"].vocab,\n                                  fields[\"tgt\"].vocab)\n\n    # Load the model states from checkpoint or initialize them.\n    if checkpoint is not None:\n        print('Loading model parameters.')\n        model.load_state_dict(checkpoint['model'])\n        generator.load_state_dict(checkpoint['generator'])\n    else:\n        if model_opt.param_init != 0.0:\n            print('Intializing model parameters.')\n            for p in model.parameters():\n                p.data.uniform_(-model_opt.param_init, model_opt.param_init)\n            for p in generator.parameters():\n                p.data.uniform_(-model_opt.param_init, model_opt.param_init)\n        model.encoder.embeddings.load_pretrained_vectors(\n                model_opt.pre_word_vecs_enc, model_opt.fix_word_vecs_enc)\n        model.decoder.embeddings.load_pretrained_vectors(\n                model_opt.pre_word_vecs_dec, model_opt.fix_word_vecs_dec)\n\n    # Add generator to model (this registers it as parameter of model).\n    model.generator = generator\n\n    # Make the whole model leverage GPU if indicated to do so.\n    if gpu:\n        model.cuda()\n    else:\n        model.cpu()\n\n    return model\n", "path": "onmt/ModelConstructor.py"}]}