FPGA開発日記

カテゴリ別記事インデックス https://msyksphinz.github.io/github_pages , English Version https://fpgadevdiary.hatenadiary.com/

TensorFlow Serving実行環境をVagrantで構築する(Pythonのバージョンで引っ掛かる部分)

前回のTensorFlow ServingをVagrantで自動的に構築する話、もう一度自分でやってみると、いろんな部分で動作しない部分があった。bazelとか、grpcとかのバージョンはいろいろ注意深くやらなければならない。

特にPythonのバージョンで引掛った。Ubuntuのバージョンを14.04LTSに落としたため、いくつかのライブラリをバージョンアップさせる必要がある。

1. Ubuntu 14.04LTSでTensorFlow Serving環境を構築するときに注意すること

現在の僕の持っている最新のChefビルドスクリプトは以下だ。

github.com

いくつか注意しなければならない点がある。

1.1 Numpyのバージョンを上げること

stackoverflow.com

このサイトでは対象は違うものの、同一のエラーが出る。Ubuntu 14.04LTSでは、PythonのNumpyのバージョンが1.9までしか上がっていないことが問題だ。 現状では、そのままでアップデートは難しいため、Ubuntuリポジトリから、Numpyだけ最新のものに合わせる。

python-numpy package : Ubuntu

Numpyのバージョンを1.10にバージョンアップさせるのはChefの中で以下だ。

remote_file "/home/vagrant/download/python-numpy_1.10.4-2ubuntu2_amd64.deb" do
  source "https://launchpad.net/ubuntu/+archive/primary/+files/python-numpy_1.10.4-2ubuntu2_amd64.deb"
  owner 'vagrant'
  group 'vagrant'
  mode '0755'
  action :create
end


execute "install numpy-1.10.4" do
  cwd "/home/vagrant/download/"
  command "dpkg -i ./python-numpy_1.10.4-2ubuntu2_amd64.deb"
end

1.2 Java 8のインストールをDialog無しで実行するために必要なこと

Java8は、bazelのインストール時に必要になるパッケージだが、これはインストール時にDialogでいくつか質問に答える項目があり、そのままではChefに構築で実装できない。 いろいろ調べた結果、以下のようにあらかじめスクリプトを組んでおくことで、回避できるようだ。

execute "echo debconf shared/accepted-oracle-license-v1-1 select true | sudo debconf-set-selections"
execute "echo debconf shared/accepted-oracle-license-v1-1 seen true | sudo debconf-set-selections"
execute "DEBIAN_FRONTEND=noninteractive apt-get install -y oracle-java8-installer"

1.3 bazelをユーザ領域にインストールするのに必要なこと

bazelのインストールには、--userオプションを付けるような指示があるが、これもちょっと注意が必要だ。Vagrant Provision時のみの問題かもしれないが、何故かrootの領域にいろんなものをインストールしようとする。 HOMEの環境変数を変更する必要がありそうだ。でないと、/root/の領域にアクセスしようとする。

execute "install bazel" do
  user "vagrant"
  environment "HOME" => "/home/vagrant"
  cwd "/home/vagrant/download/"
  command "./bazel-0.1.5-installer-linux-x86_64.sh --user --prefix=/home/vagrant/ --bin=/home/vagrant/bin --base=/home/vagrant/.bazel --bazelrc=/home/vagrant/.bazelrc"
end

1.4 grpcioのバージョンを上げること

grpcioは、そもそもUbuntuのバージョンを14.04LTSに落とした最大の要因だ。インストールするためには、以下が必要だ。

execute "extract python_pip grpcio" do
  command "sudo pip install --upgrade ndg-httpsclient && pip install grpcio"
end

という訳で、Ubuntu 14.04LTS + TensorFlow Servingの自動環境構築スクリプトの完成だ。

$ vagrant up
...
==> default:
==> default:     [execute] No GPU support will be enabled for TensorFlow
==> default:               Configuration finished
==> default: [2016-02-25T13:17:47+00:00] INFO: execute[configure tensorflow serving] ran successfully
==> default:     - execute ./configure
==> default:   * execute[install tensorflow servivg] action run
==> default:
==> default:     [execute] ____Loading...
==> default:               ____Found 112 targets...
==> default:               ____Building...
==> default:               ____[0 / 4] BazelWorkspaceStatusAction stable-status.txt
==> default:               ____Elapsed time: 3.321s, Critical Path: 0.16s
==> default: [2016-02-25T13:17:50+00:00] INFO: execute[install tensorflow servivg] ran successfully
==> default:     - execute /home/vagrant/bin/bazel build tensorflow_serving/...
==> default: [2016-02-25T13:17:50+00:00] INFO: Chef Run complete in 50.140883478 seconds
==> default: [2016-02-25T13:17:50+00:00] INFO: Skipping removal of unused files from the cache
==> default:
==> default: Running handlers:
==> default: [2016-02-25T13:17:50+00:00] INFO: Running report handlers
==> default: Running handlers complete
==> default: [2016-02-25T13:17:50+00:00] INFO: Report handlers complete
==> default: Chef Client finished, 56/114 resources updated in 01 hours 13 minutes 02 seconds
$

よし!