설치

Pip으로 설치

다음을 실행하여 TensorFlow Decision Forests를 설치합니다.

# Install TensorFlow Decision Forests.
pip3 install tensorflow_decision_forests --upgrade

그런 다음 다음을 실행하여 설치를 확인합니다.

# Check the version of TensorFlow Decision Forests.
python3 -c "import tensorflow_decision_forests as tfdf; print('Found TF-DF v' + tfdf.__version__)"

소스에서 빌드

기술적 세부 사항

TensorFlow Decision Forests(TF-DF)는 TensorFlow에 대한 사용자 지정 작업을 구현하므로 TensorFlow의 ABI에 의존합니다. ABI는 버전 간에 변경될 수 있으므로 모든 TF-DF 버전은 하나의 특정 TensorFlow 버전과만 호환됩니다.

TF-DF로 모든 TensorFlow를 컴파일하고 배송하는 것을 피하기 위해 TF-DF는 TensorFlow의 Pip 패키지와 함께 배포되는 libtensorflow 공유 라이브러리에 대해 연결됩니다. Tensorflow의 작은 부분만 컴파일되며 강력한 워크스테이션에서 컴파일하는 데는 최대 10분 밖에 걸리지 않습니다(TensorFlow 전체를 컴파일하는 경우 여러 시간이 소요됨). 이것이 작동하려면 실제로 컴파일되는 TensorFlow 버전과 libtensorflow 공유 라이브러리가 정확히 일치해야 합니다.

tools/test_bazel.sh 스크립트는 사용된 패키지 버전이 일치하도록 TF-DF 빌드를 구성합니다. 이 프로세스에 대한 자세한 내용은 이 스크립트의 소스 코드를 참조하세요. TensorFlow 컴파일은 자주 변경되므로 최신 TensorFlow 버전과 야간 빌드만 지원합니다.

리눅스

도커 빌드

Linux에서 TF-DF를 빌드하는 가장 쉬운 방법은 TensorFlow의 빌드 Build docker 를 사용하는 것입니다. 빌드하려면 다음 단계를 실행하세요.

./tools/start_compile_docker.sh # Start the docker, might require root
export RUN_TESTS=1              # Whether to run tests after build
export PY_VERSION=3.9           # Python version to use for build
# TensorFlow version to compile against. This must match exactly the version
# of TensorFlow used at runtime, otherwise TF-DF may crash unexpectedly.
export TF_VERSION=2.16.1        # Set to "nightly" for building with tf-nightly
./tools/test_bazel.sh

이렇게 하면 컴파일된 C++ 코드가 bazel-bin 디렉터리에 배치됩니다. 이는 컨테이너 외부에 노출되지 않는 기호 링크입니다(즉, 컨테이너를 떠난 후 빌드가 사라짐).

바퀴를 만들려면 다음을 실행하세요.

tools/build_pip_package.sh ALL_VERSIONS INSTALL_PYENV

이렇게 하면 Docker 내부에 PyenvPyenv-virtualenv가 설치되고 이를 사용하여 빌드를 위해 지원되는 모든 버전에 Python을 설치합니다. 휠은 dist/ 하위 디렉토리에 배치됩니다.

수동 빌드

Docker 없이 TF-DF를 구축하는 것은 더 어려울 수 있으며 팀에서는 이를 지원하지 못할 수도 있습니다.

요구사항

  • 바젤 >= 6.3.0
  • 파이썬 >= 3
  • 힘내
  • Pyenv, Pyenv-virtualenv(많은 Python 버전을 패키징하는 경우에만)

건물

다음과 같이 TensorFlow 결정 포레스트를 다운로드합니다.

# Download the source code of TF-DF.
git clone https://github.com/tensorflow/decision-forests.git
cd decision-forests

선택 사항: TensorFlow 결정 포레스트는 Yggdrasil 결정 포레스트 에 따라 달라집니다. Yggdrasil 코드를 편집하려면 Yggdrasil 저장소를 복제하고 third_party/yggdrasil_decision_forests/workspace.bzl 에서 그에 따라 경로를 변경할 수 있습니다.

다음 명령을 사용하여 TF-DF의 단위 테스트를 컴파일하고 실행합니다. test_bazel.sh 는 컴퓨터의 기본 컴파일러에 대해 구성되어 있습니다. 이 구성을 변경하려면 파일을 직접 편집하세요.

# Build and test TF-DF.
RUN_TESTS=1 PY_VERSION=3.9 TF_VERSION=2.16.1 ./tools/test_bazel.sh

다음 명령을 사용하여 pip 패키지를 생성하고 테스트합니다. python3.9를 사용하려는 Python 버전으로 바꾸십시오. test_bazel.sh 스크립트와 동일한 버전의 Python을 사용할 필요는 없습니다.

구성이 Manylinux2014 와 호환되는 경우 manylinux2014 호환 pip 패키지가 생성됩니다.

구성이 Manylinux2014와 호환되지 않으면 manylinux2014 와 호환되지 않는 pip 패키지가 생성되고 최종 확인이 실패합니다. 자신의 컴퓨터에서 TF-DF를 사용하려는 경우에는 중요하지 않습니다. Manylinux2014 호환 빌드를 만드는 쉬운 방법은 위에서 언급한 도커를 사용하는 것입니다.

# Build and test a Pip package.
./tools/build_pip_package.sh python3.9

이 명령은 TF-DF pip 패키지를 설치하고 examples/minimal.py 에서 예제를 실행합니다. Pip 패키지는 dist/ 디렉터리에 있습니다.

다른 호환 가능한 Python 버전용 Pip 패키지를 생성하려면 다음을 실행하세요.

# Install the other versions of python (assume only python3.9 is installed; this is the case in the build docker).
sudo apt-get update && sudo apt-get install python3.9 python3-pip

# Create the Pip package for the other version of python
./tools/build_pip_package.sh python3.9

또는 다음 명령을 실행하여 pyenv를 사용하여 호환되는 모든 Python 버전에 대한 pip 패키지를 생성할 수 있습니다. 자세한 내용은 tools/build_pip_package.sh 헤더를 참조하세요.

# Build and test all the Pip package using Pyenv.
./tools/build_pip_package.sh ALL_VERSIONS

맥 OS

설정

요구사항

  • XCode 명령줄 도구
  • Bazel ( Bazelisk 권장)
  • Homebrew 패키지: GNU coreutils, GNU sed, GNU grep
  • Pyenv(여러 Python 버전으로 Pip 패키지 빌드용)

Arm64 CPU

ARM64 CPU가 탑재된 MacOS 시스템의 경우 다음 단계를 따르세요.

  1. 환경 준비

    git clone https://github.com/tensorflow/decision-forests.git
    python3 -m venv venv
    source venv/bin/activate
    
  2. 사용하고 실행할 Python 버전과 TensorFlow 버전을 결정하세요.

    cd decision-forests
    bazel clean --expunge            # Remove old builds (esp. cross-compiled).
    export RUN_TESTS=1               # Whether to run tests after build.
    export PY_VERSION=3.9            # Python version to use for build.
    # TensorFlow version to compile against. This must match exactly the version
    # of TensorFlow used at runtime, otherwise TF-DF may crash unexpectedly.
    export TF_VERSION=2.16.1
    ./tools/test_bazel.sh            # Takes ~15 minutes on a modern Mac.
    
  3. 빌드를 패키징합니다.

    # Building the packages uses different virtualenvs through Pyenv.
    deactivate
    # Build the packages.
    ./tools/build_pip_package.sh ALL_VERSIONS
    
  4. 패키지는 decision-forests/dist/ 에서 찾을 수 있습니다.

Intel CPU용 크로스 컴파일

Apple CPU가 탑재된 MacOS 컴퓨터가 있는 경우 다음과 같이 Intel CPU가 탑재된 MacOS 컴퓨터용 TF-DF를 크로스 컴파일하세요.

  1. 환경 준비

    git clone https://github.com/tensorflow/decision-forests.git
    python3 -m venv venv
    source venv/source/activate
    
  2. 사용하고 실행할 Python 버전을 결정하세요.

    cd decision-forests
    bazel clean --expunge            # Remove old builds (esp. cross-compiled).
    export RUN_TESTS=0               # Cross-compiled builds can't run tests.
    export PY_VERSION=3.9            # Python version to use for build.
    # TensorFlow version to compile against. This must match exactly the version
    # of TensorFlow used at runtime, otherwise TF-DF may crash unexpectedly.
    export TF_VERSION=2.16.1
    export MAC_INTEL_CROSSCOMPILE=1  # Enable cross-compilation.
    ./tools/test_bazel.sh            # Takes ~15 minutes on a modern Mac.
    
  3. 빌드를 패키징합니다.

    # Building the packages uses different virtualenvs through Pyenv.
    deactivate
    # Build the packages.
    ./tools/build_pip_package.sh ALL_VERSIONS_MAC_INTEL_CROSSCOMPILE
    
  4. 패키지는 decision-forests/dist/ 에서 찾을 수 있습니다. 아직 테스트되지 않았으므로 배포하기 전에 테스트하는 것이 현명할 것입니다.

윈도우

Windows 빌드는 과거에 성공적으로 생성되었지만 현재로서는 유지 관리되지 않습니다. Windows에서 컴파일하기 위한 (아마도 오래된) 포인터는 tools/test_bazel.battools/test_bazel.sh 를 참조하십시오.

Windows 사용자의 경우 YDF는 공식 Windows 빌드와 TF-DF의 대부분의 기능(및 그 이상!)을 제공합니다.