|
36 | 36 | parser.add_argument("--epochs", type=int, default=10, help="Corpus iteration num.") |
37 | 37 | parser.add_argument("--batch_size", type=int, default=300, help="The number of sequences contained in a mini-batch.") |
38 | 38 | parser.add_argument("--max_seq_len", type=int, default=64, help="Number of words of the longest seqence.") |
39 | | -parser.add_argument("--n_gpu", type=int, default=1, help="Number of GPUs to use, 0 for CPU.") |
| 39 | +parser.add_argument("--device", default="gpu", type=str, choices=["cpu", "gpu", "xpu"] ,help="The device to select to train the model, is must be cpu/gpu/xpu.") |
40 | 40 | parser.add_argument("--base_lr", type=float, default=0.001, help="The basic learning rate that affects the entire network.") |
41 | 41 | parser.add_argument("--emb_dim", type=int, default=128, help="The dimension in which a word is embedded.") |
42 | 42 | parser.add_argument("--hidden_size", type=int, default=128, help="The number of hidden nodes in the GRU layer.") |
|
46 | 46 |
|
47 | 47 |
|
48 | 48 | def train(args): |
49 | | - paddle.set_device("gpu" if args.n_gpu else "cpu") |
| 49 | + paddle.set_device(args.device) |
50 | 50 |
|
51 | 51 | # Create dataset. |
52 | 52 | train_dataset = LacDataset(args.data_dir, mode='train') |
53 | 53 | test_dataset = LacDataset(args.data_dir, mode='test') |
54 | 54 |
|
55 | 55 | batchify_fn = lambda samples, fn=Tuple( |
56 | | - Pad(axis=0, pad_val=0), # word_ids |
57 | | - Stack(), # length |
58 | | - Pad(axis=0, pad_val=0), # label_ids |
| 56 | + Pad(axis=0, pad_val=0, dtype='int64'), # word_ids |
| 57 | + Stack(dtype='int64'), # length |
| 58 | + Pad(axis=0, pad_val=0, dtype='int64'), # label_ids |
59 | 59 | ): fn(samples) |
60 | 60 |
|
61 | 61 | # Create sampler for dataloader |
@@ -116,7 +116,4 @@ def train(args): |
116 | 116 |
|
117 | 117 | if __name__ == "__main__": |
118 | 118 | args = parser.parse_args() |
119 | | - if args.n_gpu > 1: |
120 | | - paddle.distributed.spawn(train, args=(args, ), nprocs=args.n_gpu) |
121 | | - else: |
122 | | - train(args) |
| 119 | + train(args) |
0 commit comments