일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
- 데이터베이스
- ubuntu
- 야구
- 뉴스타파
- Git
- 문파문파
- Tizen
- 인공지능
- 해외직구
- python
- NC 다이노스
- 태그를 입력해 주세요.
- arm
- 리뷰
- 블로그
- 김경문
- 애플
- 타이젠
- 우분투
- 안드로이드
- 조세피난처
- 프로야구
- 손민한
- Linux
- 단통법
- ubuntu 12.04
- 국정원
- NC다이노스
- 문파문파 공략
- mysql
- Today
- Total
꿈꾸는 사람.
소스에서 텐서플로우 빌드 (Docker builds a TensorFlow from source.) 본문
이 글은 공식 Tensorflow를 사용할 수 없는 환경을 가진 사용자가 소스에서 빌드하여 적합한 Tensorflow를 설치하는 방법을 제시하는 것이다.
공식 커뮤니티에서 제공하는 Tensorflow 바이너리는 최신 하드웨어를 기본으로 제공되어 구형이나 최신 CPU/GPU를 지원하지 않는다.
특히 virtualbox와 같은 가상 머신은 CPU의 AVX, AVX2와 같은 CPU 명령어를 지원하지 않아 도커 기반의 Tensorflow를 실행하면 core dump의 오류가 발생하여 사용할 수 없다.
이 경우 Tensorflow 플랫폼을 다시 컴파일해야 할 때 사용할 수 있는 방법을 제공한다.
소스에서 빌드하는 방법의 개요
1. 빌드 환경을 설정
tensorflow 커뮤니티에서 제공하는 도커 이미지를 받고 실행한다.
2. 최신 tensorflow 소스를 받고 환경 설정
tensorflow소스를 받고 특정 버전으로 변경
python 종속성을 설치
3. 개발 환경에 맞게 bazel 설정
bazel 배포 URI를 apt 저장소에 추가
bazel 빌드 구성
개발 환경에 맞는 bazel 빌드 플래그 선택
4. 개발 환경용 bazel 로 빌드
선택한 플래그로 pip 패키지 만들 도구를 빌드한다.
빌드 시간이 아주 오래 걸린다.
5. 도구를 실행하여 whl 파일로 pip 패키지를 만든다.
6. Tensorflow를 새로 설치하고 확인
7. 도커 컨테이너의 변경을 이미지에 반영한다.
소스에서 빌드하는 상세한 방법
1. 빌드 환경을 설정한다.
최신 개발 이미지인 tensorflow/tensorflow:devel를 받고 실행한다.
- 도커 이미지 받기
$ docker pull tensorflow/tensorflow:devel
- 도커 이미지 실행
$ docker run -it -w /tensorflow_src -v $PWD:/mnt -e HOST_PERMS="$(id -u):$(id -g)" tensorflow/tensorflow:devel bash
2. 최신 tensorflow 소스를 받고 환경 설정을 한다.
- tensorflow 소스 받기
컨테이너의 /tensorflow_src 폴더 내부에 tensorflow소스를 받고 특정 버전으로 변경
/tensorflow_src# git pull
/tensorflow_src# git checkout r2.4
- python 종속성을 설치
tensorflow 사이트의 공식 설치 문서에는 도커에서 python 종속성 설치가 없다.
pip 패키지로 빌드하는 과정을 참고하여 누락된 패키지(keras_applications 등)을 설치한다.
필수 패키지는 pip, six numpy wheel setuptools mock future keras-applications keras_preprocessing들이다.
/tensorflow_src# pip install keras-applications --no-deps
3. 개발 환경에 맞게 bazel 설정
virtualbox 상의 우분투 20.04에서 빌드 시간이 반나절 이상 걸린다.
이때 bazel 빌드 중 오류가 발생하면 많은 시간을 버리게 되어 bazel 설치를 진행하였다.
- bazel 배포 URI를 apt 저장소에 추가 (선택)
/tensorflow_src# sudo apt install curl gnupg
/tensorflow_src# curl -fsSL https://bazel.build/bazel-release.pub.gpg | gpg --dearmor > bazel.gpg
/tensorflow_src# mv bazel.gpg /etc/apt/trusted.gpg.d/
/tensorflow_src# echo "deb [arch=amd64] https://storage.googleapis.com/bazel-apt stable jdk1.8" | tee /etc/apt/sources.list.d/baze.list
- bazel 빌드 구성
tensorflow_src 경로에서 configure를 실행하여 시스템 빌드를 구성한다.
- bazel 빌드 플래그 확인
개발 환경은 프로젝트 수행 환경에 따라 다르며 개발자 별로도 다른 것이 일반적이다.
각 CPU 별로 설정할 빌드 플래그를 올바르게 선택하는 것이 핵심이다.
다음과 같이 CPU의 마이크로 아키텍처를 확인할 수 있다.
/tensorflow_src# cat /sys/devices/cpu/caps/pmu_name
skylake
/tensorflow_src# grep flags -m1 /proc/cpuinfo | cut -d ":" -f 2
또한 virtualbox를 사용하는 경우 FMA 명령어와 AVX를 지원하지 않으므로 관련 플래그 설정을 추가한다.
4. 개발 환경용 bazel 로 빌드
선택한 플래그로 pip 패키지 만들 도구를 빌드한다.
아래 예는 windows 10 상에 virtualbox에 설치된 ubuntu 20.04에서 가져온 도커에서 실행한 빌드 명령이다.
/tensorflow_src# bazel build --config=opt --copt=-mno-fma4 --copt=-mno-avx --copt=-mno-avx2 //tensorflow/tools/pip_package:build_pip_package
빌드 시간이 아주 오래 걸리므로 빌드 전에 최적의 상태를 만들어 둔다.
5. 도구를 실행하여 whl 파일로 pip 패키지를 만든다.
도커 실행할 때 볼륨을 바인딩한 경로에 wheel 파일을 만든다.
그리고 컨테이너 실행 시 설정한 사용자 권한으로 파일 소유권을 변경한다.
/tensorflow_src# ./bazel-bin/tensorflow/tools/pip_package/build_pip_package $PWD:/mnt
/tensorflow_src# chown $HOST_PERMS /mnt/tensorflow-2.4.1-cp36-cp36m-linux_x86_64.whl
6. Tensorflow를 새로 설치하고 확인
이전에 설치된 tensorflow가 있다면 삭제하고 새롭게 빌드한 것을 설치한다.
설치 후 동작을 확인한다.
/tensorflow_src# pip uninstall tensorflow
/tensorflow_src# pip install /mnt/tensorflow-2.4.1-cp36-cp36m-linux_x86_64whl
/tensorflow_src# python -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))"
7. 도커 컨테이너의 변경을 이미지에 반영한다.
아래 명령으로 이전 단계에서 새로 빌드하고 설치한 텐서플로우를 도커 이미지로 반영해야 한다.
$ docker ps -a # 이전 단계에서 중단한 도커 컨테이너 ID 확인
$ docker commit 5d3cedb351df # 변경한 도커 컨테이너를 새 이미지로 커밋
$ docker tag ebca879230b10a943fa3b35a2ed6544a44b3dc82bf75a9a0450f68531c1db5db tfvbox # 커밋한 이미지에 태그를 만든다.
부록
실제 설치 로그를 아래에 추가한다.
1. 도커 이미지 받고 실행하기
2. 최신 TensorFlow 소스를 받고 환경 설정을 한다.
- tensorflow 소스 받기
root@5d3cedb351df:/tensorflow_src# git pull
remote: Enumerating objects: 1053, done.
remote: Counting objects: 100% (1053/1053), done.
remote: Compressing objects: 100% (14/14), done.
remote: Total 1266 (delta 1041), reused 1048 (delta 1039), pack-reused 213
Receiving objects: 100% (1266/1266), 272.17 KiB | 591.00 KiB/s, done.
Resolving deltas: 100% (1102/1102), completed with 517 local objects.
From https://github.com/tensorflow/tensorflow
43f5aec62fd..d9613ebb701 master -> origin/master
8820d650ad2..5b8ebdd51cb nightly -> origin/nightly
5c849f2550d..85c8b2a817f r2.4 -> origin/r2.4
Updating 43f5aec62fd..d9613ebb701
Fast-forward
.bazelrc | 33 +
RELEASE.md | 2 +
tensorflow/BUILD | 6 +
tensorflow/c/eager/c_api_test.cc | 6 +-
tensorflow/c/eager/gradients_test.cc | 622 +------------------
tensorflow/c/experimental/gradients/BUILD | 27 +
.../c/experimental/gradients/grad_test_helper.cc | 26 +
.../c/experimental/gradients/grad_test_helper.h | 3 +
...
create mode 100644 tensorflow/lite/micro/tools/ci_build/tflm_bazel/WORKSPACE
create mode 100644 tensorflow/lite/micro/tools/ci_build/tflm_bazel/tensorflow.bzl
create mode 100644 tensorflow/lite/micro/tools/ci_build/tflm_bazel/workspace.bzl
create mode 100644 tensorflow/lite/micro/tools/make/ext_libs/cmsis-nn.inc
delete mode 100644 tensorflow/lite/micro/tools/make/ext_libs/cmsis_nn.inc
create mode 100644 tensorflow/lite/micro/tools/make/ext_libs/ethos-u.inc
delete mode 100644 tensorflow/lite/micro/tools/make/ext_libs/ethosu.inc
create mode 100644 tensorflow/security/fuzzing/raggedCountSparseOutput_fuzz.py
root@5d3cedb351df:/tensorflow_src#
- 특정 버전의 소스로 변경
$ root@5d3cedb351df:/tensorflow_src# git checkout r2.4
Branch 'r2.4' set up to track remote branch 'r2.4' from 'origin'.
Switched to a new branch 'r2.4'
- Python 패키지 종속성 확인
3. 개발 환경에 맞게 bazel 설정
- Bazel 배포 URI를 apt 저장소에 추가
root@5d3cedb351df:/tensorflow_src# python configure.py
WARNING: current bazel installation is not a release version.
Make sure you are running at least bazel 3.1.0
Please specify the location of python. [Default is /usr/local/bin/python]:
Found possible Python library paths:
/usr/lib/python3/dist-packages
/usr/local/lib/python3.6/dist-packages
Please input the desired Python library path to use. Default is [/usr/lib/python3/dist-packages]
/usr/local/lib/python3.6/dist-packages
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.
Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -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=mkl_aarch64 # Build with oneDNN support for Aarch64.
--config=monolithic # Config for mostly static monolithic build.
--config=ngraph # Build with Intel nGraph support.
--config=numa # Build with NUMA support.
--config=dynamic_kernels # (Experimental) Build kernels into separate shared objects.
--config=v2 # Build TensorFlow 2.x instead of 1.x.
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=nonccl # Disable NVIDIA NCCL support.
root@5d3cedb351df:/tensorflow_src#
- bazel 빌드 구성
root@5d3cedb351df:~# ls -al /etc/apt/trusted.gpg.d/
total 20
drwxr-xr-x 2 root root 4096 Nov 19 13:09 .
drwxr-xr-x 1 root root 4096 Nov 19 13:09 ..
-rw-r--r-- 1 root root 2796 Sep 17 2018 ubuntu-keyring-2012-archive.gpg
-rw-r--r-- 1 root root 2794 Sep 17 2018 ubuntu-keyring-2012-cdimage.gpg
-rw-r--r-- 1 root root 1733 Sep 17 2018 ubuntu-keyring-2018-archive.gpg
root@5d3cedb351df:~# sudo apt install curl gnupg
Reading package lists... Done
Building dependency tree
Reading state information... Done
curl is already the newest version (7.58.0-2ubuntu3.12).
The following additional packages will be installed:
dirmngr gnupg-l10n gnupg-utils gpg-agent gpg-wks-client gpg-wks-server gpgsm
libksba8 libnpth0 pinentry-curses
Suggested packages:
dbus-user-session libpam-systemd pinentry-gnome3 tor parcimonie xloadimage
scdaemon pinentry-doc
The following NEW packages will be installed:
dirmngr gnupg gnupg-l10n gnupg-utils gpg-agent gpg-wks-client gpg-wks-server
gpgsm libksba8 libnpth0 pinentry-curses
0 upgraded, 11 newly installed, 0 to remove and 7 not upgraded.
Need to get 1497 kB of archives.
After this operation, 4429 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://archive.ubuntu.com/ubuntu bionic/main amd64 libksba8 amd64 1.3.5-2 [92.6 kB]
Get:2 http://archive.ubuntu.com/ubuntu bionic/main amd64 libnpth0 amd64 1.5-3 [7668 B]
Get:3 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 dirmngr amd64 2.2.4-1ubuntu1.3 [316 kB]
Get:4 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 gnupg-l10n all 2.2.4-1ubuntu1.3 [49.7 kB]
Get:5 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 gnupg-utils amd64 2.2.4-1ubuntu1.3 [127 kB]
Get:6 http://archive.ubuntu.com/ubuntu bionic/main amd64 pinentry-curses amd64 1.1.0-1 [35.8 kB]
Get:7 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 gpg-agent amd64 2.2.4-1ubuntu1.3 [227 kB]
Get:8 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 gpg-wks-client amd64 2.2.4-1ubuntu1.3 [91.8 kB]
Get:9 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 gpg-wks-server amd64 2.2.4-1ubuntu1.3 [85.0 kB]
Get:10 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 gpgsm amd64 2.2.4-1ubuntu1.3 [215 kB]
Get:11 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 gnupg amd64 2.2.4-1ubuntu1.3 [249 kB]
Fetched 1497 kB in 7s (206 kB/s)
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package libksba8:amd64.
(Reading database ... 30704 files and directories currently installed.)
Preparing to unpack .../00-libksba8_1.3.5-2_amd64.deb ...
Unpacking libksba8:amd64 (1.3.5-2) ...
Selecting previously unselected package libnpth0:amd64.
Preparing to unpack .../01-libnpth0_1.5-3_amd64.deb ...
Unpacking libnpth0:amd64 (1.5-3) ...
Selecting previously unselected package dirmngr.
Preparing to unpack .../02-dirmngr_2.2.4-1ubuntu1.3_amd64.deb ...
Unpacking dirmngr (2.2.4-1ubuntu1.3) ...
Selecting previously unselected package gnupg-l10n.
Preparing to unpack .../03-gnupg-l10n_2.2.4-1ubuntu1.3_all.deb ...
Unpacking gnupg-l10n (2.2.4-1ubuntu1.3) ...
Selecting previously unselected package gnupg-utils.
Preparing to unpack .../04-gnupg-utils_2.2.4-1ubuntu1.3_amd64.deb ...
Unpacking gnupg-utils (2.2.4-1ubuntu1.3) ...
Selecting previously unselected package pinentry-curses.
Preparing to unpack .../05-pinentry-curses_1.1.0-1_amd64.deb ...
Unpacking pinentry-curses (1.1.0-1) ...
Selecting previously unselected package gpg-agent.
Preparing to unpack .../06-gpg-agent_2.2.4-1ubuntu1.3_amd64.deb ...
Unpacking gpg-agent (2.2.4-1ubuntu1.3) ...
Selecting previously unselected package gpg-wks-client.
Preparing to unpack .../07-gpg-wks-client_2.2.4-1ubuntu1.3_amd64.deb ...
Unpacking gpg-wks-client (2.2.4-1ubuntu1.3) ...
Selecting previously unselected package gpg-wks-server.
Preparing to unpack .../08-gpg-wks-server_2.2.4-1ubuntu1.3_amd64.deb ...
Unpacking gpg-wks-server (2.2.4-1ubuntu1.3) ...
Selecting previously unselected package gpgsm.
Preparing to unpack .../09-gpgsm_2.2.4-1ubuntu1.3_amd64.deb ...
Unpacking gpgsm (2.2.4-1ubuntu1.3) ...
Selecting previously unselected package gnupg.
Preparing to unpack .../10-gnupg_2.2.4-1ubuntu1.3_amd64.deb ...
Unpacking gnupg (2.2.4-1ubuntu1.3) ...
Setting up libnpth0:amd64 (1.5-3) ...
Setting up libksba8:amd64 (1.3.5-2) ...
Setting up gnupg-l10n (2.2.4-1ubuntu1.3) ...
Setting up gpgsm (2.2.4-1ubuntu1.3) ...
Setting up gnupg-utils (2.2.4-1ubuntu1.3) ...
Setting up pinentry-curses (1.1.0-1) ...
Setting up dirmngr (2.2.4-1ubuntu1.3) ...
Setting up gpg-agent (2.2.4-1ubuntu1.3) ...
Setting up gpg-wks-server (2.2.4-1ubuntu1.3) ...
Setting up gpg-wks-client (2.2.4-1ubuntu1.3) ...
Setting up gnupg (2.2.4-1ubuntu1.3) ...
Processing triggers for libc-bin (2.27-3ubuntu1.3) ...
root@5d3cedb351df:~#
root@5d3cedb351df:~# curl -fsSL https://bazel.build/bazel-release.pub.gpg | gpg --dearmor > bazel.gpg
root@5d3cedb351df:~# mv bazel.gpg /etc/apt/trusted.gpg.d/
root@5d3cedb351df:~# echo "deb [arch=amd64] https://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list
deb [arch=amd64] https://storage.googleapis.com/bazel-apt stable jdk1.8
root@5d3cedb351df:~# ls -al /etc/apt/trusted.gpg.d/
total 28
drwxr-xr-x 1 root root 4096 Jan 21 08:56 .
drwxr-xr-x 1 root root 4096 Nov 19 13:09 ..
-rw-r--r-- 1 root root 2304 Jan 21 08:56 bazel.gpg
-rw-r--r-- 1 root root 2796 Sep 17 2018 ubuntu-keyring-2012-archive.gpg
-rw-r--r-- 1 root root 2794 Sep 17 2018 ubuntu-keyring-2012-cdimage.gpg
-rw-r--r-- 1 root root 1733 Sep 17 2018 ubuntu-keyring-2018-archive.gpg
root@5d3cedb351df:~#
4. 개발 환경용 bazel 로 빌드
- bazel 빌드로 pip 패키지 만드는 도구 빌드
root@5d3cedb351df:/tensorflow_src# bazel build --config=opt --copt=-mno-fma4 --copt=-mno-avx --copt=-mno-avx2 //tensorflow/tools/pip_package:build_pip_package
ERROR: The project you're trying to build requires Bazel 3.1.0 (specified in /tensorflow_src/.bazelversion), but it wasn't found in /usr/local/lib/bazel/bin.
Bazel binaries for all official releases can be downloaded from here:
https://github.com/bazelbuild/bazel/releases
You can download the required version directly using this command:
(cd "/usr/local/lib/bazel/bin" && curl -fLO https://releases.bazel.build/3.1.0/release/bazel-3.1.0-linux-x86_64 && chmod +x bazel-3.1.0-linux-x86_64)
root@5d3cedb351df:/tensorflow_src# whereis bazel
bazel: /usr/local/bin/bazel /usr/local/lib/bazel
root@5d3cedb351df:/tensorflow_src# cd /usr/local/lib/bazel/bin/
root@5d3cedb351df:/usr/local/lib/bazel/bin# curl -fLO https://releases.bazel.build/3.1.0/release/bazel-3.1.0-linux-x86_64
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 43.2M 100 43.2M 0 0 9694k 0 0:00:04 0:00:04 --:--:-- 9694k
root@5d3cedb351df:/usr/local/lib/bazel/bin# chmod +x bazel-3.1.0-linux-x86_64
root@5d3cedb351df:/usr/local/lib/bazel/bin#
root@5d3cedb351df:/usr/local/lib/bazel/bin# ls -al baz*
-rwxr-xr-x 1 root root 8678 Jan 1 1980 bazel
-rwxr-xr-x 1 root root 45327849 Jan 21 09:14 bazel-3.1.0-linux-x86_64
-rwxr-xr-x 1 root root 339462 Jan 1 1980 bazel-complete.bash
-rwxr-xr-x 1 root root 47154615 Jan 1 1980 bazel-real
-rw-r--r-- 1 root root 5305 Jan 1 1980 bazel.fish
root@5d3cedb351df:/tensorflow_src# bazel build --config=opt --copt=-mno-fma4 --copt=-mno-avx --copt=-mno-avx2 //tensorflow/tools/pip_package:build_pip_package
Extracting Bazel installation...
Starting local Bazel server and connecting to it...
INFO: Options provided by the client:
Inherited 'common' options: --isatty=1 --terminal_columns=80
INFO: Reading rc options for 'build' from /tensorflow_src/.bazelrc:
Inherited 'common' options: --experimental_repo_remote_exec
INFO: Reading rc options for 'build' from /tensorflow_src/.bazelrc:
'build' options: --apple_platform_type=macos --define framework_shared_object=true --define open_source_build=true --java_toolchain=//third_party/toolchains/java:tf_java_toolchain --host_java_toolchain=//third_party/toolchains/java:tf_java_toolchain --define=tensorflow_enable_mlir_generated_gpu_kernels=0 --define=use_fast_cpp_protos=true --define=allow_oversize_protos=true --spawn_strategy=standalone -c opt --announce_rc --define=grpc_no_ares=true --noincompatible_remove_legacy_whole_archive --noincompatible_prohibit_aapt1 --enable_platform_specific_config --config=short_logs --config=v2
INFO: Reading rc options for 'build' from /tensorflow_src/.tf_configure.bazelrc:
'build' options: --action_env PYTHON_BIN_PATH=/usr/local/bin/python --action_env PYTHON_LIB_PATH=/usr/local/lib/python3.6/dist-packages --python_path=/usr/local/bin/python --config=xla --action_env TF_CONFIGURE_IOS=0
INFO: Found applicable config definition build:short_logs in file /tensorflow_src/.bazelrc: --output_filter=DONT_MATCH_ANYTHING
INFO: Found applicable config definition build:v2 in file /tensorflow_src/.bazelrc: --define=tf_api_version=2 --action_env=TF2_BEHAVIOR=1
INFO: Found applicable config definition build:xla in file /tensorflow_src/.bazelrc: --define=with_xla_support=true
INFO: Found applicable config definition build:opt in file /tensorflow_src/.tf_configure.bazelrc: --copt=-Wno-sign-compare --host_copt=-Wno-sign-compare --define with_default_optimizations=true
INFO: Found applicable config definition build:linux in file /tensorflow_src/.bazelrc: --copt=-w --host_copt=-w --define=PREFIX=/usr --define=LIBDIR=$(PREFIX)/lib --define=INCLUDEDIR=$(PREFIX)/include --define=PROTOBUF_INCLUDE_PATH=$(PREFIX)/include --cxxopt=-std=c++14 --host_cxxopt=-std=c++14 --config=dynamic_kernels
INFO: Found applicable config definition build:dynamic_kernels in file /tensorflow_src/.bazelrc: --define=dynamic_loaded_kernels=true --copt=-DAUTOLOAD_DYNAMIC_KERNELS
DEBUG: Rule 'io_bazel_rules_go' indicated that a canonical reproducible form can be obtained by modifying arguments shallow_since = "1557349968 -0400"
DEBUG: Repository io_bazel_rules_go instantiated at:
no stack (--record_rule_instantiation_callstack not enabled)
Repository rule git_repository defined at:
/root/.cache/bazel/_bazel_root/43801f1e35f242fb634ebbc6079cf6c5/external/bazel_tools/tools/build_defs/repo/git.bzl:195:18: in <toplevel>
DEBUG: Rule 'io_bazel_rules_docker' indicated that a canonical reproducible form can be obtained by modifying arguments shallow_since = "1556410077 -0400"
DEBUG: Repository io_bazel_rules_docker instantiated at:
no stack (--record_rule_instantiation_callstack not enabled)
Repository rule git_repository defined at:
/root/.cache/bazel/_bazel_root/43801f1e35f242fb634ebbc6079cf6c5/external/bazel_tools/tools/build_defs/repo/git.bzl:195:18: in <toplevel>
WARNING: Download from https://mirror.bazel.build/github.com/aws/aws-sdk-cpp/archive/1.7.336.tar.gz failed: class com.google.devtools.build.lib.bazel.repository.downloader.UnrecoverableHttpException GET returned 404 Not Found
WARNING: Download from https://storage.googleapis.com/mirror.tensorflow.org/www.sqlite.org/2020/sqlite-amalgamation-3340000.zip failed: class com.google.devtools.build.lib.bazel.repository.downloader.UnrecoverableHttpException GET returned 404 Not Found
WARNING: Download from https://storage.googleapis.com/mirror.tensorflow.org/github.com/llvm/llvm-project/archive/f402e682d0ef5598eeffc9a21a691b03e602ff58.tar.gz failed: class com.google.devtools.build.lib.bazel.repository.downloader.UnrecoverableHttpException GET returned 404 Not Found
INFO: Analyzed target //tensorflow/tools/pip_package:build_pip_package (403 packages loaded, 31111 targets configured).
INFO: Found 1 target...
Target //tensorflow/tools/pip_package:build_pip_package up-to-date:
bazel-bin/tensorflow/tools/pip_package/build_pip_package
INFO: Elapsed time: 10097.827s, Critical Path: 396.10s
INFO: 15645 processes: 15645 local.
INFO: Build completed successfully, 16939 total actions
root@5d3cedb351df:/tensorflow_src#
5. 도구를 실행하여 whl 파일로 pip 패키지를 만든다.
# tensorflow 패키지를 빌드
root@5d3cedb351df:/tensorflow_src# ./bazel-bin/tensorflow/tools/pip_package/build_pip_package /mnt
Fri Jan 22 05:57:15 UTC 2021 : === Preparing sources in dir: /tmp/tmp.QEVhhmoibj
/tensorflow_src /tensorflow_src
/tensorflow_src
/tensorflow_src/bazel-bin/tensorflow/tools/pip_package/build_pip_package.runfiles/org_tensorflow /tensorflow_src
/tensorflow_src
/tmp/tmp.QEVhhmoibj/tensorflow/include /tensorflow_src
/tensorflow_src
Fri Jan 22 05:58:18 UTC 2021 : === Building wheel
warning: no files found matching 'README'
warning: no files found matching '*.pyd' under directory '*'
warning: no files found matching '*.pyi' under directory '*'
warning: no files found matching '*.pd' under directory '*'
warning: no files found matching '*.dylib' under directory '*'
warning: no files found matching '*.dll' under directory '*'
warning: no files found matching '*.lib' under directory '*'
warning: no files found matching '*.csv' under directory '*'
warning: no files found matching '*.h' under directory 'tensorflow/include/tensorflow'
warning: no files found matching '*.proto' under directory 'tensorflow/include/tensorflow'
warning: no files found matching '*' under directory 'tensorflow/include/third_party'
Fri Jan 22 05:59:03 UTC 2021 : === Output wheel file is in: /mnt
# tensorflow 패키지의 소유권을 도커 실행 시 설정한 사용자로 변경한다.
root@5d3cedb351df:/tensorflow_src# ls -l /mnt/tensorflow-2.4.1-cp36-cp36m-linux_x86_64.whl
-rw-r--r-- 1 root root 132856106 Jan 22 05:59 /mnt/tensorflow-2.4.1-cp36-cp36m-linux_x86_64.whl
root@5d3cedb351df:/tensorflow_src# chown $HOST_PERMS /mnt/tensorflow-2.4.1-cp36-cp36m-linux_x86_64.whl
root@5d3cedb351df:/tensorflow_src# ls -l /mnt/tensorflow-2.4.1-cp36-cp36m-linux_x86_64.whl
-rw-r--r-- 1 1000 1000 132856106 Jan 22 05:59 /mnt/tensorflow-2.4.1-cp36-cp36m-linux_x86_64.whl
6. Tensorflow를 새로 설치하고 확인
# 컨테이너 내에서 tensorflow 설치
root@5d3cedb351df:/tensorflow_src# pip uninstall tensorflow
WARNING: Skipping tensorflow as it is not installed.
root@5d3cedb351df:/tensorflow_src# pip install /mnt/tensorflow-2.4.1-cp36-cp36m-linux_x86_64.whl
Processing /mnt/tensorflow-2.4.1-cp36-cp36m-linux_x86_64.whl
Requirement already satisfied: keras-preprocessing~=1.1.2 in /usr/local/lib/python3.6/dist-packages (from tensorflow==2.4.1) (1.1.2)
Collecting gast==0.3.3
Downloading gast-0.3.3-py2.py3-none-any.whl (9.7 kB)
Collecting absl-py~=0.10
Downloading absl_py-0.11.0-py3-none-any.whl (127 kB)
|████████████████████████████████| 127 kB 1.7 MB/s
Collecting astunparse~=1.6.3
Downloading astunparse-1.6.3-py2.py3-none-any.whl (12 kB)
Collecting flatbuffers~=1.12.0
Downloading flatbuffers-1.12-py2.py3-none-any.whl (15 kB)
Collecting google-pasta~=0.2
Downloading google_pasta-0.2.0-py3-none-any.whl (57 kB)
|████████████████████████████████| 57 kB 1.9 MB/s
Collecting grpcio~=1.32.0
Downloading grpcio-1.32.0-cp36-cp36m-manylinux2014_x86_64.whl (3.8 MB)
|████████████████████████████████| 3.8 MB 5.0 MB/s
Collecting h5py~=2.10.0
Downloading h5py-2.10.0-cp36-cp36m-manylinux1_x86_64.whl (2.9 MB)
|████████████████████████████████| 2.9 MB 3.9 MB/s
Collecting numpy~=1.19.2
Downloading numpy-1.19.5-cp36-cp36m-manylinux2010_x86_64.whl (14.8 MB)
|████████████████████████████████| 14.8 MB 111 kB/s
Collecting opt-einsum~=3.3.0
Downloading opt_einsum-3.3.0-py3-none-any.whl (65 kB)
|████████████████████████████████| 65 kB 1.5 MB/s
Collecting protobuf>=3.9.2
Downloading protobuf-3.14.0-cp36-cp36m-manylinux1_x86_64.whl (1.0 MB)
|████████████████████████████████| 1.0 MB 2.9 MB/s
Collecting six~=1.15.0
Downloading six-1.15.0-py2.py3-none-any.whl (10 kB)
Collecting tensorboard~=2.4
Downloading tensorboard-2.4.1-py3-none-any.whl (10.6 MB)
|████████████████████████████████| 10.6 MB 168 kB/s
Requirement already satisfied: setuptools>=41.0.0 in /usr/local/lib/python3.6/dist-packages (from tensorboard~=2.4->tensorflow==2.4.1) (51.3.3)
Collecting google-auth<2,>=1.6.3
Downloading google_auth-1.24.0-py2.py3-none-any.whl (114 kB)
|████████████████████████████████| 114 kB 3.0 MB/s
Collecting cachetools<5.0,>=2.0.0
Downloading cachetools-4.2.0-py3-none-any.whl (12 kB)
Collecting google-auth-oauthlib<0.5,>=0.4.1
Downloading google_auth_oauthlib-0.4.2-py2.py3-none-any.whl (18 kB)
Collecting markdown>=2.6.8
Downloading Markdown-3.3.3-py3-none-any.whl (96 kB)
|████████████████████████████████| 96 kB 2.0 MB/s
Collecting pyasn1-modules>=0.2.1
Downloading pyasn1_modules-0.2.8-py2.py3-none-any.whl (155 kB)
|████████████████████████████████| 155 kB 2.9 MB/s
Collecting pyasn1<0.5.0,>=0.4.6
Downloading pyasn1-0.4.8-py2.py3-none-any.whl (77 kB)
|████████████████████████████████| 77 kB 2.1 MB/s
Collecting requests<3,>=2.21.0
Downloading requests-2.25.1-py2.py3-none-any.whl (61 kB)
|████████████████████████████████| 61 kB 3.1 MB/s
Requirement already satisfied: idna<3,>=2.5 in /usr/lib/python3/dist-packages (from requests<3,>=2.21.0->tensorboard~=2.4->tensorflow==2.4.1) (2.6)
Collecting certifi>=2017.4.17
Downloading certifi-2020.12.5-py2.py3-none-any.whl (147 kB)
|████████████████████████████████| 147 kB 3.4 MB/s
Collecting chardet<5,>=3.0.2
Downloading chardet-4.0.0-py2.py3-none-any.whl (178 kB)
|████████████████████████████████| 178 kB 2.0 MB/s
Collecting requests-oauthlib>=0.7.0
Downloading requests_oauthlib-1.3.0-py2.py3-none-any.whl (23 kB)
Collecting oauthlib>=3.0.0
Downloading oauthlib-3.1.0-py2.py3-none-any.whl (147 kB)
|████████████████████████████████| 147 kB 2.6 MB/s
Collecting rsa<5,>=3.1.4
Downloading rsa-4.7-py3-none-any.whl (34 kB)
Collecting tensorboard-plugin-wit>=1.6.0
Downloading tensorboard_plugin_wit-1.8.0-py3-none-any.whl (781 kB)
|████████████████████████████████| 781 kB 3.4 MB/s
Collecting tensorflow-estimator<2.5.0,>=2.4.0
Downloading tensorflow_estimator-2.4.0-py2.py3-none-any.whl (462 kB)
|████████████████████████████████| 462 kB 3.2 MB/s
Collecting termcolor~=1.1.0
Downloading termcolor-1.1.0.tar.gz (3.9 kB)
Collecting typing-extensions~=3.7.4
Downloading typing_extensions-3.7.4.3-py3-none-any.whl (22 kB)
Collecting urllib3<1.27,>=1.21.1
Downloading urllib3-1.26.2-py2.py3-none-any.whl (136 kB)
|████████████████████████████████| 136 kB 3.5 MB/s
Collecting werkzeug>=0.11.15
Downloading Werkzeug-1.0.1-py2.py3-none-any.whl (298 kB)
|████████████████████████████████| 298 kB 3.7 MB/s
Collecting wheel~=0.35
Downloading wheel-0.36.2-py2.py3-none-any.whl (35 kB)
Collecting wrapt~=1.12.1
Downloading wrapt-1.12.1.tar.gz (27 kB)
Collecting importlib-metadata
Downloading importlib_metadata-3.4.0-py3-none-any.whl (10 kB)
Collecting zipp>=0.5
Downloading zipp-3.4.0-py3-none-any.whl (5.2 kB)
Building wheels for collected packages: termcolor, wrapt
Building wheel for termcolor (setup.py) ... done
Created wheel for termcolor: filename=termcolor-1.1.0-py3-none-any.whl size=5679 sha256=02ef2a9e79c75b8b77de69474280435d7d71e77d27839d71b858fbbd0c516108
Stored in directory: /root/.cache/pip/wheels/93/2a/eb/e58dbcbc963549ee4f065ff80a59f274cc7210b6eab962acdc
Building wheel for wrapt (setup.py) ... done
Created wheel for wrapt: filename=wrapt-1.12.1-cp36-cp36m-linux_x86_64.whl size=69374 sha256=3b574a983f2e6520a22ce9960dcacc02ad5fda9067769e23a97c8c111e05d58b
Stored in directory: /root/.cache/pip/wheels/32/42/7f/23cae9ff6ef66798d00dc5d659088e57dbba01566f6c60db63
Successfully built termcolor wrapt
Installing collected packages: urllib3, pyasn1, chardet, certifi, zipp, typing-extensions, six, rsa, requests, pyasn1-modules, oauthlib, cachetools, requests-oauthlib, importlib-metadata, google-auth, wheel, werkzeug, tensorboard-plugin-wit, protobuf, numpy, markdown, grpcio, google-auth-oauthlib, absl-py, wrapt, termcolor, tensorflow-estimator, tensorboard, opt-einsum, h5py, google-pasta, gast, flatbuffers, astunparse, tensorflow
Attempting uninstall: six
Found existing installation: six 1.11.0
Uninstalling six-1.11.0:
Successfully uninstalled six-1.11.0
Attempting uninstall: wheel
Found existing installation: wheel 0.30.0
Uninstalling wheel-0.30.0:
Successfully uninstalled wheel-0.30.0
Attempting uninstall: numpy
Found existing installation: numpy 1.18.5
Uninstalling numpy-1.18.5:
Successfully uninstalled numpy-1.18.5
Attempting uninstall: h5py
Found existing installation: h5py 3.1.0
Uninstalling h5py-3.1.0:
Successfully uninstalled h5py-3.1.0
Successfully installed absl-py-0.11.0 astunparse-1.6.3 cachetools-4.2.0 certifi-2020.12.5 chardet-4.0.0 flatbuffers-1.12 gast-0.3.3 google-auth-1.24.0 google-auth-oauthlib-0.4.2 google-pasta-0.2.0 grpcio-1.32.0 h5py-2.10.0 importlib-metadata-3.4.0 markdown-3.3.3 numpy-1.19.5 oauthlib-3.1.0 opt-einsum-3.3.0 protobuf-3.14.0 pyasn1-0.4.8 pyasn1-modules-0.2.8 requests-2.25.1 requests-oauthlib-1.3.0 rsa-4.7 six-1.15.0 tensorboard-2.4.1 tensorboard-plugin-wit-1.8.0 tensorflow-2.4.1 tensorflow-estimator-2.4.0 termcolor-1.1.0 typing-extensions-3.7.4.3 urllib3-1.26.2 werkzeug-1.0.1 wheel-0.36.2 wrapt-1.12.1 zipp-3.4.0
root@5d3cedb351df:/tensorflow_src#
# 컨테이너 내에서 tensorflow 동작 확인
root@5d3cedb351df:/mnt# python -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))"
2021-01-25 09:22:56.456654: I tensorflow/compiler/jit/xla_cpu_device.cc:41] Not creating XLA devices, tf_xla_enable_xla_devices not set
2021-01-25 09:22:56.456923: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: SSE3 SSE4.1 SSE4.2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
tf.Tensor(-123.58844, shape=(), dtype=float32)
- /tensorflow_src에서 동작 확인하면 오류 발생하여 /mnt에서 실행 확인
7. 도커 컨테이너의 변경을 이미지에 반영한다.
'AI > Tensorflow' 카테고리의 다른 글
Tensorflow 기반 인공지능 개발을 위해 GPU 관련 도구 설치 (0) | 2020.02.12 |
---|