ï¼å¤ãè¨äºï¼EC2ã®GPUã¤ã³ã¹ã¿ã³ã¹ã«Chainerã5è¡ã§å ¥ãã¦4è¡ã§åãã
PFI/PFN社ã§ãªã¼ãã³ã½ã¼ã¹å ¬éãããã£ã¼ãã©ã¼ãã³ã°ãã¬ã¼ã ã¯ã¼ã¯Chainerããã§ä½¿ã£ã¦é ãã¦ããæ¹ããããã¨ããããã¾ãã
ãã¦ãããªChainerã§ãããMacBookã§ãç°¡åã«ä½¿ãå§ãããã¨ã¯ã§ãã¾ãããç価ãçºæ®ãããã«ã¯GPUç°å¢ã欲ããã¨ããã§ããã¾ãä¸æ¹ãGPUãç©ãã ãã¹ã¯ãããPCã§ãï¼ç¹ã«PyCUDAã®ï¼ã¤ã³ã¹ãã¼ã«ã§ã¤ã¾ã¥ãæ¹ãããã®ãäºå®ã§ãã
éçºå´ã®äººéã¨ãã¦ã¯ãã§ããã°æ軽ã«è©¦ãã¦ããããç°å¢ãæä¾ããããããã§ã¯ããã¯ãAWSã®EC2ã§GPUã¤ã³ã¹ã¿ã³ã¹ä½¿ãã®ãä¸çªããã¨æãã¾ã*1ã
Chainer on EC2ã¯ä½åãããã°çã§è¨äºãå ¬éããã¦ãã¾ãããä»ã®ã¨ããæãç°¡åãªæ¹æ³ã¯Ryosuke Tajimaããã®AWSでサクッとChainerを使ってみるã§ãã
ãããã¯ãããã§ãPyCUDAãã½ã¼ã¹ããã®ãã«ããã¦ããããã¨ã«ãªã£ã¦ãã¾ããåå ã¯ãsudoå®è¡ã«ããã¦å¤ãã®ç°å¢ã§ã¯$PATHãä¸æ¸ãããããããCUDAã®ã¤ã³ã¹ãã¼ã«ãã£ã¬ã¯ããªã«PATHãéããPyCUDAã®ãã«ãã失æãããã¨ã«ããã¾ãã
ããã¯ãæè¿å ¬å¼ããã¥ã¡ã³ãã®Tipsにも加えられたããã«ãã¦ã¼ã¶ã¼ã®ãã¼ã ãã£ã¬ã¯ããªä»¥ä¸ã«ã¤ã³ã¹ãã¼ã«ãããªãã·ã§ã³ãpipã«ã¤ãããã$PATHãsudoç°å¢ã«æ示çã«æ¸¡ããã¨ã§åé¿ã§ãã¾ãã
ããã§ãã®è¨äºã§ã¯ãæçã§EC2ã«Chainerç°å¢ãç¨æããæ§åããè¦ããããã¨æãã¾ãã
ã¾ããTajimaããã¨åæ§ã«こちらの記事ãåèã«ãNVIDIAãå ¬éãã¦ããCUDAç°å¢å ¥ãGPUã¤ã³ã¹ã¿ã³ã¹ï¼Amazon Linuxãã¼ã¹ï¼ãAWS Marketplaceããæ¢ãã¦ç«ã¡ä¸ãã¾ãã
ã¤ã³ã¹ã¿ã³ã¹ãèµ·åãããec2-userã¨ãã¦ãã°ã¤ã³ãã¦ãã¾ãCUDAã¤ã³ã¹ãã¼ã«ãã£ã¬ã¯ããªã«é¢ããè¨å®ã.bash_profileã«è¿½è¨ãã¦åæ ãã¾ãï¼ããã¾ã§ã§3è¡ï¼ã
$ echo 'export PATH=/opt/nvidia/cuda/bin:$PATH' >> .bash_profile $ echo 'export LD_LIBRARY_PATH=/opt/nvidia/cuda/lib64:$LD_LIBRARY_PATH' >> .bash_profile $ source .bash_profile
次ã«chainerã--userãªãã·ã§ã³ä»ãã§ã¤ã³ã¹ãã¼ã«ãã¾ãï¼4è¡ç®ï¼ãnumpyã®ã¤ã³ã¹ãã¼ã«ã«å°ãæéããããã®ã§æ°åå¾
ã¡ã¾ãã
$ pip install --user chainer
ï¼ä¸ç¥ï¼
ããã§ãchaineræ¬ä½ã¨numpyãsixãªã©ã¯ã¤ã³ã¹ãã¼ã«ã§ãã¾ãããCPUã¢ã¼ãã§ããã°ããå®è¡ã§ãã¾ãããããã¯ç½®ãã¨ãã¦ãããããé£é¢ã®GPU対å¿ã«ç§»ãã¾ãã
ä¸è¨ã®ããã«ã--userä»ãã§è©¦ãã¦ã¿ã¾ãï¼5è¡ç®ï¼ã
$ pip install --user --upgrade chainer-cuda-deps
ï¼ä¸ç¥ï¼nvcc no in pathã¨ããã¨ã©ã¼ã¯åºã¦ãã¾ããï¼
ï¼ä¸ç¥ï¼ããã§ãå°ãæéããããã¾ãï¼
ããï¼ï¼ããã¨ãããï¼PyCUDAå«ãã¦ã¤ã³ã¹ãã¼ã«ã«æåããããã§ãã
ã§ã¯æ¬å½ã«åãã®ãã©ãããMNISTãµã³ãã«ãå®è¡ãã¦ã¿ã¾ãããï¼3è¡æ¶è²»ï¼ãGithubãã最新リリースのSource code (tar.gz)ããã¦ã³ãã¼ããã¾ãã以ä¸ã§ã¯å·çæç¹ï¼2015/08/09ï¼ã®ææ°çã»Chainer v1.1.2ãå©ç¨ãã¦ãã¾ããããã¼ã¸ã§ã³çªå·ã¯èªã¿æ¿ãã¦ãã ããã
$ wget https://github.com/pfnet/chainer/archive/v1.1.2.tar.gz $ tar zxvf v1.1.2.tar.gz $ cd chainer-1.1.2/examples/mnist/
ï¼ä¸ç¥ï¼
ã§ã¯GPUå®è¡ãªãã·ã§ã³ãä»ãã¦åããã¾ãï¼ã©ã¹ã1è¡ï¼ã
$ python train_mnist.py --gpu 0
ï¼ä¸ç¥ï¼MNISTãã¼ã¿ã»ããã®å¤æã«å°ãæéããããã¾ãï¼
ç¡äºã«MNISTãµã³ãã«ã®å®è¡ãå®äºãã精度ãåºã¦ããããã§ãï¼ç´98.5%ï¼
ã¾ã¨ããã¨ãEC2ã®NVIDIA製AMIãGPUã¤ã³ã¹ã¿ã³ã¹ã§ä½¿ãã°ã以ä¸ã®5è¡ï¼4è¡ãå®è¡ãããã¨ã§ãChainerã®GPUå©ç¨ãå¯è½ãªç°å¢ãã©ãªãã§ãæã«å ¥ãã¾ããæéã«ããã¨ãã¤ã³ã¹ã¿ã³ã¹ç«ã¡ä¸ããã10-15åç¨åº¦ã§ããã¾ã§ãã©ãçããã¨æãã¾ãã
$ echo 'export PATH=/opt/nvidia/cuda/bin:$PATH' >> .bash_profile $ echo 'export LD_LIBRARY_PATH=/opt/nvidia/cuda/lib64:$LD_LIBRARY_PATH' >> .bash_profile $ source .bash_profile $ pip install --user chainer $ pip install --user --upgrade chainer-cuda-deps --- $ wget https://github.com/pfnet/chainer/archive/v1.1.2.tar.gz $ tar zxvf v1.1.2.tar.gz $ cd chainer-1.1.2/examples/mnist/ $ python train_mnist.py --gpu 0
ãããç®åãã«ãã¦ããã²ãèªåã®ç 究ãä»äºã趣å³ã§Chainerããæ´»ç¨ä¸ããã
ããã§ã¯ãHave a happy Chainer life!
⻠念ã®ãããä¸è¨NVIDIA製AMIã¯ç¡æã§ãããEC2ã¤ã³ã¹ã¿ã³ã¹ã®å©ç¨ã«ã¯å¥éæéããããã¾ããèªå·±è²¬ä»»ã§ãé¡ããã¾ãã
*1:ãå ¬å¼ã®AMIå ¬éããã°ããã®ã§ã¯ãã¨ãã声ãããããã§ããã2é±éãã¨ã«ãã¼ã¸ã§ã³ã¢ããããç¾ç¶ã§ã¯ã¡ã³ããé£ããã¨ããäºæ ãããã¾ã