Skip to content

Building TensorFlow Transform

linuxonz edited this page Nov 14, 2024 · 19 revisions

Building TensorFlow Transform

The instructions provided below specify the steps to build TensorFlow Transform version 1.15.0 on Linux on IBM Z for the following distributions:

  • Ubuntu (20.04, 22.04, 24.04)

General Notes:

  • When following the steps below please use a standard permission user unless otherwise specified.
  • A directory /<source_root>/ will be referred to in these instructions, this is a temporary writable directory anywhere you'd like to place it.

1. Build and Install TensorFlow Transform v1.15.0

1.1. Build using script

If you want to build TensorFlow Transform using manual steps, go to STEP 1.2.

Use the following commands to build TensorFlow Transform using the build script. Please make sure you have wget installed.

wget -q https://raw.githubusercontent.com/linux-on-ibm-z/scripts/master/TensorflowTransform/1.15.0/build_tensorflow_transform.sh

# Build TensorFlow Transform
bash build_tensorflow_transform.sh    [Provide -t option for executing build with tests, -p option for choosing the Python version from {3.9, 3.10, 3.11}, if not specified, the script will use the distro provided Python version (i.e., Python 3.11).]

If the build completes successfully, go to STEP 2. In case of error, check logs for more details or go to STEP 1.2 to follow manual build steps.

1.2. Install the dependencies

export SOURCE_ROOT=/<source_root>/
export PATCH_URL="https://raw.githubusercontent.com/linux-on-ibm-z/scripts/master/TensorflowTransform/1.15.0/patch"
  • Ubuntu 20.04

    sudo apt-get update
    sudo apt-get install -y build-essential cargo curl git libopenblas-dev libgeos-dev
  • Ubuntu 22.04

    sudo apt-get update
    sudo apt-get install -y build-essential cargo curl git cmake libopenblas-dev libgeos-dev
  • Ubuntu 24.04

    sudo apt-get update
    sudo apt-get install -y build-essential cargo curl git cmake gcc-11 g++-11 libopenblas-dev libgeos-dev
    sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 60
    sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 60

1.3. Build and Install TensorFlow 2.16.1

  • The instructions for building TensorFlow 2.16.1 can be found here.

  • Use the following commands to build TensorFlow 2.16.1 with python 3.11 which is the highest python version supported by TensorFlow Transform:

  • With python 3.9 upgrade pip version pip3 install --upgrade pip

    cd $SOURCE_ROOT
    wget -O build_tensorflow.sh https://raw.githubusercontent.com/linux-on-ibm-z/scripts/master/Tensorflow/2.16.1/build_tensorflow.sh
    bash build_tensorflow.sh -p 3.11 -y

1.4. Build and Install Apache Arrow 10.0.1

  • Build CMake 3.21.2 (only on Ubuntu 20.04)

    cd $SOURCE_ROOT
    wget https://github.com/Kitware/CMake/releases/download/v3.21.2/cmake-3.21.2.tar.gz
    tar -xzf cmake-3.21.2.tar.gz
    cd cmake-3.21.2
    ./bootstrap --prefix=/usr
    make
    sudo make install
  • Download source code

    cd $SOURCE_ROOT
    git clone -b apache-arrow-10.0.1 https://github.com/apache/arrow.git
  • Build and install Arrow C++ library

    cd $SOURCE_ROOT/arrow/cpp
    mkdir release
    cd release
    cmake -DCMAKE_INSTALL_PREFIX=/usr/local \
       -DARROW_PARQUET=ON \
       -DARROW_PYTHON=ON \
       -DCMAKE_BUILD_TYPE=Release \
       ..
    make -j$(nproc)
    sudo make install
    export LD_LIBRARY_PATH=/usr/local/lib${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
  • Build and install pyarrow library

    cd $SOURCE_ROOT/arrow/python
    curl -o pyarrow.diff ${PATCH_URL}/pyarrow.diff
    git apply pyarrow.diff
    export PYARROW_WITH_PARQUET=1
    export PYARROW_PARALLEL=4
    sed -i '2d'  requirements-build.txt
    sed -i '2a oldest-supported-numpy>=0.14; python_version<'\''3.9'\''' requirements-build.txt
    sed -i '3a numpy<2.0.0,>=1.25; python_version>='\''3.9'\''' requirements-build.txt
    sudo pip3 install -r requirements-build.txt
    python setup.py build_ext bdist_wheel
    sudo pip3 install dist/*.whl

1.5. Build and Install Apache Beam 2.53.0

  • Build and install Apache Beam

    cd $SOURCE_ROOT
    sudo GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=True pip3 install numpy==1.24.3 scipy==1.13.1 'apache-beam[gcp]'==2.53.0

1.6. Build and Install tfx-bsl 1.15.1

  • Download source code

    cd $SOURCE_ROOT
    git clone -b v1.15.1 https://github.com/tensorflow/tfx-bsl.git
  • Build and install tfx-bsl

    curl -o tfx-bsl.diff ${PATCH_URL}/tfx-bsl.diff
    cd $SOURCE_ROOT/tfx-bsl
    git apply ../tfx-bsl.diff
    
    sudo touch /usr/local/include/immintrin.h
    sed -i "178s/.*/'tensorflow>=2.15,<2.17',/" setup.py
    python3 setup.py bdist_wheel
    sudo pip3 install dist/*.whl

1.7. Install TensorFlow Transform

It is also possible to build and install TensorFlow Transform manually. This step is required if you intend to run the test cases as in Step 3.

  • Download source code

    cd $SOURCE_ROOT
    git -b v1.15.0 clone https://github.com/tensorflow/transform.git
  • Build and install

    cd $SOURCE_ROOT/transform
    sed -i "53s/.*/'tensorflow>=2.15,<2.17',/" setup.py
    sudo python3 setup.py install

Note: If any other particular version of a python package is required during installation, please run sudo pip3 install '<package-name>==<version>' to install it:

2. Verify TensorFlow Transform (Optional)

  • Install Keras

    pip3 install tf-keras
  • Run TensorFlow Transform from command Line

    $ cd $SOURCE_ROOT
    $ python3
     >>> import tensorflow as tf
     >>> import tensorflow_transform as tft
     >>> tft.version.__version__
     '1.15.0'
     >>>
  • Follow instructions in this tutorial to use TensorFlow Transform to preprocess data.

3. Execute Test Suite (Optional)

  • Run the complete testsuite

    cd $SOURCE_ROOT/transform
    python3 -m unittest discover -v -p '*_test.py'
  • Run a single test case (for example BeamImplTest.testHandleBatchError)

    cd $SOURCE_ROOT/transform
    python3 -m unittest -v tensorflow_transform/beam/impl_test.py -k BeamImplTest.testHandleBatchError

Note: Test case BeamImplTest.testNumericAnalyzersWithCompositeInputssparse_elementwise_tf.float64 fails intermittently on both s390x and Intel but will pass after an individual rerun.

References:

Clone this wiki locally