Azureの小ネタ (改)

~Azureネタを中心に、色々とその他の技術的なことなどを~

Cognitive Toolkit 2.0 の GA とインストール

Cognitive Toolkit 2.0 が GAしました。各種Docsにインストール方法がありますが、微妙にRC版を指してたりするので、要注意です。備忘録変わりにメモっておきますが、数週間後にはここの情報も古くなると思うので、鵜呑みにしないでください。

以下が正式なDocsですが、現時点で更新が追いついていません。

インストール

すべて執筆時点の情報です。またVS2015はインストールされてる前提です。

Python

後のスクリプトインストールで、インストールされますが、自前のPython環境とかあるひとは、注意が必要でしょう。

CUDA

以下からCUDAインストールします。ドライバのバージョン云々の警告が表示されますが、無視して継続します。

nvccでバージョンを確認しておきます。

> nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2016 NVIDIA Corporation
Built on Mon_Jan__9_17:32:33_CST_2017
Cuda compilation tools, release 8.0, V8.0.60

念のためチャント実行できるかサンプル実行してみました。以下に行列積のサンプルぽいのがあるので、

C:\ProgramData\NVIDIA Corporation\CUDA Samples\v8.0\0_Simple\matrixMul

msbuild なりVS2015なりで、ソリューションを開きビルドします。以下のフォルダに移動し、EXEを実行しますと、結果が表示されます。

C:\ProgramData\NVIDIA Corporation\CUDA Samples\v8.0\bin\win64\Debug
> matrixMul.exe
[Matrix Multiply Using CUDA] - Starting...
GPU Device 0: "GeForce GTX 1080 Ti" with compute capability 6.1

MatrixA(320,320), MatrixB(640,320)
Computing result using CUDA Kernel...
done
Performance= 35.58 GFlop/s, Time= 3.684 msec, Size= 131072000 Ops, WorkgroupSize= 1024 threads/block
Checking computed result for correctness: Result = PASS

NOTE: The CUDA Samples are not meant for performance measurements. Results may vary when GPU Boost is enabled.

あんまり性能出てない気がしますが、CUDA Kernelで実行されているようです。

CNTK

以下からバイナリをゲットしてセットアップスクリプトを実行すると楽です。Pythonもインストールしてれます。

github.com

f:id:StateMachine:20170605120358p:plain

v2.0 GPUを選びますと、ライセンスの確認がでてきますので、Acceptして継続するとZIPがダウンロードされます。

f:id:StateMachine:20170605120627p:plain

ZIP を c:\local\CNTK-2-0に展開して、install.batを叩きます。細かなスクリプトオプションは、 Setup Windows binary script options | Microsoft Docs に書かれてます。

> cd c:\local\CNTK-2-0
> cd cntk\Scripts\install\windows
> .\install.bat

CNTK Binary Install Script


This script will setup CNTK, the CNTK prerequisites and the CNTK Python environment onto the system.
More help can be found at:
  https://github.com/Microsoft/CNTK/wiki/Setup-Windows-Binary-Script

The script will analyse your machine and will determine which components are required.
The required components will be downloaded in [C:\local\CNTK-2-0\Scripts\install\windows\ps\InstallCache]
Repeated operation of this script will reuse already downloaded components.

 - If required VS2015 Runtime will be installed
 - If required MSMPI will be installed
 - Anaconda3 will be installed into [C:\local\Anaconda3-4.1.1-Windows-x86_64]
 - A CNTK-PY35 environment will be created or updated in [C:\local\Anaconda3-4.1.1-Windows-x86_64\envs]
 - CNTK will be installed or updated in the CNTK-PY35 environment


1 - I agree and want to continue
Q - Quit the installation process
1

Determining Operations to perform. This will take a moment...

The following operations will be performed:
 * Install Anaconda3-4.1.10
 * Setup CNTK PythonEnvironment 35
 * Setup/Update CNTK Wheel 35
 * Create CNTKPY batch file

Do you want to continue? (y/n)
y

Installing Anaconda3-4.1.1. Please be patient ....
Setup/Update with wheel: https://cntk.ai/PythonWheel/GPU/cntk-2.0-cp35-cp35m-win_amd64.whl. Please be patient....
Collecting cntk==2.0 from https://cntk.ai/PythonWheel/GPU/cntk-2.0-cp35-cp35m-win_amd64.whl
  Downloading https://cntk.ai/PythonWheel/GPU/cntk-2.0-cp35-cp35m-win_amd64.whl (201.2MB)
    100% |################################| 201.2MB 6.8kB/s
Requirement already satisfied (use --upgrade to upgrade): scipy>=0.17 in c:\local\anaconda3-4.1.1-windows-x86_64\envs\cntk-py35\lib\site-packages (from cntk==2.0)
Requirement already satisfied (use --upgrade to upgrade): numpy>=1.11 in c:\local\anaconda3-4.1.1-windows-x86_64\envs\cntk-py35\lib\site-packages (from cntk==2.0)
Installing collected packages: cntk
Successfully installed cntk-2.0
You are using pip version 8.1.2, however version 9.0.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
Install operations finished

CNTK v2 Python install complete.

To activate the CNTK Python environment and set the PATH to include CNTK, start a command shell and run
   C:\local\CNTK-2-0\scripts\cntkpy35.bat

Please checkout tutorials and examples here:
   C:\local\CNTK-2-0\Tutorials
   C:\local\CNTK-2-0\Examples

動作確認

動作確認として、ロジスティク回帰なサンプルを実行してみます。説明はこちら。

CNTK/Tutorials/HelloWorld-LogisticRegression at master · Microsoft/CNTK · GitHub

cd c:\local\CNTK-2-0
cd Tutorials\HelloWorld-LogisticRegression

以下はCPU実行

c:\local\CNTK-2-0\cntk\CNTK.exe configFile=lr_bs.cntk makeMode=false command=Train

以下はGPU実行となります。

c:\local\CNTK-2-0\cntk\CNTK.exe  configFile=lr_bs.cntk  makeMode=false  command=Train  deviceId=auto

まとめ

とどのつまり、全部以下に書いてあります。

Setup CNTK on your machine | Microsoft Docs