インストール

Pip によるインストール

以下を実行して TensorFlow デシジョン フォレストをインストールします。

# 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 バージョンも 1 つの特定の TensorFlow バージョンとのみ互換性があります。

すべての TensorFlow を TF-DF でコンパイルして出荷することを避けるために、TF-DF は TensorFlow の Pip パッケージで配布される libtensorflow 共有ライブラリに対してリンクします。 Tensorflow のごく一部のみがコンパイルされ、強力なワークステーションではコンパイルにかかる時間はわずか 10 分程度です (TensorFlow のすべてをコンパイルする場合は数時間かかります)。これが確実に機能するようにするには、実際にコンパイルされる TensorFlow のバージョンと libtensorflow 共有ライブラリが正確に一致する必要があります。

tools/test_bazel.shスクリプトは、使用されるパッケージのバージョンが一致するように TF-DF ビルドを構成します。この処理の詳細については、このスクリプトのソース コードを参照してください。 TensorFlow のコンパイルは頻繁に変更されるため、最新の TensorFlow バージョンと夜間のビルドのみをサポートします。

Linux

ドッカービルド

Linux 上で TF-DF をビルドする最も簡単な方法は、TensorFlow の build 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
  • Python >= 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 と互換性のあるものにする簡単な方法は、上記の Docker を使用することです。

# 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コマンドラインツール
  • バゼル(バゼリスク推奨)
  • 自作パッケージ: 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.batおよびtools/test_bazel.shを参照してください。

Windows ユーザー向けに、 YDF は公式の Windows ビルドと TF-DF のほとんどの機能 (そしてそれ以上!) を提供します。