基于ZStack構(gòu)建深度學(xué)習(xí)云平臺(tái)
前言
深度學(xué)習(xí)是機(jī)器學(xué)習(xí)和人工智能研究的熱門(mén)分支,也是當(dāng)今最流行的科學(xué)研究趨勢(shì)之一。深度學(xué)習(xí)方法為計(jì)算機(jī)視覺(jué)、機(jī)器學(xué)習(xí)帶來(lái)了革命性的進(jìn)步,而新的深度學(xué)習(xí)技術(shù)也正在不斷誕生。由于深度學(xué)習(xí)正快速發(fā)展,新的研究者很難對(duì)這一技術(shù)實(shí)時(shí)跟進(jìn)。國(guó)內(nèi)各大公有云廠商都提供了相應(yīng)的深度學(xué)習(xí)相關(guān)產(chǎn)品,但對(duì)于初學(xué)者并不那么實(shí)用。本文將介紹基于產(chǎn)品化云平臺(tái)——ZStack,來(lái)構(gòu)建對(duì)初學(xué)者友好、易運(yùn)維、易使用的深度學(xué)習(xí)云平臺(tái)。
由于ZStack的輕量性,我們僅通過(guò)一臺(tái)普通PC機(jī)就能部署云平臺(tái),進(jìn)而實(shí)現(xiàn)深度學(xué)習(xí)平臺(tái)構(gòu)建。讀者可結(jié)合本文輕松擴(kuò)展出規(guī)模更大、功能更為完備的深度學(xué)習(xí)云平臺(tái)。
1 、ZStack簡(jiǎn)介
ZStack是下一代開(kāi)源的云計(jì)算IaaS(基礎(chǔ)架構(gòu)即服務(wù))軟件。它主要面向未來(lái)的智能數(shù)據(jù)中心,通過(guò)提靈活完善的APIs來(lái)管理包括計(jì)算、存儲(chǔ)和網(wǎng)絡(luò)在內(nèi)的數(shù)據(jù)中心資源。用戶可以利用ZStack快速構(gòu)建自己的智能云數(shù)據(jù)中心,也可以在穩(wěn)定的ZStack之上搭建靈活的云應(yīng)用場(chǎng)景。
ZStack功能架構(gòu)
ZStack產(chǎn)品優(yōu)勢(shì):
ZStack是基于專有云平臺(tái)4S(Simple簡(jiǎn)單,Strong健壯,Scalable彈性,Smart智能)標(biāo)準(zhǔn)設(shè)計(jì)的下一代云平臺(tái)IaaS軟件。
1. 簡(jiǎn)單(Simple)
• 簡(jiǎn)單安裝部署:提供安裝文件網(wǎng)絡(luò)下載,30分鐘完成從裸機(jī)到云平臺(tái)的安裝部署。
• 簡(jiǎn)單搭建云平臺(tái):支持云主機(jī)的批量(生成,刪除等)操作,提供列表展示和滑窗詳情。
• 簡(jiǎn)單實(shí)用操作:詳細(xì)的用戶手冊(cè),足量的幫助信息,良好的社區(qū),標(biāo)準(zhǔn)的API提供。
• 友好UI交互:設(shè)計(jì)精良的專業(yè)操作界面,精簡(jiǎn)操作實(shí)現(xiàn)強(qiáng)大的功能。
2. 健壯(Strong)
• 穩(wěn)定且高效的系統(tǒng)架構(gòu)設(shè)計(jì):擁有全異步的后臺(tái)架構(gòu),進(jìn)程內(nèi)微服務(wù)架構(gòu),無(wú)鎖架構(gòu),無(wú)狀態(tài)服務(wù)架構(gòu),一致性哈希環(huán),保證系統(tǒng)架構(gòu)的高效穩(wěn)定。目前已實(shí)現(xiàn):?jiǎn)喂芾砉?jié)點(diǎn)管理上萬(wàn)臺(tái)物理主機(jī)、數(shù)十萬(wàn)臺(tái)云主機(jī);而多個(gè)管理節(jié)點(diǎn)構(gòu)建的集群使用一個(gè)數(shù)據(jù)庫(kù)、一套消息總線可管理十萬(wàn)臺(tái)物理主機(jī)、數(shù)百萬(wàn)臺(tái)云主機(jī)、并發(fā)處理數(shù)萬(wàn)個(gè)API。
• 支撐高并發(fā)的API請(qǐng)求:?jiǎn)蝂Stack管理節(jié)點(diǎn)可以輕松處理每秒上萬(wàn)個(gè)并發(fā)API調(diào)用請(qǐng)求。
• 支持HA的嚴(yán)格要求:在網(wǎng)絡(luò)或節(jié)點(diǎn)失效情況下,業(yè)務(wù)云主機(jī)可自動(dòng)切換到其它健康節(jié)點(diǎn)運(yùn)行;利用管理節(jié)點(diǎn)虛擬化實(shí)現(xiàn)了單管理節(jié)點(diǎn)的高可用,故障時(shí)支持管理節(jié)點(diǎn)動(dòng)態(tài)遷移。
3. 彈性(Scalable)
• 支撐規(guī)模無(wú)限制:?jiǎn)喂芾砉?jié)點(diǎn)可管理從一臺(tái)到上萬(wàn)臺(tái)物理主機(jī),數(shù)十萬(wàn)臺(tái)云主機(jī)。
• 全API交付:ZStack提供了全套IaaS API,用戶可使用這些APIs完成全新跨地域的可用區(qū)域搭建、
網(wǎng)絡(luò)配置變更、以及物理服務(wù)器的升級(jí)。
• 資源可按需調(diào)配:云主機(jī)和云存儲(chǔ)等重要資源可根據(jù)用戶需求進(jìn)行擴(kuò)縮容。ZStack不僅支持對(duì)云主
機(jī)的CPU、內(nèi)存等資源進(jìn)行在線更改,還可對(duì)云主機(jī)的網(wǎng)絡(luò)帶寬、磁盤(pán)帶寬等資源進(jìn)行動(dòng)態(tài)調(diào)整。
4. 智能(Smart)
• 自動(dòng)化運(yùn)維管理:在ZStack環(huán)境里,一切由APIs來(lái)管理。ZStack利用Ansible庫(kù)實(shí)現(xiàn)全自動(dòng)部署和
升級(jí),自動(dòng)探測(cè)和重連,在網(wǎng)絡(luò)抖動(dòng)或物理主機(jī)重啟后能自動(dòng)回連各節(jié)點(diǎn)。其中定時(shí)任務(wù)支持定時(shí)
開(kāi)關(guān)云主機(jī)以及定時(shí)對(duì)云主機(jī)快照等輪詢操作。
• 在線無(wú)縫升級(jí):5分鐘一鍵無(wú)縫升級(jí),用戶只需升級(jí)管控節(jié)點(diǎn)。計(jì)算節(jié)點(diǎn)、存儲(chǔ)節(jié)點(diǎn)、網(wǎng)絡(luò)節(jié)點(diǎn)在
管控軟件啟動(dòng)后自動(dòng)升級(jí)。
• 智能化的UI交互界面:實(shí)時(shí)的資源計(jì)算,避免用戶誤操作。
• 實(shí)時(shí)的全局監(jiān)控:實(shí)時(shí)掌握整個(gè)云平臺(tái)當(dāng)前系統(tǒng)資源的消耗情況,通過(guò)實(shí)時(shí)監(jiān)控,智能化調(diào)配,從
而節(jié)省IT的軟硬件資源。
0x2 構(gòu)建深度學(xué)習(xí)平臺(tái)
2.1 組件部署介紹
- TensorFlow
是一個(gè)開(kāi)放源代碼軟件庫(kù),用于進(jìn)行高性能數(shù)值計(jì)算。借助其靈活的架構(gòu),用戶可以輕松地將計(jì)算工作部署到多種平臺(tái)(CPU、GPU、TPU)和設(shè)備(桌面設(shè)備、服務(wù)器集群、移動(dòng)設(shè)備、邊緣設(shè)備等)。TensorFlow最初是由 Google Brain 團(tuán)隊(duì)中的研究人員和工程師開(kāi)發(fā)的,可為機(jī)器學(xué)習(xí)和深度學(xué)習(xí)提供強(qiáng)力支持,并且其靈活的數(shù)值計(jì)算核心廣泛應(yīng)用于許多其他科學(xué)領(lǐng)域。
- cuDNN
NVIDIA CUDA深層神經(jīng)網(wǎng)絡(luò)庫(kù)(cuDNN)是一種用于深層神經(jīng)網(wǎng)絡(luò)的GPU加速庫(kù)原始圖形。cuDNN為標(biāo)準(zhǔn)例程提供了高度調(diào)優(yōu)的實(shí)現(xiàn),如前向和后向卷積、池化、歸一化和激活層。cuDNN是NVIDIA深度學(xué)習(xí)SDK的一部分。
- TensorBoard
是一個(gè)可視化工具,能夠有效地展示Tensorflow在運(yùn)行過(guò)程中的計(jì)算圖、各種指標(biāo)隨著時(shí)間的變化趨勢(shì)以及訓(xùn)練中使用到的數(shù)據(jù)信息。
- Jupyter
Jupyter是一個(gè)交互式的筆記本,可以很方便地創(chuàng)建和共享文學(xué)化程序文檔,支持實(shí)時(shí)代碼,數(shù)學(xué)方程,可視化和 markdown。一般用與做數(shù)據(jù)清理和轉(zhuǎn)換,數(shù)值模擬,統(tǒng)計(jì)建模,機(jī)器學(xué)習(xí)等等。
2.2 云平臺(tái)環(huán)境準(zhǔn)備
環(huán)境介紹
本次使用如下配置構(gòu)建深度學(xué)習(xí)平臺(tái):
物理服務(wù)器配置 | GPU型號(hào) | 云主機(jī)配置 | 云主機(jī)系統(tǒng) | IP地址 | 主機(jī)名 | |
Intel(R) i5-3470 DDR3 24G |
|
8vCPU16G | CentOS7.4 | 192.168.66.6 | GPU-TF |
本次使用一臺(tái)普通PC機(jī)部署ZStack云平臺(tái),使用云平臺(tái)中GPU透?jìng)鞴δ軐⒁粔KNVIDIA QuadroP2000顯卡透?jìng)鹘o一個(gè)CentOS7.4虛擬機(jī),進(jìn)行平臺(tái)的構(gòu)建。
ZStack云平臺(tái)部署步驟詳情參考官方文檔:https://www.zstack.io/help/product_manuals/user_guide/3.html#c3
2.2.1 創(chuàng)建云主機(jī)
選擇“云資源池”點(diǎn)擊“云主機(jī)”點(diǎn)擊“創(chuàng)建云主機(jī)按鈕”打開(kāi)云主機(jī)創(chuàng)建頁(yè)面;
創(chuàng)建云主機(jī)的步驟:
1、選擇添加方式; 平臺(tái)支持創(chuàng)建單個(gè)云主機(jī)和創(chuàng)建多個(gè)云主機(jī),根據(jù)需求進(jìn)行選擇。
2、設(shè)置云主機(jī)名稱;在設(shè)置名稱時(shí)建議以業(yè)務(wù)系統(tǒng)名稱進(jìn)行命名,方便管理運(yùn)維。
3、選擇計(jì)算規(guī)格;根據(jù)定義的計(jì)算規(guī)格結(jié)合業(yè)務(wù)需求選擇適合的計(jì)算規(guī)格。
4、選擇鏡像模板;根據(jù)業(yè)務(wù)需求選擇相應(yīng)的鏡像模板。
5、選擇三層網(wǎng)絡(luò);在新版本中平臺(tái)三層網(wǎng)絡(luò)同時(shí)支持IPv4和IPv6,請(qǐng)根據(jù)自身業(yè)務(wù)需求進(jìn)行選擇;同時(shí)也可以在創(chuàng)建云主機(jī)過(guò)程中設(shè)置網(wǎng)卡屬性。
6、確認(rèn)配置無(wú)誤后點(diǎn)擊“確定”開(kāi)始創(chuàng)建。
2.2.2 透?jìng)鱃PU操作
點(diǎn)擊云主機(jī)名稱點(diǎn)擊配置信息;
找到GPU設(shè)備標(biāo)簽,點(diǎn)擊操作選擇加載,然后選擇相應(yīng)的GPU設(shè)備給云主機(jī)直接使用。
0x3 開(kāi)始部署
3.1 運(yùn)行環(huán)境準(zhǔn)備
- 安裝pip
- # curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
- # python get-pip.py
- # pip --version
- pip 18.1 from /usr/lib/python2.7/site-packages/pip (python 2.7)
- # python --version
- Python 2.7.5
- 安裝GCC G++
- # yum install gcc gcc-c++
- # gcc --version
- gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36)
- 安裝一些需要的包
- #yum -y install zlib*
- #yum install openssl-devel -y
- #yum install sqlite* -y
- 升級(jí)CentOS默認(rèn)Python2.7.5版本到3.6.5
- 下載Python源碼包
- # wget -c https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz
- 解壓源碼包
- # tar -zvxf Python-3.6.5.tgz
- 進(jìn)入源碼目錄
- # cd Python-3.6.5/
- # ./configure --with-ssl
- 編譯并安裝
- # make && make install
- 查看一下新安裝的python3的文件位置
- # ll /usr/local/bin/python*
|
3.2 安裝CUDA
- 升級(jí)內(nèi)核:
- # rpm -import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
- # rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
- # yum -y --enablerepo=elrepo-kernel install kernel-ml.x86_64 kernel-ml-devel.x86_64
- 查看內(nèi)核版本默認(rèn)啟動(dòng)順序:
- awk -F\' '$1=="menuentry " {print $2}' /etc/grub2.cfg
- CentOS Linux (4.20.0-1.el7.elrepo.x86_64) 7 (Core)
- CentOS Linux (3.10.0-862.el7.x86_64) 7 (Core)
- CentOS Linux (0-rescue-c4581dac5b734c11a1881c8eb10d6b09) 7 (Core)
- #vim /etc/default/grub
- GRUB_DEFAULT=saved 改為GRUB_0=saved
- 運(yùn)行g(shù)rub2-mkconfig命令來(lái)重新創(chuàng)建內(nèi)核配置
- # grub2-mkconfig -o /boot/grub2/grub.cfg
- #reboot
- # uname -r 重啟后驗(yàn)證一下內(nèi)核版本
- 4.20.0-1.el7.elrepo.x86_64
- CUDA Toolkit安裝有兩種方式:
- Package安裝 (RPM and Deb packages)
- Runfile安裝
- 這里選擇使用Runfile模式進(jìn)行安裝
- 安裝包下載:https://developer.nvidia.com/compute/cuda/10.0/Prod/local_installers/cuda_10.0.130_410.48_linux
- 根據(jù)自身操作系統(tǒng)進(jìn)行安裝包篩選,并下載。復(fù)制下載鏈接直接用wget -c命令進(jìn)行下載
- # wget -c https://developer.nvidia.com/compute/cuda/10.0/Prod/local_installers/cuda_10.0.130_410.48_linux
- #chmod +x cuda_10.0.130_410.48_linux
- #./cuda_10.0.130_410.48_linux
- Do you accept the previously read EULA?
- accept/decline/quit: accept
- Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 410.48?
- (y)es/(n)o/(q)uit: y
- Install the CUDA 10.0 Toolkit?
- (y)es/(n)o/(q)uit: y
- Enter Toolkit Location
- [ default is /usr/local/cuda-10.0 ]:
- Do you want to install a symbolic link at /usr/local/cuda?
- (y)es/(n)o/(q)uit: y
- Install the CUDA 10.0 Samples?
- (y)es/(n)o/(q)uit: y
- Enter CUDA Samples Location
- [ default is /root ]:
- 配置CUDA運(yùn)行環(huán)境變量:
- # vim /etc/profile
- # CUDA
- export PATH=/usr/local/cuda-10.0/bin${PATH:+:${PATH}}
- export LD_LIBRARY_PATH=/usr/local/cuda-10.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
- # source /etc/profile
- 檢查版本
- # nvcc --version
- nvcc: NVIDIA (R) Cuda compiler driver
- Copyright (c) 2005-2018 NVIDIA Corporation
- Built on Sat_Aug_25_21:08:01_CDT_2018
- Cuda compilation tools, release 10.0, V10.0.130
- 使用實(shí)例驗(yàn)證測(cè)試CUDA是否正常:
- #cd /root/NVIDIA_CUDA-10.0_Samples/1_Utilities/deviceQuery
- # make
- "/usr/local/cuda-10.0"/bin/nvcc -ccbin g++ -I../../common/inc -m64 -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_37,code=sm_37 -gencode arch=compute_50,code=sm_50 -gencode arch=compute_52,code=sm_52 -gencode arch=compute_60,code=sm_60 -gencode arch=compute_61,code=sm_61 -gencode arch=compute_70,code=sm_70 -gencode arch=compute_75,code=sm_75 -gencode arch=compute_75,code=compute_75 -o deviceQuery.o -c deviceQuery.cpp
- "/usr/local/cuda-10.0"/bin/nvcc -ccbin g++ -m64 -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_37,code=sm_37 -gencode arch=compute_50,code=sm_50 -gencode arch=compute_52,code=sm_52 -gencode arch=compute_60,code=sm_60 -gencode arch=compute_61,code=sm_61 -gencode arch=compute_70,code=sm_70 -gencode arch=compute_75,code=sm_75 -gencode arch=compute_75,code=compute_75 -o deviceQuery deviceQuery.o
- mkdir -p ../../bin/x86_64/linux/release
- cp deviceQuery ../../bin/x86_64/linux/release
- # cd ../../bin/x86_64/linux/release/
- # ./deviceQuery
- #./deviceQuery Starting...
- CUDA Device Query (Runtime API) version (CUDART static linking)
- Detected 1 CUDA Capable device(s)
- Device 0: "Quadro P2000"
- CUDA Driver Version / Runtime Version 10.0 / 10.0
- CUDA Capability Major/Minor version number: 6.1
- Total amount of global memory: 5059 MBytes (5304745984 bytes)
- ( 8) Multiprocessors, (128) CUDA Cores/MP: 1024 CUDA Cores
- GPU Max Clock rate: 1481 MHz (1.48 GHz)
- Memory Clock rate: 3504 Mhz
- Memory Bus Width: 160-bit
- L2 Cache Size: 1310720 bytes
- Maximum Texture Dimension Size (x,y,z) 1D=(131072), 2D=(131072, 65536), 3D=(16384, 16384, 16384)
- Maximum Layered 1D Texture Size, (num) layers 1D=(32768), 2048 layers
- Maximum Layered 2D Texture Size, (num) layers 2D=(32768, 32768), 2048 layers
- Total amount of constant memory: 65536 bytes
- Total amount of shared memory per block: 49152 bytes
- Total number of registers available per block: 65536
- Warp size: 32
- Maximum number of threads per multiprocessor: 2048
- Maximum number of threads per block: 1024
- Max dimension size of a thread block (x,y,z): (1024, 1024, 64)
- Max dimension size of a grid size (x,y,z): (2147483647, 65535, 65535)
- Maximum memory pitch: 2147483647 bytes
- Texture alignment: 512 bytes
- Concurrent copy and kernel execution: Yes with 2 copy engine(s)
- Run time limit on kernels: No
- Integrated GPU sharing Host Memory: No
- Support host page-locked memory mapping: Yes
- Alignment requirement for Surfaces: Yes
- Device has ECC support: Disabled
- Device supports Unified Addressing (UVA): Yes
- Device supports Compute Preemption: Yes
- Supports Cooperative Kernel Launch: Yes
- Supports MultiDevice Co-op Kernel Launch: Yes
- Device PCI Domain ID / Bus ID / location ID: 0 / 0 / 11
- Compute Mode:
- < Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >
- deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 10.0, CUDA Runtime Version = 10.0, NumDevs = 1
- Result = PASS
- Result = PASS且測(cè)試過(guò)程中無(wú)報(bào)錯(cuò),表示測(cè)試通過(guò)!
3.3安裝 cuDNN
cuDNN的全稱為NVIDIA CUDA® Deep Neural Network library,是NVIDIA專門(mén)針對(duì)深度神經(jīng)網(wǎng)絡(luò)(Deep Neural Networks)中的基礎(chǔ)操作而設(shè)計(jì)基于GPU的加速庫(kù)。cuDNN為深度神經(jīng)網(wǎng)絡(luò)中的標(biāo)準(zhǔn)流程提供了高度優(yōu)化的實(shí)現(xiàn)方式。
- 下載安裝包:https://developer.nvidia.com/rdp/cudnn-download
- 注:下載前需先注冊(cè) NVIDIA Developer Program,然后才能下載。
- 可以根據(jù)自身的環(huán)境選擇相應(yīng)版本進(jìn)行下載,這個(gè)有身份驗(yàn)證只能瀏覽器下載然后再上傳到云主機(jī)中。
- 安裝:
- #rpm -ivh libcudnn7-7.4.2.24-1.cuda10.0.x86_64.rpm libcudnn7-devel-7.4.2.24-1.cuda10.0.x86_64.rpm libcudnn7-doc-7.4.2.24-1.cuda10.0.x86_64.rpm
- 準(zhǔn)備中... ################################# [100%]
- 正在升級(jí)/安裝...
- 1:libcudnn7-7.4.2.24-1.cuda10.0 ################################# [ 33%]
- 2:libcudnn7-devel-7.4.2.24-1.cuda10################################# [ 67%]
- 3:libcudnn7-doc-7.4.2.24-1.cuda10.0################################# [100%]
- 驗(yàn)證cuDNN:
- # cp -r /usr/src/cudnn_samples_v7/ $HOME
- # cd $HOME/cudnn_samples_v7/mnistCUDNN
- # make clean && make
- rm -rf *o
- rm -rf mnistCUDNN
- /usr/local/cuda/bin/nvcc -ccbin g++ -I/usr/local/cuda/include -IFreeImage/include -m64 -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_50,code=sm_50 -gencode arch=compute_53,code=sm_53 -gencode arch=compute_53,code=compute_53 -o fp16_dev.o -c fp16_dev.cu
- g++ -I/usr/local/cuda/include -IFreeImage/include -o fp16_emu.o -c fp16_emu.cpp
- g++ -I/usr/local/cuda/include -IFreeImage/include -o mnistCUDNN.o -c mnistCUDNN.cpp
- /usr/local/cuda/bin/nvcc -ccbin g++ -m64 -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_50,code=sm_50 -gencode arch=compute_53,code=sm_53 -gencode arch=compute_53,code=compute_53 -o mnistCUDNN fp16_dev.o fp16_emu.o mnistCUDNN.o -I/usr/local/cuda/include -IFreeImage/include -LFreeImage/lib/linux/x86_64 -LFreeImage/lib/linux -lcudart -lcublas -lcudnn -lfreeimage -lstdc++ -lm
- # ./mnistCUDNN
- cudnnGetVersion() : 7402 , CUDNN_VERSION from cudnn.h : 7402 (7.4.2)
- Host compiler version : GCC 4.8.5
- There are 1 CUDA capable devices on your machine :
- device 0 : sms 8 Capabilities 6.1, SmClock 1480.5 Mhz, MemSize (Mb) 5059, MemClock 3504.0 Mhz, Ecc=0, boardGroupID=0
- Using device 0
- Testing single precision
- Loading image data/one_28x28.pgm
- Performing forward propagation ...
- Testing cudnnGetConvolutionForwardAlgorithm ...
- Fastest algorithm is Algo 1
- Testing cudnnFindConvolutionForwardAlgorithm ...
- ^^^^ CUDNN_STATUS_SUCCESS for Algo 0: 0.036864 time requiring 0 memory
- ^^^^ CUDNN_STATUS_SUCCESS for Algo 1: 0.044032 time requiring 3464 memory
- ^^^^ CUDNN_STATUS_SUCCESS for Algo 2: 0.053248 time requiring 57600 memory
- ^^^^ CUDNN_STATUS_SUCCESS for Algo 4: 0.116544 time requiring 207360 memory
- ^^^^ CUDNN_STATUS_SUCCESS for Algo 7: 0.181248 time requiring 2057744 memory
- Resulting weights from Softmax:
- 0.0000000 0.9999399 0.0000000 0.0000000 0.0000561 0.0000000 0.0000012 0.0000017 0.0000010 0.0000000
- Loading image data/three_28x28.pgm
- Performing forward propagation ...
- Resulting weights from Softmax:
- 0.0000000 0.0000000 0.0000000 0.9999288 0.0000000 0.0000711 0.0000000 0.0000000 0.0000000 0.0000000
- Loading image data/five_28x28.pgm
- Performing forward propagation ...
- Resulting weights from Softmax:
- 0.0000000 0.0000008 0.0000000 0.0000002 0.0000000 0.9999820 0.0000154 0.0000000 0.0000012 0.0000006
- Result of classification: 1 3 5
- Test passed!
- Testing half precision (math in single precision)
- Loading image data/one_28x28.pgm
- Performing forward propagation ...
- Testing cudnnGetConvolutionForwardAlgorithm ...
- Fastest algorithm is Algo 1
- Testing cudnnFindConvolutionForwardAlgorithm ...
- ^^^^ CUDNN_STATUS_SUCCESS for Algo 0: 0.032896 time requiring 0 memory
- ^^^^ CUDNN_STATUS_SUCCESS for Algo 1: 0.036448 time requiring 3464 memory
- ^^^^ CUDNN_STATUS_SUCCESS for Algo 2: 0.044000 time requiring 28800 memory
- ^^^^ CUDNN_STATUS_SUCCESS for Algo 4: 0.115488 time requiring 207360 memory
- ^^^^ CUDNN_STATUS_SUCCESS for Algo 7: 0.180224 time requiring 2057744 memory
- Resulting weights from Softmax:
- 0.0000001 1.0000000 0.0000001 0.0000000 0.0000563 0.0000001 0.0000012 0.0000017 0.0000010 0.0000001
- Loading image data/three_28x28.pgm
- Performing forward propagation ...
- Resulting weights from Softmax:
- 0.0000000 0.0000000 0.0000000 1.0000000 0.0000000 0.0000714 0.0000000 0.0000000 0.0000000 0.0000000
- Loading image data/five_28x28.pgm
- Performing forward propagation ...
- Resulting weights from Softmax:
- 0.0000000 0.0000008 0.0000000 0.0000002 0.0000000 1.0000000 0.0000154 0.0000000 0.0000012 0.0000006
- Result of classification: 1 3 5
- Test passed!
- Test passed!且測(cè)試過(guò)程中無(wú)報(bào)錯(cuò),表示測(cè)試通過(guò)!
3.4安裝 TensorFlow
- # pip3 install --upgrade setuptools==30.1.0
- # pip3 install tf-nightly-gpu
- 驗(yàn)證測(cè)試:
- 在 Python 交互式 shell 中輸入以下幾行簡(jiǎn)短的程序代碼:
- # python
- import tensorflow as tf
- hello = tf.constant('Hello, TensorFlow!')
- sess = tf.Session()
- print(sess.run(hello))
- 如果系統(tǒng)輸出以下內(nèi)容,就說(shuō)明您可以開(kāi)始編寫(xiě) TensorFlow 程序了:
- Hello, TensorFlow!
- 同時(shí)使用nvidia-smi命令可以看到當(dāng)前顯卡的處理任務(wù)。
3.5 安裝TensorBoard 可視化工具
可以用 TensorBoard 來(lái)展現(xiàn) TensorFlow 圖,繪制圖像生成的定量指標(biāo)圖以及顯示附加數(shù)據(jù)(如其中傳遞的圖像)。通過(guò) pip 安裝 TensorFlow 時(shí),也會(huì)自動(dòng)安裝 TensorBoard:
- 驗(yàn)證版本:
- # pip3 show tensorboard
- Name: tensorboard
- Version: 1.12.2
- Summary: TensorBoard lets you watch Tensors Flow
- Home-page: https://github.com/tensorflow/tensorboard
- Author: Google Inc.
- Author-email: opensource@google.com
- License: Apache 2.0
- Location: /usr/lib/python2.7/site-packages
- Requires: protobuf, numpy, futures, grpcio, wheel, markdown, werkzeug, six
- Required-by:
- 啟動(dòng)服務(wù):
- # tensorboard --logdir /var/log/tensorboard.log
- TensorBoard 1.13.0a20190107 at http://GPU-TF:6006 (Press CTRL+C to quit)
- 根據(jù)提示在瀏覽器上輸入http://服務(wù)器IP:6006
3.6 安裝Jupyter
Jupyter是一個(gè)交互式的筆記本,可以很方便地創(chuàng)建和共享文學(xué)化程序文檔,支持實(shí)時(shí)代碼,數(shù)學(xué)方程,可視化和 markdown。一般用與做數(shù)據(jù)清理和轉(zhuǎn)換,數(shù)值模擬,統(tǒng)計(jì)建模,機(jī)器學(xué)習(xí)等等。
- 安裝:
- # sudo pip3 install jupyter
- 生成配置文件:
- # jupyter notebook --generate-config
- Writing default config to: /root/.jupyter/jupyter_notebook_config.py
- 生成Jupyter密碼:
- # python
- Python 3.6.5 (default, Jan 15 2019, 02:51:51)
- [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
- Type "help", "copyright", "credits" or "license" for more information.
- >>> from notebook.auth import passwd;
- >>> passwd()
- Enter password:
- Verify password:
- 'sha1:6067bcf7350b:8407670bb3f94487c9404ed3c20c1ebf7ddee32e'
- >>>
- 將生成的hash串寫(xiě)入Jupyter配置文件:
- # vim /root/.jupyter/jupyter_notebook_config.py
- 啟動(dòng)服務(wù)
- # jupyter notebook --allow-root --ip='192.168.66.11'
- 瀏覽器登陸
- 輸入密碼后登陸:即可正常訪問(wèn)
- 執(zhí)行測(cè)試任務(wù):
- 運(yùn)行TensorFlow Demo示例
- Jupyter中新建 HelloWorld 示例,代碼如下:
- import tensorflow as tf
- # Simple hello world using TensorFlow
- # Create a Constant op
- # The op is added as a node to the default graph.
- #
- # The value returned by the constructor represents the output
- # of the Constant op.
- hello = tf.constant('Hello, TensorFlow!')
- # Start tf session
- sess = tf.Session()
- # Run the op
- print(sess.run(hello))
0x4總結(jié)
通過(guò)使用ZStack云平臺(tái)可以快速構(gòu)建深度學(xué)習(xí)平臺(tái),云平臺(tái)自身無(wú)需太多的復(fù)雜配置,在安裝各種驅(qū)動(dòng)及深度學(xué)習(xí)組件時(shí)也與物理機(jī)無(wú)異。安裝好驅(qū)動(dòng)后進(jìn)行性能測(cè)試發(fā)現(xiàn)與同配置物理邏輯性能相當(dāng),GPU部分沒(méi)有任何性能損失。
當(dāng)上述軟件環(huán)境都準(zhǔn)備完成以后,可配置多塊GPU并從模板創(chuàng)建多個(gè)云主機(jī)一一透?jìng)?,結(jié)合ZStack本身的多租戶屬性,可使得多人在同一套環(huán)境中互不影響進(jìn)行開(kāi)發(fā)或者運(yùn)行應(yīng)用程序,從而成為一個(gè)真正的深度學(xué)習(xí)“云”平臺(tái)。