Chainerで100倍以上の性能比を確認
H.P.C. High Performance ComputingのVisual Technology.inc.は、ディープラーニングフレームワークのひとつである Chinerのサンプルプログラム”mnist”をIBM Power System S822LC for HPC(Minsky) で性能検証を行いました。
P100の単体性能に加えて、CPU⇔GPU、GPU⇔GPUとがNVLink接続された事による相乗効果でCPU比100倍以上の性能比を確認しました。
mnistのサンプルプログラムリスト
※55行目で args.gpu 指定することでGPUで計算されます
1 #!/usr/bin/env python
2 from __future__ import print_function
3 import argparse
4
5 import chainer
6 import chainer.functions as F
7 import chainer.links as L
8 from chainer import training
9 from chainer.training import extensions
10
11
12 # Network definition
13 class MLP(chainer.Chain):
14
15 def __init__(self, n_units, n_out):
16 super(MLP, self).__init__(
17 # the size of the inputs to each layer will be inferred
18 l1=L.Linear(None, n_units), # n_in -> n_units
19 l2=L.Linear(None, n_units), # n_units -> n_units
20 l3=L.Linear(None, n_out), # n_units -> n_out
21 )
22
23 def __call__(self, x):
24 h1 = F.relu(self.l1(x))
25 h2 = F.relu(self.l2(h1))
26 return self.l3(h2)
27
28
29 def main():
30 parser = argparse.ArgumentParser(description=’Chainer example: MNIST’)
31 parser.add_argument(‘–batchsize’, ‘-b’, type=int, default=100,
32 help=’Number of images in each mini-batch’)
33 parser.add_argument(‘–epoch’, ‘-e’, type=int, default=20,
34 help=’Number of sweeps over the dataset to train’)
35 parser.add_argument(‘–gpu’, ‘-g’, type=int, default=-1,
36 help=’GPU ID (negative value indicates CPU)’)
37 parser.add_argument(‘–out’, ‘-o’, default=’result’,
38 help=’Directory to output the result’)
39 parser.add_argument(‘–resume’, ‘-r’, default=”,
40 help=’Resume the training from snapshot’)
41 parser.add_argument(‘–unit’, ‘-u’, type=int, default=1000,
42 help=’Number of units’)
43 args = parser.parse_args()
44
45 print(‘GPU: {}’.format(args.gpu))
46 print(‘# unit: {}’.format(args.unit))
47 print(‘# Minibatch-size: {}’.format(args.batchsize))
48 print(‘# epoch: {}’.format(args.epoch))
49 print(”)
50
51 # Set up a neural network to train
52 # Classifier reports softmax cross entropy loss and accuracy at every
53 # iteration, which will be used by the PrintReport extension below.
54 model = L.Classifier(MLP(args.unit, 10))
55 if args.gpu >= 0:
56 chainer.cuda.get_device(args.gpu).use() # Make a specified GPU current
57 model.to_gpu() # Copy the model to the GPU
58
59 # Setup an optimizer
60 optimizer = chainer.optimizers.Adam()
61 optimizer.setup(model)
62
63 # Load the MNIST dataset
64 train, test = chainer.datasets.get_mnist()
65
66 train_iter = chainer.iterators.SerialIterator(train, args.batchsize)
67 test_iter = chainer.iterators.SerialIterator(test, args.batchsize,
68 repeat=False, shuffle=False)
69
70 # Set up a trainer
71 updater = training.StandardUpdater(train_iter, optimizer, device=args.gpu)
72 trainer = training.Trainer(updater, (args.epoch, ‘epoch’), out=args.out)
73
74 # Evaluate the model with the test dataset for each epoch
75 trainer.extend(extensions.Evaluator(test_iter, model, device=args.gpu))
76
77 # Dump a computational graph from ‘loss’ variable at the first iteration
78 # The “main” refers to the target link of the “main” optimizer.
79 trainer.extend(extensions.dump_graph(‘main/loss’))
80
81 # Take a snapshot at each epoch
82 trainer.extend(extensions.snapshot(), trigger=(args.epoch, ‘epoch’))
83
84 # Write a log of evaluation statistics for each epoch
85 trainer.extend(extensions.LogReport())
86
87 # Save two plot images to the result dir
88 trainer.extend(
89 extensions.PlotReport([‘main/loss’, ‘validation/main/loss’], ‘epoch’,
90 file_name=’loss.png’))
91 trainer.extend(
92 extensions.PlotReport([‘main/accuracy’, ‘validation/main/accuracy’],
93 ‘epoch’, file_name=’accuracy.png’))
94
95 # Print selected entries of the log to stdout
96 # Here “main” refers to the target link of the “main” optimizer again, and
97 # “validation” refers to the default name of the Evaluator extension.
98 # Entries other than ‘epoch’ are reported by the Classifier link, called by
99 # either the updater or the evaluator.
100 trainer.extend(extensions.PrintReport(
101 [‘epoch’, ‘main/loss’, ‘validation/main/loss’,
102 ‘main/accuracy’, ‘validation/main/accuracy’, ‘elapsed_time’]))
103
104 # Print a progress bar to stdout
105 trainer.extend(extensions.ProgressBar())
106
107 if args.resume:
108 # Resume from a snapshot
109 chainer.serializers.load_npz(args.resume, trainer)
110
111 # Run the training
112 trainer.run()
113
114 if __name__ == ‘__main__’:
115 main()
Deep Learning on OpenPOWER Servers
CPU-GPU間およびGPU-GPU間のNVLink接続が以下の諸問題を解決します。
- CPUとGPUの連携による一層の高速化
- CPUシステムメモリの活用によリ、ディープラーニング・モデルのサイズに関する制約の排除
MinskyでのNVLink and P100 GPUの性能効果
CPU-GPU間およびGPU-GPU間のNVLink接続が以下の諸問題を解決します。
- NVLinkの効果で通信時間とオーバーヘッドが大きく減少
- GPU-GPU間のデータ移動、CPU-GPU間のデータ移動が高速化することによる学習時間の大幅短縮
MinskyのCPU-GPU間NVLink接続の効果例
ディープニュラルネットはどんどん大きく、複雑になっており、GPUメモリの容量にすべての必要パラメータを格納することが困難になりつつあります。そのような状況では、CPUメモリを効果的に使用し、より大きなモデルを扱う必要があります。
大きなディープニュラルネットモデルを扱う状況で、MinskyのCPU-GPU間のNVLink接続が大きな効果を発揮します。PCIe接続されたシステムに比べ、1.7倍程度の性能向上を実現します。