Ultra-fast build of Tensorflow with Bazel Remote Caching [Google Cloud Storage version]

**Tensorflow-bin**　[![GitHub stars](https://img.shields.io/github/stars/PINTO0309/Tensorflow-bin.svg?style=social&label=Stars)](https://github.com/PINTO0309/Tensorflow-bin)
<a href="https://github.com/PINTO0309/Tensorflow-bin"><img src="https://github-link-card.s3.ap-northeast-1.amazonaws.com/PINTO0309/Tensorflow-bin.png" width="460px"></a>
**Bazel_bin**　[![GitHub stars](https://img.shields.io/github/stars/PINTO0309/Bazel_bin.svg?style=social&label=Stars)](https://github.com/PINTO0309/Bazel_bin)
<a href="https://github.com/pinto0309/Bazel_bin"><img src="https://github-link-card.s3.ap-northeast-1.amazonaws.com/pinto0309/Bazel_bin.png" width="460px"></a>
# １．Introduction
今回は Google Cloud Storage をキャッシング環境に使用した最もお手軽なビルド手順を試行しました。 １時間掛かる Tensorflow のビルドを ２分２０秒ほどに短縮できます。 ビルド済みのバイナリとソースファイルをハッシュ化してストレージ上にキャッシュし、２回目以降のビルド時にはキャッシュ済みのハッシュ値と現ファイルから計算したハッシュ値を比較して同じであればビルドを簡略化し、ハッシュ値に差分のあるファイルのみコンパイルします。 よって、初回ビルド時はキャッシュが全く無くキャッシングの処理に余分な時間を割くため、通常のビルドよりも少しだけ遅くなります。 検証の結果、Tensorflow がバージョンアップした場合はキャッシングのベースとなっているハッシュ値が完全に異なるようで、うまくキャッシュが効きませんでした。 試行錯誤しながらビルドバラメータを頻繁に変更したり、とあるソースファイルのバグフィックスを単発で実施した場合のリビルドの場合にはかなり強力なパフォーマンスを発揮します。 複数の開発者間でビルド済みのバイナリを共有してデバッグ効率を少しだけ上げるような用途には向いていそうです。 次回は、nginxを使用した完全無料ローカルキャッシュ環境構築にトライしてみようと思います。

Build Tensorflow super fast using Bazel's Remote Caching feature. It is 24 times faster than the standard build method. However, according to the examination result of this article, it seems that the difference in the version upgrade of the repository can not be compensated. Provides a shared and incremental compilation environment for pre-built binaries among multiple developers. Next time, I would like to try the local cache procedure by nginx.
<blockquote class="twitter-tweet"><p lang="ja" dir="ltr">Bazel の リモートキャッシングを有効にした Tensorflow v1.14.0 のフルビルドの様子を動画にしました。 速すぎて笑えます。<a href="https://t.co/fACRf2WfKu">https://t.co/fACRf2WfKu</a></p>&mdash; PINTO0309 (@PINTO03091) <a href="https://twitter.com/PINTO03091/status/1157900577726070784?ref_src=twsrc%5Etfw">August 4, 2019</a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>

# ２．Environment

- Ubuntu 16.04 x86_64
- Tensorflow v1.13.2 + Bazel 0.20.0
- Tensorflow v1.14.0 + Bazel 0.24.1
- Google Cloud Storage

![bazel-caching (1).png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/e950e642-f8cd-9d24-2b90-4b66092e84ef.png)

# ３．Prepare Google Cloud Storage for Caching
You need a Google Cloud account with billing enabled.

## ３−１．Create storage bucket
**https://docs.bazel.build/versions/master/remote-caching.html#google-cloud-storage**

![FireShot Capture 056 - ストレージ バケットの作成  -  Cloud Storage  -  Google Cloud - cloud.google.com.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/9d06c4eb-fcfc-3896-a08a-d18d6c9bb3a6.png)
![FireShot Capture 057 - 参照 - My First Project - Google Cloud Platform - console.cloud.google.com.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/35e64fef-8a0d-f6cb-1a67-164c8b9beb3a.png)
![FireShot Capture 058 - Storage – My First Project – Google Cloud Platform - console.cloud.google.com.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/6bf07a51-413b-c5a2-8b30-990d88d50e39.png)
![FireShot Capture 059 - Storage – My First Project – Google Cloud Platform - console.cloud.google.com.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/e3b4325d-dc7a-bacb-d2ac-4265ac5324f7.png)
![FireShot Capture 060 - Storage – My First Project – Google Cloud Platform - console.cloud.google.com.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/b81c7ddf-df35-32ba-5ff6-d62bbc07d9e6.png)
![FireShot Capture 061 - Storage – My First Project – Google Cloud Platform - console.cloud.google.com.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/0109073b-22a2-a70a-1340-c233b2cfec93.png)
![FireShot Capture 062 - バケットの詳細 - My First Project - Google Cloud Platform - console.cloud.google.com.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/79d02dd8-8dd6-a851-9acc-43be5e1e374e.png)

## ３−２．Create service account
**https://cloud.google.com/iam/docs/creating-managing-service-accounts#creating_a_service_account**

![FireShot Capture 063 - サービス アカウントの作成と管理  -  Cloud Identity and Access Management のドキュメント  - _ - cloud.google.com.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/ac1ec71b-2a47-b544-c782-45850da7e8a3.png)
![FireShot Capture 064 - サービス アカウント – IAM と管理 – Google Cloud Platform - console.cloud.google.com.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/0c4daae2-afc4-e144-8246-a78bb764bae8.png)
![FireShot Capture 065 - サービス アカウント – IAM と管理 – Google Cloud Platform - console.cloud.google.com.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/a72e6c66-daa2-bdf9-b9f5-acbba20dcc6d.png)
![FireShot Capture 066 - サービス アカウント – IAM と管理 – My First Project – Google Cloud Platform_ - console.cloud.google.com.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/73b1646e-8131-3827-6abd-2d29dd4996f7.png)
![FireShot Capture 067 - サービス アカウントの作成 – IAM と管理 – My First Project – Google Cloud Platform_ - console.cloud.google.com.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/471b5660-5b99-b932-b745-319a9d135799.png)
![FireShot Capture 068 - サービス アカウントの作成 – IAM と管理 – My First Project – Google Cloud Platform_ - console.cloud.google.com.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/f0c18d3c-a9f5-2c91-1c8a-9659c0667781.png)
![FireShot Capture 070 - サービス アカウントの作成 – IAM と管理 – My First Project – Google Cloud Platform_ - console.cloud.google.com.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/63b6fdb3-2f68-a56f-7520-ca4459f0d7ce.png)
![FireShot Capture 071 - サービス アカウントの作成 – IAM と管理 – My First Project – Google Cloud Platform_ - console.cloud.google.com.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/6138f5b2-407c-0510-f131-4d9545a12ece.png)
![FireShot Capture 072 - サービス アカウントの作成 – IAM と管理 – My First Project – Google Cloud Platform_ - console.cloud.google.com.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/4c25fb15-8fa4-7cd7-187b-c879d9178953.png)
![FireShot Capture 074 - サービス アカウントの作成 – IAM と管理 – My First Project – Google Cloud Platform_ - console.cloud.google.com.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/e79d87af-9e44-665d-404d-a44036c1e9f8.png)

A json file with a name such as **`xxxxx-xxxxxxxxxxxx.json`** will be downloaded automatically.

![FireShot Capture 075 - サービス アカウントの作成 – IAM と管理 – My First Project – Google Cloud Platform_ - console.cloud.google.com.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/0d0e2448-a8ae-4742-0d2a-d7ea5d386825.png)
![FireShot Capture 076 - サービス アカウント – IAM と管理 – My First Project – Google Cloud Platform_ - console.cloud.google.com.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/6878dcf0-7341-cd4f-b38b-341da696d72f.png)

## ３−３．Preparation for connection to Remote cache (Google Cloud Storage)

```console:
$ cd ~
$ mkdir bazel-caching
$ mv ~/Downloads/xxxxx-xxxxxxxxxxxx.json ${HOME}/bazel-caching
```

# ４．(First time) Building Tensorflow v1.13.2

```console:
$ sudo apt-get install -y libhdf5-dev libc-ares-dev libeigen3-dev
$ sudo pip3 install keras_applications==1.0.7 --no-deps
$ sudo pip3 install keras_preprocessing==1.0.9 --no-deps
$ sudo pip3 install h5py==2.9.0
$ sudo apt-get install -y openmpi-bin libopenmpi-dev
$ sudo -H pip3 install -U --user six numpy wheel mock
$ sudo apt update;sudo apt upgrade

$ cd ~
$ git clone https://github.com/PINTO0309/Bazel_bin.git
$ Bazel_bin/0.20.0/Ubuntu1604_x86_64/install.sh

$ cd ~
$ git clone https://github.com/tensorflow/tensorflow.git
$ cd tensorflow
$ git branch -a
* master
  remotes/origin/0.6.0
  remotes/origin/HEAD -> origin/master
  remotes/origin/bananabowl-patch-1
  remotes/origin/ewilderj-patch-1
  remotes/origin/jvishnuvardhan-patch-1
  remotes/origin/jvishnuvardhan-patch-9
  remotes/origin/master
  remotes/origin/patch-cherry-pick-tf-data
  remotes/origin/r0.10
  remotes/origin/r0.11
  remotes/origin/r0.12
  remotes/origin/r0.7
  remotes/origin/r0.8
  remotes/origin/r0.9
  remotes/origin/r1.0
  remotes/origin/r1.1
  remotes/origin/r1.10
  remotes/origin/r1.11
  remotes/origin/r1.12
  remotes/origin/r1.13
  remotes/origin/r1.14
  remotes/origin/r1.2
  remotes/origin/r1.3
  remotes/origin/r1.4
  remotes/origin/r1.5
  remotes/origin/r1.6
  remotes/origin/r1.7
  remotes/origin/r1.8
  remotes/origin/r1.9
  remotes/origin/r2.0
  remotes/origin/release_1.14.0
  remotes/origin/rthadur-patch-1

$ git checkout -b r1.13 origin/r1.13
$ sudo bazel clean

$ ./configure

WARNING: --batch mode is deprecated. Please instead explicitly shut down your Bazel server using the command "bazel shutdown".
INFO: Invocation ID: 202dac03-9d5d-4544-ba79-90001b7b2ca9
You have bazel 0.20.0- (@non-git) installed.
Please specify the location of python. [Default is /usr/bin/python]: /usr/bin/python3


Found possible Python library paths:
  /opt/intel/openvino_2019.2.242/python/python3
  /opt/intel/openvino_2019.2.242/python/python3.5
  /home/b920405/git/caffe-jacinto/python
  /opt/intel/openvino_2019.2.242/deployment_tools/model_optimizer
  .
  /opt/movidius/caffe/python
  /usr/lib/python3/dist-packages
  /usr/local/lib/python3.5/dist-packages
  /usr/local/lib
Please input the desired Python library path to use.  Default is [/opt/intel/openvino_2019.2.242/python/python3]
/usr/local/lib/python3.5/dist-packages
Do you wish to build TensorFlow with XLA JIT support? [Y/n]: n
No XLA JIT support will be enabled for TensorFlow.

Do you wish to build TensorFlow with OpenCL SYCL support? [y/N]: n
No OpenCL SYCL support will be enabled for TensorFlow.

Do you wish to build TensorFlow with ROCm support? [y/N]: n
No ROCm support will be enabled for TensorFlow.

Do you wish to build TensorFlow with CUDA support? [y/N]: n
No CUDA support will be enabled for TensorFlow.

Do you wish to download a fresh release of clang? (Experimental) [y/N]: n
Clang will not be downloaded.

Do you wish to build TensorFlow with MPI support? [y/N]: n
No MPI support will be enabled for TensorFlow.

Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -march=native -Wno-sign-compare]: 


Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]: n
Not configuring the WORKSPACE for Android builds.

Preconfigured Bazel build configs. You can use any of the below by adding "--config=<>" to your build command. See .bazelrc for more details.
	--config=mkl         	# Build with MKL support.
	--config=monolithic  	# Config for mostly static monolithic build.
	--config=gdr         	# Build with GDR support.
	--config=verbs       	# Build with libverbs support.
	--config=ngraph      	# Build with Intel nGraph support.
	--config=dynamic_kernels	# (Experimental) Build kernels into separate shared objects.
Preconfigured Bazel build configs to DISABLE default on features:
	--config=noaws       	# Disable AWS S3 filesystem support.
	--config=nogcp       	# Disable GCP support.
	--config=nohdfs      	# Disable HDFS support.
	--config=noignite    	# Disable Apacha Ignite support.
	--config=nokafka     	# Disable Apache Kafka support.
	--config=nonccl      	# Disable NVIDIA NCCL support.
Configuration finished

$ sudo bazel build \
--config=opt \
--config=noaws \
--config=nogcp \
--config=nohdfs \
--config=noignite \
--config=nokafka \
--config=nonccl \
--copt=-ftree-vectorize \
--copt=-funsafe-math-optimizations \
--copt=-ftree-loop-vectorize \
--copt=-fomit-frame-pointer \
--remote_http_cache=https://storage.googleapis.com/bucket-bazel-tensorflow \
--google_credentials=${HOME}/bazel-caching/xxxxx-xxxxxxxxxxxx.json \
//tensorflow/tools/pip_package:build_pip_package
```
![Screenshot 2019-08-04 00:15:46.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/018d40de-a8b4-6783-c221-a4c96e1bb8f5.png)
Action result metadata is stored under the path **`/ac/`**
Output files are stored under the path **`/cas/`**

![FireShot Capture 077 - バケットの詳細 - My First Project - Google Cloud Platform - console.cloud.google.com.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/d4015834-91cb-8ac5-3d19-ef53072fd946.png)
![FireShot Capture 078 - バケットの詳細 - My First Project - Google Cloud Platform - console.cloud.google.com.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/00495dc6-16a0-1612-52a8-7ddacd6e799b.png)

# ５．(Second time) Building Tensorflow v1.14.0

```console:
$ cd ~
$ Bazel_bin/0.24.1/Ubuntu1604_x86_64/install.sh

$ cd ~
$ cd tensorflow
$ git checkout -b r1.14 origin/r1.14
$ sudo bazel clean

$ ./configure

WARNING: --batch mode is deprecated. Please instead explicitly shut down your Bazel server using the command "bazel shutdown".
You have bazel 0.24.1- (@non-git) installed.
Please specify the location of python. [Default is /usr/bin/python]: /usr/bin/python3


Found possible Python library paths:
  /opt/intel/openvino_2019.2.242/python/python3
  /opt/intel/openvino_2019.2.242/python/python3.5
  /home/b920405/git/caffe-jacinto/python
  /opt/intel/openvino_2019.2.242/deployment_tools/model_optimizer
  .
  /opt/movidius/caffe/python
  /usr/lib/python3/dist-packages
  /usr/local/lib/python3.5/dist-packages
  /usr/local/lib
Please input the desired Python library path to use.  Default is [/opt/intel/openvino_2019.2.242/python/python3]
/usr/local/lib/python3.5/dist-packages
Do you wish to build TensorFlow with XLA JIT support? [Y/n]: n
No XLA JIT support will be enabled for TensorFlow.

Do you wish to build TensorFlow with OpenCL SYCL support? [y/N]: n
No OpenCL SYCL support will be enabled for TensorFlow.

Do you wish to build TensorFlow with ROCm support? [y/N]: n
No ROCm support will be enabled for TensorFlow.

Do you wish to build TensorFlow with CUDA support? [y/N]: n
No CUDA support will be enabled for TensorFlow.

Do you wish to download a fresh release of clang? (Experimental) [y/N]: n
Clang will not be downloaded.

Do you wish to build TensorFlow with MPI support? [y/N]: n
No MPI support will be enabled for TensorFlow.

Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -march=native -Wno-sign-compare]: 


Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]: n
Not configuring the WORKSPACE for Android builds.

Preconfigured Bazel build configs. You can use any of the below by adding "--config=<>" to your build command. See .bazelrc for more details.
	--config=mkl         	# Build with MKL support.
	--config=monolithic  	# Config for mostly static monolithic build.
	--config=gdr         	# Build with GDR support.
	--config=verbs       	# Build with libverbs support.
	--config=ngraph      	# Build with Intel nGraph support.
	--config=numa        	# Build with NUMA support.
	--config=dynamic_kernels	# (Experimental) Build kernels into separate shared objects.
Preconfigured Bazel build configs to DISABLE default on features:
	--config=noaws       	# Disable AWS S3 filesystem support.
	--config=nogcp       	# Disable GCP support.
	--config=nohdfs      	# Disable HDFS support.
	--config=noignite    	# Disable Apache Ignite support.
	--config=nokafka     	# Disable Apache Kafka support.
	--config=nonccl      	# Disable NVIDIA NCCL support.
Configuration finished

$ sudo bazel build \
--config=opt \
--config=noaws \
--config=nogcp \
--config=nohdfs \
--config=noignite \
--config=nokafka \
--config=nonccl \
--copt=-ftree-vectorize \
--copt=-funsafe-math-optimizations \
--copt=-ftree-loop-vectorize \
--copt=-fomit-frame-pointer \
--remote_http_cache=https://storage.googleapis.com/bucket-bazel-tensorflow \
--google_credentials=${HOME}/bazel-caching/xxxxx-xxxxxxxxxxxx.json \
//tensorflow/tools/pip_package:build_pip_package
```
It seems that caching does not work well if you switch the version or branch of the OSS to be built.
![Screenshot 2019-08-04 14:20:18.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/59838b45-b33f-9076-a898-f1756a5bd396.png)

# ６．(Third time) Building Tensorflow v1.14.0 (Fix the program and rebuild it after removing Bazel's prebuilt binaries)

```python:tensorflow/lite/python/interpreter.py
# Add the following two lines to the last line
  def set_num_threads(self, i):
    return self._interpreter.SetNumThreads(i)
```

```CPP:tensorflow/lite/python/interpreter_wrapper/interpreter_wrapper.cc
// Corrected the vicinity of the last line as follows
PyObject* InterpreterWrapper::ResetVariableTensors() {
  TFLITE_PY_ENSURE_VALID_INTERPRETER();
  TFLITE_PY_CHECK(interpreter_->ResetVariableTensors());
  Py_RETURN_NONE;
}

PyObject* InterpreterWrapper::SetNumThreads(int i) {
  interpreter_->SetNumThreads(i);
  Py_RETURN_NONE;
}

}  // namespace interpreter_wrapper
}  // namespace tflite
```

```CPP:tensorflow/lite/python/interpreter_wrapper/interpreter_wrapper.h
  // should be the interpreter object providing the memory.
  PyObject* tensor(PyObject* base_object, int i);

  PyObject* SetNumThreads(int i);

 private:
  // Helper function to construct an `InterpreterWrapper` object.
  // It only returns InterpreterWrapper if it can construct an `Interpreter`.
```

```python:tensorflow/lite/tools/make/Makefile
BUILD_WITH_NNAPI=false
```

```python:tensorflow/contrib/__init__.py
from tensorflow.contrib import checkpoint
#if os.name != "nt" and platform.machine() != "s390x":
#  from tensorflow.contrib import cloud
from tensorflow.contrib import cluster_resolver
```

```python:tensorflow/contrib/__init__.py
from tensorflow.contrib.summary import summary

if os.name != "nt" and platform.machine() != "s390x":
  try:
    from tensorflow.contrib import cloud
  except ImportError:
    pass

from tensorflow.python.util.lazy_loader import LazyLoader
ffmpeg = LazyLoader("ffmpeg", globals(),
                    "tensorflow.contrib.ffmpeg")
```

```console:
$ sudo bazel clean

$ ./configure

WARNING: --batch mode is deprecated. Please instead explicitly shut down your Bazel server using the command "bazel shutdown".
You have bazel 0.24.1- (@non-git) installed.
Please specify the location of python. [Default is /usr/bin/python]: /usr/bin/python3


Found possible Python library paths:
  /opt/intel/openvino_2019.2.242/python/python3
  /opt/intel/openvino_2019.2.242/python/python3.5
  /home/b920405/git/caffe-jacinto/python
  /opt/intel/openvino_2019.2.242/deployment_tools/model_optimizer
  .
  /opt/movidius/caffe/python
  /usr/lib/python3/dist-packages
  /usr/local/lib/python3.5/dist-packages
  /usr/local/lib
Please input the desired Python library path to use.  Default is [/opt/intel/openvino_2019.2.242/python/python3]
/usr/local/lib/python3.5/dist-packages
Do you wish to build TensorFlow with XLA JIT support? [Y/n]: n
No XLA JIT support will be enabled for TensorFlow.

Do you wish to build TensorFlow with OpenCL SYCL support? [y/N]: n
No OpenCL SYCL support will be enabled for TensorFlow.

Do you wish to build TensorFlow with ROCm support? [y/N]: n
No ROCm support will be enabled for TensorFlow.

Do you wish to build TensorFlow with CUDA support? [y/N]: n
No CUDA support will be enabled for TensorFlow.

Do you wish to download a fresh release of clang? (Experimental) [y/N]: n
Clang will not be downloaded.

Do you wish to build TensorFlow with MPI support? [y/N]: n
No MPI support will be enabled for TensorFlow.

Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -march=native -Wno-sign-compare]: 


Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]: n
Not configuring the WORKSPACE for Android builds.

Preconfigured Bazel build configs. You can use any of the below by adding "--config=<>" to your build command. See .bazelrc for more details.
	--config=mkl         	# Build with MKL support.
	--config=monolithic  	# Config for mostly static monolithic build.
	--config=gdr         	# Build with GDR support.
	--config=verbs       	# Build with libverbs support.
	--config=ngraph      	# Build with Intel nGraph support.
	--config=numa        	# Build with NUMA support.
	--config=dynamic_kernels	# (Experimental) Build kernels into separate shared objects.
Preconfigured Bazel build configs to DISABLE default on features:
	--config=noaws       	# Disable AWS S3 filesystem support.
	--config=nogcp       	# Disable GCP support.
	--config=nohdfs      	# Disable HDFS support.
	--config=noignite    	# Disable Apache Ignite support.
	--config=nokafka     	# Disable Apache Kafka support.
	--config=nonccl      	# Disable NVIDIA NCCL support.
Configuration finished

$ sudo bazel build \
--config=opt \
--config=noaws \
--config=nogcp \
--config=nohdfs \
--config=noignite \
--config=nokafka \
--config=nonccl \
--copt=-ftree-vectorize \
--copt=-funsafe-math-optimizations \
--copt=-ftree-loop-vectorize \
--copt=-fomit-frame-pointer \
--remote_http_cache=https://storage.googleapis.com/bucket-bazel-tensorflow \
--google_credentials=${HOME}/bazel-caching/xxxxx-xxxxxxxxxxxx.json \
//tensorflow/tools/pip_package:build_pip_package
```
If you just fix a bug fix or build sequence without switching the OSS version or branch to build, caching seems to work well.
![Screenshot 2019-08-04 14:37:03.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/194769/dd2d5d99-094e-9024-6005-b4829572e916.png)

# ７．Appendix

```bash:bucket_object_delete_gsutil_command
gsutil -m rm -r gs://bucket-bazel-tensorflow/ac
gsutil -m rm -r gs://bucket-bazel-tensorflow/cas
```

# ８．Reference articles
**https://docs.bazel.build/versions/master/remote-caching.html**