爆速でAzure linux GPU環境を構築する方法

スポンサードリンク



こんにちは。sinyです。

本記事では、Azure上にディープラーニング学習用のGPU環境を構築する簡単な方法をご紹介します。

Azure Data Science Virtual Machine(DSVM)とは?

Azure Data Science Virtual Machine(略してDSVM)はAzure で使用できる仮想マシン イメージで、データ分析や機械学習(ディープラーニング)で一般的に使われるツール群がプレインストールされているため、細かい環境構築をすることなくVMを立ち上げるだけですぐに目的の作業が開始できるので大変便利です。

DSVMには3種類の環境が準備されています。(2019年12月12日現在)

DSVMのOS環境
  • Windows Server 2016
  • Ubuntu 16.04 LTS
  • CentOS 7.4

また、DSVMには様々なツールが標準搭載されています。

代表的なところをあげると、以下のようなものが標準搭載されています。

DSVM 上で使用できるツール
  • Microsoft Machine Learning Server
  • Anaconda Python 2.7 および 3.5
  • WindowsではMS Office ProPlus(Excel,Word,PowerPoint)が付属。
  • SQL Server 2017
  • Jupyter Notebook Server
  • Visual Studio Code
  • PyCharm Community Edition

他にもいろいろなツールが利用できますが、詳細は以下を参照。

OSの種類によってできることが多少異なるようです。(以下を参照)

DSVM環境の構築方法

DSVMでGPU環境を構築する方法はとてもシンプルで簡単です。

大きくやり方は2種類あります。

  1. AzurePortal上でマウスクリックで作成
  2. コマンドラインで作成(Azure CLIなど)

 

AzurePortal上でマウスクリックで作成

 

AzurePortalにアクセスし検索欄で「data science virtual machine」と入力して仮想マシンの一覧を検索し、"Data Science Virtual Machine for Linux (Ubuntu)" を選択します

Data Science Virtual Machine for Linux(Ubuntu)の画面が表示されたら「作成」ボタンを押しましょう。

いくつか設定項目がありますが、最小限の設定だけ指定します。

  • リソースグループ…必須
  • 仮想マシン名…任意の名称
  • 地域…任意(今回は(アジア太平洋) 東日本を選択)
  • サイズ…VMのスペックを指定
  • 認証の種類(パスワード方式 or ssh方式)

リソースグループは必ず指定する必要があるため、既存のグループを指定するか、まだ存在していない場合は新規に作成します。
仮想マシンと地域は適宜指定します。

次にサイズの部分ですがデフォルトでは「Standard DS3 v2 4 vcpu 数、14 GiB のメモリ (¥34,081/月)」となっているので、GPU環境を利用したい場合はここでスペックを変更します。

サイズを変更します」ボタンを押すとVMサイズの選択画面が表示されます。
デフォルトだとすべての情報が表示されないので、下図の赤丸部分をすべてクリックしてフィルタを全解除します。

その後、検索欄に「N」と入力するとGPUサイズの情報が一覧表示されます。

今回は「NV6_Promo」を選択します。

 GPU環境は高額なので個人利用の際は料金に注意しましょう!
※VMのスペック詳細はについては以下を参照。

 

最後に管理者アカウントの認証方式を選択します。

「パスワード」と「SSH公開キー」の2種類ありますが、今回はパスワード方式を選択して、ユーザ名とパスワードを設定します。

確認および作成」→「作成」の順にボタンを押してVMを作成します。

VMの作成が完了すると以下の画面「デプロイが完了しました」が表示されるので、「リソースに移動」ボタンを押します。

「概要」→「接続」→「SSH」をクリックするとVMローカルアカウントの情報が表示(ユーザ名、IPアドレス)されるので、
この情報を使ってTeraTermでリモートアクセスします。

ローカルPCでTeraTermなどを起動して、パブリックIPに接続します。

ログオンが完了すると、Azureに構築されたGPU環境(Ubuntu)にアクセスされます。
試しにpythonバージョンを確認すると3.5.6がインストールされていました。

参考:Linux版DSVMにインストールされているモジュール一覧(pip listの結果)

siny@dsvm01-dev:~$ pip list
Package                               Version
------------------------------------- ---------------
absl-py                               0.8.1
adal                                  1.2.2
alabaster                             0.7.12
alembic                               1.3.0
appdirs                               1.4.3
applicationinsights                   0.11.9
asn1crypto                            0.24.0
astor                                 0.8.0
astroid                               2.0.4
astropy                               3.0.4
async-generator                       1.10
atomicwrites                          1.3.0
attrs                                 19.3.0
audioread                             2.1.8
autovizwidget                         0.13.1
azure                                 4.0.0
azure-applicationinsights             0.1.0
azure-batch                           4.1.3
azure-common                          1.1.23
azure-cosmosdb-nspkg                  2.0.2
azure-cosmosdb-table                  1.0.6
azure-datalake-store                  0.0.48
azure-eventgrid                       1.3.0
azure-graphrbac                       0.40.0
azure-keyvault                        1.1.0
azure-loganalytics                    0.1.0
azure-mgmt                            4.0.0
azure-mgmt-advisor                    1.0.1
azure-mgmt-applicationinsights        0.1.1
azure-mgmt-authorization              0.50.0
azure-mgmt-batch                      5.0.1
azure-mgmt-batchai                    2.0.0
azure-mgmt-billing                    0.2.0
azure-mgmt-cdn                        3.1.0
azure-mgmt-cognitiveservices          3.0.0
azure-mgmt-commerce                   1.0.1
azure-mgmt-compute                    4.6.2
azure-mgmt-consumption                2.0.0
azure-mgmt-containerinstance          1.5.0
azure-mgmt-containerregistry          2.8.0
azure-mgmt-containerservice           4.4.0
azure-mgmt-cosmosdb                   0.4.1
azure-mgmt-datafactory                0.6.0
azure-mgmt-datalake-analytics         0.6.0
azure-mgmt-datalake-nspkg             3.0.1
azure-mgmt-datalake-store             0.5.0
azure-mgmt-datamigration              1.0.0
azure-mgmt-devspaces                  0.1.0
azure-mgmt-devtestlabs                2.2.0
azure-mgmt-dns                        2.1.0
azure-mgmt-eventgrid                  1.0.0
azure-mgmt-eventhub                   2.6.0
azure-mgmt-hanaonazure                0.1.1
azure-mgmt-iotcentral                 0.1.0
azure-mgmt-iothub                     0.5.0
azure-mgmt-iothubprovisioningservices 0.2.0
azure-mgmt-keyvault                   1.1.0
azure-mgmt-loganalytics               0.2.0
azure-mgmt-logic                      3.0.0
azure-mgmt-machinelearningcompute     0.4.1
azure-mgmt-managementgroups           0.1.0
azure-mgmt-managementpartner          0.1.1
azure-mgmt-maps                       0.1.0
azure-mgmt-marketplaceordering        0.1.0
azure-mgmt-media                      1.0.0
azure-mgmt-monitor                    0.5.2
azure-mgmt-msi                        0.2.0
azure-mgmt-network                    2.7.0
azure-mgmt-notificationhubs           2.1.0
azure-mgmt-nspkg                      3.0.2
azure-mgmt-policyinsights             0.1.0
azure-mgmt-powerbiembedded            2.0.0
azure-mgmt-rdbms                      1.9.0
azure-mgmt-recoveryservices           0.3.0
azure-mgmt-recoveryservicesbackup     0.3.0
azure-mgmt-redis                      5.0.0
azure-mgmt-relay                      0.1.0
azure-mgmt-reservations               0.2.1
azure-mgmt-resource                   2.2.0
azure-mgmt-scheduler                  2.0.0
azure-mgmt-search                     2.1.0
azure-mgmt-servicebus                 0.5.3
azure-mgmt-servicefabric              0.2.0
azure-mgmt-signalr                    0.1.1
azure-mgmt-sql                        0.9.1
azure-mgmt-storage                    2.0.0
azure-mgmt-subscription               0.2.0
azure-mgmt-trafficmanager             0.50.0
azure-mgmt-web                        0.35.0
azure-nspkg                           3.0.2
azure-servicebus                      0.21.1
azure-servicefabric                   6.3.0.0
azure-servicemanagement-legacy        0.20.6
azure-storage-blob                    2.0.1
azure-storage-common                  2.1.0
azure-storage-file                    2.0.1
azure-storage-queue                   1.4.0
azurefilesfuse-spawner                1.1
Babel                                 2.7.0
backcall                              0.1.0
backports.shutil-get-terminal-size    1.0.0
beautifulsoup4                        4.6.3
bitarray                              0.8.3
bitstring                             3.1.6
bkcharts                              0.2
blaze                                 0.11.3
bleach                                2.1.4
blobxfer                              1.9.3
bokeh                                 0.13.0
boto                                  2.49.0
boto3                                 1.10.10
botocore                              1.13.10
Bottleneck                            1.2.1
cached-property                       1.5.1
cachetools                            3.1.1
catboost                              0.18
certifi                               2018.8.24
certipy                               0.1.3
cffi                                  1.11.5
chainer                               6.5.0
chainercv                             0.13.1
chainerrl                             0.7.0
chardet                               3.0.4
Click                                 7.0
cloudpickle                           1.2.2
clyent                                1.2.2
cntk-gpu                              2.5.1
color                                 0.1
colorama                              0.4.1
colour                                0.1.5
configparser                          4.0.2
contextlib2                           0.6.0
cryptography                          2.8
cupy-cuda100                          6.5.0
cycler                                0.10.0
Cython                                0.28.5
cytoolz                               0.9.0.1
dask                                  0.19.2
databricks-cli                        0.9.1
datashape                             0.5.4
decorator                             4.4.1
defusedxml                            0.6.0
distributed                           1.23.2
dlib                                  19.18.0
docutils                              0.14
easydict                              1.9
entrypoints                           0.3
enum34                                1.1.6
et-xmlfile                            1.0.1
fastcache                             1.0.2
fasteners                             0.15
fastparquet                           0.3.2
fastrlock                             0.4
filelock                              3.0.12
fire                                  0.2.1
flake8                                3.7.9
flaky                                 3.6.1
Flask                                 1.1.1
Flask-Cors                            3.0.8
future                                0.17.1
gast                                  0.2.2
gensim                                3.8.1
gevent                                1.3.6
glob2                                 0.7
gmpy2                                 2.0.8
google-auth                           1.7.0
google-auth-oauthlib                  0.4.1
google-pasta                          0.1.8
graphviz                              0.8.4
greenlet                              0.4.15
grpcio                                1.24.3
gym                                   0.15.3
h2o                                   3.26.0.9
h5py                                  2.8.0
hdijupyterutils                       0.13.1
HeapDict                              1.0.1
horovod                               0.16.4
html5lib                              1.0.1
hyperopt                              0.2.2
idna                                  2.7
imageio                               2.3.0
imagesize                             1.1.0
importlib2                            3.5.0.2
imutils                               0.5.3
ipykernel                             4.10.0
ipython                               6.5.0
ipython-genutils                      0.2.0
ipywidgets                            7.4.1
isodate                               0.6.0
isort                                 4.3.4
itsdangerous                          1.1.0
jdcal                                 1.4.1
jedi                                  0.12.1
jeepney                               0.4.1
Jinja2                                2.10.3
jmespath                              0.9.4
joblib                                0.14.0
json5                                 0.8.5
jsonschema                            2.6.0
jupyter                               1.0.0
jupyter-client                        5.3.3
jupyter-console                       5.2.0
jupyter-core                          4.5.0
jupyterhub                            1.0.0
jupyterlab                            1.2.1
jupyterlab-launcher                   0.13.1
jupyterlab-server                     1.0.0
Keras                                 2.3.1
Keras-Applications                    1.0.8
Keras-Preprocessing                   1.1.0
keras2onnx                            1.6.0
keyring                               13.2.1
kiwisolver                            1.0.1
Lasagne                               0.2.dev1
lazy-object-proxy                     1.3.1
librosa                               0.7.1
lightgbm                              2.3.0
llvmlite                              0.30.0
locket                                0.2.0
lxml                                  4.2.5
Mako                                  1.1.0
Markdown                              3.1.1
MarkupSafe                            1.0
matplotlib                            3.0.0
mccabe                                0.6.1
mistune                               0.8.3
mkl-fft                               1.0.6
mkl-random                            1.0.1
mock                                  3.0.5
monotonic                             1.5
more-itertools                        4.3.0
mpmath                                1.0.0
msgpack                               0.5.6
msrest                                0.6.10
msrestazure                           0.6.2
multipledispatch                      0.6.0
mxnet                                 1.5.1
mxnet-model-server                    1.0.8
nbconvert                             5.5.0
nbformat                              4.4.0
nbsphinx                              0.4.3
networkx                              2.2
nltk                                  3.3
nose                                  1.3.7
notebook                              5.6.0
numba                                 0.46.0
numexpr                               2.6.8
numpy                                 1.17.3
numpydoc                              0.9.1
oauthlib                              3.1.0
odo                                   0.5.1
olefile                               0.46
onnx                                  1.6.0
onnx-chainer                          1.5.0
onnx-mxnet                            0.4.2
onnxconverter-common                  1.6.0
onnxmltools                           1.5.1
onnxruntime                           1.0.0
openpyxl                              2.6.3
opt-einsum                            3.1.0
packaging                             19.2
pamela                                1.0.0
pandas                                0.25.3
pandas-datareader                     0.8.0
pandocfilters                         1.4.2
parso                                 0.5.1
partd                                 1.0.0
path.py                               11.1.0
pathlib2                              2.3.2
patsy                                 0.5.0
pbr                                   5.4.3
pep8                                  1.7.1
pexpect                               4.6.0
pickleshare                           0.7.4
Pillow                                5.2.0
pip                                   19.3.1
pkginfo                               1.4.2
plotly                                4.2.1
pluggy                                0.11.0
ply                                   3.11
progressbar33                         2.4
prometheus-client                     0.7.1
prompt-toolkit                        1.0.15
protobuf                              3.10.0
psutil                                5.4.7
psycopg2                              2.7.5
ptyprocess                            0.6.0
py                                    1.8.0
pyasn1                                0.4.7
pyasn1-modules                        0.2.7
PyAudio                               0.2.11
pycodestyle                           2.4.0
pycosat                               0.6.3
pycparser                             2.19
pycrypto                              2.6.1
pycuda                                2019.1.2
pycurl                                7.43.0.2
pydicom                               1.3.0
pydocumentdb                          2.3.5
pydot-ng                              2.0.0
pyflakes                              2.1.1
pygame                                1.9.6
pyglet                                1.3.2
Pygments                              2.4.2
pygpu                                 0.7.6
PyJWT                                 1.7.1
pykerberos                            1.2.1
pylint                                2.1.1
pyodbc                                4.0.24
pyOpenSSL                             18.0.0
pyparsing                             2.4.2
PySocks                               1.6.8
pytest                                3.8.1
pytest-arraydiff                      0.2
pytest-astropy                        0.4.0
pytest-doctestplus                    0.4.0
pytest-openfiles                      0.4.0
pytest-remotedata                     0.3.0
python-dateutil                       2.8.0
python-editor                         1.0.4
pytools                               2019.1.1
pytz                                  2019.3
PyWavelets                            1.0.0
PyYAML                                3.13
pyzmq                                 17.1.2
QtAwesome                             0.6.0
qtconsole                             4.5.5
QtPy                                  1.9.0
readme-renderer                       24.0
requests                              2.22.0
requests-kerberos                     0.12.0
requests-oauthlib                     1.2.0
requests-toolbelt                     0.9.1
resampy                               0.2.2
retrying                              1.3.3
rope                                  0.14.0
rsa                                   4.0
ruamel-yaml                           0.15.46
ruamel.yaml                           0.16.5
ruamel.yaml.clib                      0.2.0
s3transfer                            0.2.1
scikit-image                          0.14.0
scikit-learn                          0.20.0
scipy                                 1.1.0
seaborn                               0.9.0
SecretStorage                         3.1.0
Send2Trash                            1.5.0
setuptools                            40.2.0
simplegeneric                         0.8.1
singledispatch                        3.4.0.3
six                                   1.11.0
skl2onnx                              1.5.2
smart-open                            1.9.0
snowballstemmer                       2.0.0
sortedcollections                     1.0.1
sortedcontainers                      2.0.5
SoundFile                             0.10.2
sparkmagic                            0.13.1
Sphinx                                2.2.1
sphinx-rtd-theme                      0.4.3
sphinxcontrib-applehelp               1.0.1
sphinxcontrib-devhelp                 1.0.1
sphinxcontrib-htmlhelp                1.0.2
sphinxcontrib-jsmath                  1.0.1
sphinxcontrib-qthelp                  1.0.2
sphinxcontrib-serializinghtml         1.1.3
sphinxcontrib-websupport              1.1.2
spyder                                3.3.1
spyder-kernels                        0.2.6
SQLAlchemy                            1.2.11
statsmodels                           0.9.0
sudospawner                           0.6.0.dev0
sympy                                 1.2
tables                                3.4.4
tabulate                              0.8.5
TBB                                   0.1
tblib                                 1.4.0
tensorboard                           2.0.1
tensorflow-estimator                  2.0.1
tensorflow-gpu                        2.0.0
termcolor                             1.1.0
terminado                             0.8.1
testpath                              0.3.1
tf2onnx                               1.5.3
Theano                                0.9.0
thrift                                0.11.0
toolz                                 0.10.0
torch                                 1.2.0
torchvision                           0.4.0a0+6b959ee
tornado                               5.1.1
tqdm                                  4.37.0
traitlets                             4.3.2
twine                                 1.15.0
typed-ast                             1.1.0
typing                                3.6.6
typing-extensions                     3.6.6
unicodecsv                            0.14.1
urllib3                               1.23
wcwidth                               0.1.7
webencodings                          0.5.1
Werkzeug                              0.16.0
wget                                  3.2
wheel                                 0.31.1
widgetsnbextension                    3.4.1
wrapt                                 1.11.2
xgboost                               0.80
xlrd                                  1.1.0
XlsxWriter                            1.2.2
xlwt                                  1.3.0
zict                                  1.0.0

 

コマンドラインによる作成方法

Azure CLIを使うと、DSVM環境を一発で作成することができます。

パスワード方式でDSVM環境を構築する場合のコマンドは以下の通りです。

az vm create --resource-group <リソースグループ名> --name <サーバ名> --image microsoft-dsvm:linux-data-science-vm-ubuntu:linuxdsvmubuntu:latest --admin-username <ユーザ名> --admin-password <パスワード> --generate-ssh-keys --authentication-type password --public-ip-address-dns-name <dns名>

 

SSH公開キーを使う場合のDSVM環境を構築するコマンドは以下の通りです。

az vm create --resource-group <リソースグループ名> --name <サーバ名> --image microsoft-dsvm:linux-data-science-vm-ubuntu:linuxdsvmubuntu:latest --generate-ssh-keys --public-ip-address-dns-name <dns名>

 

 

JUPYTERサーバへアクセス

Azure Data Science Virtual Machineを作成するとデフォルトでJupyternotebookサーバが立ち上がっているので、
「https:<パブリックIP>:8000/」にアクセスします。

以下の画面が表示されるので、VMを作成した際に指定したユーザ名とパスワードを指定してログオンしましょう。

ログオンが完了すると以下のようにJupyterNotebook画面が表示されます。
デフォルトで様々なチュートリアルのノートブック等が存在しているのでこの辺を見ると色々勉強になりそうな感じですね。

まとめ

あらためてAzure Data Science Virtual Machineに関するポイントをまとめておきます。

  • OS環境は現状3種類(Windows Server 2016、Ubuntu 16.04 LTS、CentOS 7.4
  • 作成方法は大きく2つ(ポータル上のマウス操作で作成 or AzureCLIコマンドで作成)
  • VMサイズ選択でGPUはデフォルト表示されないのでフィルタを解除しないと選択できない。
  • WIndows版とそれ以外ではできることできないことに差がある模様。
  • Jupyterサーバを使用する場合は、必ず [パスワード] 方式でVMを作成する必要がある(SSH公開キーはサポートされてない)※2019/12/14時点

 

 

おすすめの記事