Repository: OpenNMT/OpenNMT-py

Issue:
Endless loop when loading dataset
Hi,
I'm a beginner of OpenNMT-py and I also encounter loop on loading training dataset. I have checked Issues 1079 and 1354 but it still not work. My training set is small and I have not use multiple GPU, just one. Please give me some comments, thank you!
My OpenNMT is the latest version and my os is Ubuntu18.04, here is the parameters I used:

python preprocess.py -train_src data/src-train.txt -train_tgt data/tgt-train.txt -valid_src data/src-val.txt -valid_tgt data/tgt-val.txt -save_data data/demo -src_seq_length 1000 -tgt_seq_length 1000 -dynamic_dict -share_vocab

CUDA_VISIBLE_DEVICES=0 python train.py -data data/demo -save_model demo-model -world_size 1 -gpu_ranks 0 -copy_attn
[2019-05-16 16:35:16,797 INFO]  * src vocab size = 988
[2019-05-16 16:35:16,797 INFO]  * tgt vocab size = 988
[2019-05-16 16:35:16,797 INFO] Building model...
[2019-05-16 16:35:19,271 INFO] NMTModel(
  (encoder): RNNEncoder(
    (embeddings): Embeddings(
      (make_embedding): Sequential(
        (emb_luts): Elementwise(
          (0): Embedding(988, 500, padding_idx=1)
        )
      )
    )
    (rnn): LSTM(500, 500, num_layers=2, dropout=0.3)
  )
  (decoder): InputFeedRNNDecoder(
    (embeddings): Embeddings(
      (make_embedding): Sequential(
        (emb_luts): Elementwise(
          (0): Embedding(988, 500, padding_idx=1)
        )
      )
    )
    (dropout): Dropout(p=0.3)
    (rnn): StackedLSTM(
      (dropout): Dropout(p=0.3)
      (layers): ModuleList(
        (0): LSTMCell(1000, 500)
        (1): LSTMCell(500, 500)
      )
    )
    (attn): GlobalAttention(
      (linear_in): Linear(in_features=500, out_features=500, bias=False)
      (linear_out): Linear(in_features=1000, out_features=500, bias=False)
    )
    (copy_attn): GlobalAttention(
      (linear_in): Linear(in_features=500, out_features=500, bias=False)
      (linear_out): Linear(in_features=1000, out_features=500, bias=False)
    )
  )
  (generator): CopyGenerator(
    (linear): Linear(in_features=500, out_features=988, bias=True)
    (linear_copy): Linear(in_features=500, out_features=1, bias=True)
  )
)
[2019-05-16 16:35:19,272 INFO] encoder: 4502000
[2019-05-16 16:35:19,272 INFO] decoder: 7497489
[2019-05-16 16:35:19,272 INFO] * number of parameters: 11999489
[2019-05-16 16:35:19,308 INFO] Starting training on GPU: [0]
[2019-05-16 16:35:19,308 INFO] Start training loop and validate every 10000 steps...
[2019-05-16 16:35:19,330 INFO] Loading dataset from data/demo.train.0.pt, number of examples: 762
[2019-05-16 16:35:19,382 INFO] Loading dataset from data/demo.train.0.pt, number of examples: 762
[2019-05-16 16:35:19,437 INFO] Loading dataset from data/demo.train.0.pt, number of examples: 762
[2019-05-16 16:35:19,498 INFO] Loading dataset from data/demo.train.0.pt, number of examples: 762
[2019-05-16 16:35:19,562 INFO] Loading dataset from data/demo.train.0.pt, number of examples: 762
[2019-05-16 16:35:19,632 INFO] Loading dataset from data/demo.train.0.pt, number of examples: 762
[2019-05-16 16:35:19,705 INFO] Loading dataset from data/demo.train.0.pt, number of examples: 762
[2019-05-16 16:35:19,782 INFO] Loading dataset from data/demo.train.0.pt, number of examples: 762
[2019-05-16 16:35:19,864 INFO] Loading dataset from data/demo.train.0.pt, number of examples: 762
[2019-05-16 16:35:19,950 INFO] Loading dataset from data/demo.train.0.pt, number of examples: 762
[2019-05-16 16:35:20,041 INFO] Loading dataset from data/demo.train.0.pt, number of examples: 762
[2019-05-16 16:35:20,136 INFO] Loading dataset from data/demo.train.0.pt, number of examples: 762
[2019-05-16 16:35:20,235 INFO] Loading dataset from data/demo.train.0.pt, number of examples: 762
[2019-05-16 16:35:20,339 INFO] Loading dataset from data/demo.train.0.pt, number of examples: 762
[2019-05-16 16:35:20,448 INFO] Loading dataset from data/demo.train.0.pt, number of examples: 762
[2019-05-16 16:35:20,560 INFO] Loading dataset from data/demo.train.0.pt, number of examples: 762
[2019-05-16 16:35:20,678 INFO] Loading dataset from data/demo.train.0.pt, number of examples: 762

I have tried using CPU only and default parameters, but this situation also happens. How can I do to solve this problem?





Discussion:

Resolving patch:
diff --git a/onmt/train_single.py b/onmt/train_single.py
--- a/onmt/train_single.py
+++ b/onmt/train_single.py
@@ -99,15 +99,14 @@ def main(opt, device_id):
         opt, device_id, model, fields, optim, model_saver=model_saver)
 
     train_iterables = []
-    for train_id in opt.data_ids:
-        if train_id:
+    if len(opt.data_ids) > 1:
+        for train_id in opt.data_ids:
             shard_base = "train_" + train_id
-        else:
-            shard_base = "train"
-        iterable = build_dataset_iter(shard_base, fields, opt, multi=True)
-        train_iterables.append(iterable)
-
-    train_iter = MultipleDatasetIterator(train_iterables, device_id, opt)
+            iterable = build_dataset_iter(shard_base, fields, opt, multi=True)
+            train_iterables.append(iterable)
+        train_iter = MultipleDatasetIterator(train_iterables, device_id, opt)
+    else:
+        train_iter = build_dataset_iter("train", fields, opt)
 
     valid_iter = build_dataset_iter(
         "valid", fields, opt, is_train=False)


Test patch: