LoginSignup

This article is a Private article. Only a writer and users who know the URL can access it.
Please change open range to public in publish setting if you want to share this article with other users.

More than 5 years have passed since last update.

[Singularity Hands-on] case3: Singularity でtensorflowを動かそう (--sandboxビルド, runコマンド編)

Last updated at Posted at 2018-01-21

case1では、ソースは "Docker HUb"を用い、実行は "run" コマンド でコンテナ内のtensorflowを実行します。また、本ページの親ページはこちらにあります。

Kobito.kgSxWp.png

前提条件

Singularity がインストールされていること

Hands-on1 で作成した local container から writableな sandboxのコンテナーを作成する

Singularity コンテナーの作成

command@host
CONTAINER_NAME="sbcontainer.img"
SOURCE_IMAGE="container.img"
command@host
sudo singularity build --sandbox ${CONTAINER_NAME} ${SOURCE_IMAGE}

生成物の確認

command@host
ls -l ${CONTAINER_NAME}
response@host
total 84
drwxr-xr-x  2 root root 4096 Dec  8 10:21 bin
drwxr-xr-x  2 root root 4096 Apr 12  2016 boot
drwxr-xr-x  2 root root 4096 Nov 14 13:48 dev
lrwxrwxrwx  1 root root   36 Oct 29 04:09 environment -> .singularity.d/env/90-environment.sh
drwxr-xr-x 51 root root 4096 Dec  8 10:21 etc
drwxr-xr-x  2 root root 4096 Apr 12  2016 home
drwxr-xr-x  8 root root 4096 Dec  8 10:21 lib
drwxr-xr-x  2 root root 4096 Nov 14 13:49 lib64
drwxr-xr-x  2 root root 4096 Nov 14 13:48 media
drwxr-xr-x  2 root root 4096 Nov 14 13:48 mnt
drwxr-xr-x  2 root root 4096 Dec  8 10:23 notebooks
drwxr-xr-x  2 root root 4096 Nov 14 13:48 opt
drwxr-xr-x  2 root root 4096 Apr 12  2016 proc
drwx------  4 root root 4096 Dec  8 10:23 root
drwxr-xr-x  5 root root 4096 Dec  8 10:21 run
-rwxr-xr-x  1 root root  733 Dec  8 10:20 run_jupyter.sh
drwxr-xr-x  2 root root 4096 Nov 17 21:59 sbin
lrwxrwxrwx  1 root root   24 Oct 29 04:09 singularity -> .singularity.d/runscript
drwxr-xr-x  2 root root 4096 Nov 14 13:48 srv
drwxr-xr-x  2 root root 4096 Feb  5  2016 sys
drwxrwxr-x  3 root root 4096 Dec  8 10:22 tmp
drwxr-xr-x 10 root root 4096 Nov 14 13:48 usr
drwxr-xr-x 11 root root 4096 Nov 14 13:49 var

コンテナーの ubuntu を update する

コンテナーへのログイン(書き込みモード)

command@host
sudo singularity shell --writable ${CONTAINER_NAME}

コンテナー内のパッケージをアップデート

command@container
apt-get update
apt-get install wget

MNISTのダウンロード

MNISTをダウンロードします.

command@container
cd /
wget https://raw.githubusercontent.com/tensorflow/tensorflow/r1.4/tensorflow/examples/tutorials/mnist/mnist_softmax.py
command@container
exit

Tensorflowの実行 (runコマンド経由)

inspectコマンドによるランスクリプトの確認

inspect コマンドを使って、コンテナーのランスクリプトの内容を確認します。

command@host
singularity inspect -r ${CONTAINER_NAME}
response@host
#!/bin/sh

exec "/run_jupyter.sh" "--allow-root"

現状だとjupyterが立ち上がるようです。

ランスクリプトの編集

このランスクリプトを編集します。

command@host
sudo vi ${CONTAINER_NAME}/.singularity.d/runscript

内容は以下のようにします。

編集内容
#!/bin/sh

#exec "/run_jupyter.sh" "--allow-root"
exec python /mnist_softmax.py

MNIST on tensorflow の実行

ランスクリプトを実行します。下記の例のように最後に "0.9197" のような数字がでれば完成です。

command@host
singularity run ${CONTAINER_NAME}
response@host
Extracting /tmp/tensorflow/mnist/input_data/train-images-idx3-ubyte.gz
Extracting /tmp/tensorflow/mnist/input_data/train-labels-idx1-ubyte.gz
Extracting /tmp/tensorflow/mnist/input_data/t10k-images-idx3-ubyte.gz
Extracting /tmp/tensorflow/mnist/input_data/t10k-labels-idx1-ubyte.gz
2018-01-21 06:39:08.614155: I tensorflow/core/platform/cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2
0.9197
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up