10
10
* [ Table of Contents] ( #table-of-contents )
11
11
* [ Installation with Pip] ( #installation-with-pip )
12
12
* [ Build from source] ( #build-from-source )
13
+ * [ Technical details] ( #technical-details )
13
14
* [ Linux] ( #linux )
14
- * [ Setup ] ( #setup )
15
- * [ Compilation ] ( #compilation )
15
+ * [ Docker build ] ( #docker-build )
16
+ * [ Manual build ] ( #manual-build )
16
17
* [ MacOS] ( #macos )
17
- * [ Setup] ( #setup-1 )
18
- * [ Building / Packaging (Apple CPU) ] ( #building---packaging-apple -cpu )
18
+ * [ Setup] ( #setup )
19
+ * [ Arm64 CPU] ( #arm64 -cpu )
19
20
* [ Cross-compiling for Intel CPUs] ( #cross-compiling-for-intel-cpus )
20
- * [ Final note] ( #final-note )
21
- * [ Troubleshooting] ( #troubleshooting )
21
+ * [ Windows] ( #windows )
22
22
23
23
<!-- te-->
24
24
@@ -44,24 +44,74 @@ python3 -c "import tensorflow_decision_forests as tfdf; print('Found TF-DF v' +
44
44
45
45
## Build from source
46
46
47
+ ### Technical details
48
+
49
+ TensorFlow Decision Forests (TF-DF) implements custom ops for TensorFlow and
50
+ therefore depends on TensorFlow's ABI. Since the ABI can change between
51
+ versions, any TF-DF version is only compatible with one specific TensorFlow
52
+ version.
53
+
54
+ To avoid compiling and shipping all of TensorFlow with TF-DF, TF-DF
55
+ links against libtensorflow shared library that is distributed with TensorFlow's
56
+ Pip package. Only a small part of Tensorflow is compiled and compilation only
57
+ takes ~ 10 minutes on a strong workstation (instead of multiple hours when
58
+ compiling all of TensorFlow). To ensure this works, the version of TensorFlow
59
+ that is actually compiled and the libtensorflow shared library must match
60
+ exactly.
61
+
62
+ The ` tools/test_bazel.sh ` script configures the TF-DF build to ensure the
63
+ versions of the packages used match. For details on this process, see the source
64
+ code of this script. Since TensorFlow compilation changes often, it only
65
+ supports building with the most recent TensorFlow versions and nightly.
66
+
67
+ ** Note** : When distributing builds, you may set the ` __git_version__ ` string in
68
+ ` tensorflow_decision_forests/__init__.py ` to identify the commit you built from.
69
+
47
70
### Linux
48
71
49
- #### Setup
72
+ #### Docker build
73
+
74
+ The easiest way to build TF-DF on Linux is by using TensorFlow's build
75
+ [ Build docker] ( https://github.com/tensorflow/build ) . Just run the following
76
+ steps to build:
77
+
78
+ ``` shell
79
+ ./tools/start_compile_docker.sh # Start the docker, might require root
80
+ export RUN_TESTS=1 # Whether to run tests after build
81
+ export PY_VERSION=3.9 # Python version to use for build
82
+ # TensorFlow version to compile against. This must match exactly the version
83
+ # of TensorFlow used at runtime, otherwise TF-DF may crash unexpectedly.
84
+ export TF_VERSION=2.16.1 # Set to "nightly" for building with tf-nightly
85
+ ./tools/test_bazel.sh
86
+ ```
87
+
88
+ This places the compiled C++ code in the ` bazel-bin ` directory. Note that this
89
+ is a symbolic link that is not exposed outside the container (i.e. the build is
90
+ gone after leaving the container).
91
+
92
+ For building the wheels, run
93
+ ``` shell
94
+ tools/build_pip_package.sh ALL_VERSIONS INSTALL_PYENV
95
+ ```
96
+
97
+ This will install [ Pyenv] ( https://github.com/pyenv/pyenv ) and
98
+ [ Pyenv-virtualenv] ( https://github.com/pyenv/pyenv-virtualenv ) inside the docker
99
+ and use it to install Python in all supported versions for building. The wheels
100
+ are placed in the ` dist/ ` subdirectory.
101
+
102
+ #### Manual build
103
+
104
+ Building TF-DF without the docker might be harder, and the team is probably not
105
+ able to help with this.
50
106
51
107
** Requirements**
52
108
53
- - Bazel >= 3.7.2
109
+ - Bazel >= 6.3.0
54
110
- Python >= 3
55
111
- Git
56
- - Python packages: numpy tensorflow pandas
57
-
58
- Instead of installing the dependencies by hands, you can use the
59
- [ TensorFlow Build docker] ( https://github.com/tensorflow/build ) . If you choose
60
- this options, install Docker:
112
+ - Pyenv, Pyenv-virtualenv (only if packaging for many Python versions)
61
113
62
- - [ Docker] ( https://docs.docker.com/get-docker/ ) .
63
-
64
- #### Compilation
114
+ ** Building**
65
115
66
116
Download TensorFlow Decision Forests as follows:
67
117
@@ -71,31 +121,22 @@ git clone https://github.com/tensorflow/decision-forests.git
71
121
cd decision-forests
72
122
```
73
123
74
- ** Optional:* * TensorFlow Decision Forests depends on
124
+ * Optional:* TensorFlow Decision Forests depends on
75
125
[ Yggdrasil Decision Forests] ( https://github.com/google/yggdrasil-decision-forests )
76
126
. If you want to edit the Yggdrasil code, you can clone the Yggdrasil repository
77
127
and change the path accordingly in
78
128
` third_party/yggdrasil_decision_forests/workspace.bzl ` .
79
129
80
- ** Optional:** If you want to use the docker option, run the
81
- ` start_compile_docker.sh ` script and continue to the next step. If you don't
82
- want to use the docker option, continue to the next step directly.
83
-
84
- ``` shell
85
- # Optional: Install and start the build docker.
86
- ./tools/start_compile_docker.sh
87
- ```
88
-
89
130
Compile and run the unit tests of TF-DF with the following command. Note that
90
- ` test_bazel.sh ` is configured for ` python3.8 ` and the default compiler on your
91
- machine. Edit the file directly to change this configuration.
131
+ ` test_bazel.sh ` is configured for the default compiler on your machine. Edit the
132
+ file directly to change this configuration.
92
133
93
134
``` shell
94
135
# Build and test TF-DF.
95
- ./tools/test_bazel.sh
136
+ RUN_TESTS=1 PY_VERSION=3.9 TF_VERSION=2.16.1 ./tools/test_bazel.sh
96
137
```
97
138
98
- Create and test a pip package with the following command. Replace python3.8 by
139
+ Create and test a pip package with the following command. Replace python3.9 by
99
140
the version of python you want to use. Note that you don't have to use the same
100
141
version of Python as in the ` test_bazel.sh ` script.
101
142
@@ -154,25 +195,28 @@ For MacOS systems with ARM64 CPU, follow these steps:
154
195
155
196
1 . Prepare your environment
156
197
157
- ```
198
+ ``` shell
158
199
git clone https://github.com/tensorflow/decision-forests.git
159
200
python3 -m venv venv
160
- source venv/source /activate
201
+ source venv/bin /activate
161
202
```
162
203
163
204
1. Decide which Python version and TensorFlow version you want to use and run
164
205
165
- ```
206
+ ` ` ` shell
166
207
cd decision-forests
167
- export TF_VERSION=2.15.0 # Change to the TensorFlow Version you need.
168
- export PY_VERSION=3.9 # Change to the Python you need.
169
- export RUN_TESTS=1 # Change to 0 if you want to skip tests.
170
- ./tools/test_bazel.sh # Takes ~15 minutes on a modern Mac.
208
+ bazel clean --expunge # Remove old builds (esp. cross-compiled).
209
+ export RUN_TESTS=1 # Whether to run tests after build.
210
+ export PY_VERSION=3.9 # Python version to use for build.
211
+ # TensorFlow version to compile against. This must match exactly the version
212
+ # of TensorFlow used at runtime, otherwise TF-DF may crash unexpectedly.
213
+ export TF_VERSION=2.16.1
214
+ ./tools/test_bazel.sh # Takes ~15 minutes on a modern Mac.
171
215
` ` `
172
216
173
- 1. Package the code .
217
+ 1. Package the build .
174
218
175
- ```
219
+ ` ` ` shell
176
220
# Building the packages uses different virtualenvs through Pyenv.
177
221
deactivate
178
222
# Build the packages.
@@ -188,36 +232,43 @@ machines with Intel CPUs as follows.
188
232
189
233
1. Prepare your environment
190
234
191
- ```
235
+ ` ` ` shell
192
236
git clone https://github.com/tensorflow/decision-forests.git
193
237
python3 -m venv venv
194
238
source venv/source/activate
195
239
` ` `
196
240
197
241
1. Decide which Python version you want to use and run
198
242
199
- ```
243
+ ` ` ` shell
200
244
cd decision-forests
201
- export TF_VERSION=2.15.0 # Change to the TensorFlow Version you need.
202
- export PY_VERSION=3.9 # Change to the Python you need.
203
- export RUN_TESTS=0 # Cross-compiled packages cannot be tested.
204
- export MAC_INTEL_CROSSCOMPILE=1
205
- ./tools/test_bazel.sh # Takes ~15 minutes on a modern Mac.
245
+ bazel clean --expunge # Remove old builds (esp. cross-compiled).
246
+ export RUN_TESTS=0 # Cross-compiled builds can't run tests.
247
+ export PY_VERSION=3.9 # Python version to use for build.
248
+ # TensorFlow version to compile against. This must match exactly the version
249
+ # of TensorFlow used at runtime, otherwise TF-DF may crash unexpectedly.
250
+ export TF_VERSION=2.16.1
251
+ export MAC_INTEL_CROSSCOMPILE=1 # Enable cross-compilation.
252
+ ./tools/test_bazel.sh # Takes ~15 minutes on a modern Mac.
206
253
` ` `
207
254
208
- 1. Package the code .
255
+ 1. Package the build .
209
256
210
- ```
257
+ ` ` ` shell
211
258
# Building the packages uses different virtualenvs through Pyenv.
212
259
deactivate
213
260
# Build the packages.
214
261
./tools/build_pip_package.sh ALL_VERSIONS_MAC_INTEL_CROSSCOMPILE
215
262
` ` `
216
263
217
- 1. The packages can be found in `decision-forests/dist/`.
264
+ 1. The packages can be found in ` decision-forests/dist/` . Note that they have
265
+ not been tested and it would be prudent to test them before distribution.
266
+
267
+ # ## Windows
218
268
219
- ## Final note
269
+ A Windows build has been successfully produced in the past, but is not
270
+ maintained at this point. See ` tools/test_bazel.bat` and ` tools/test_bazel.sh`
271
+ for (possibly outdated) pointers for compiling on Windows.
220
272
221
- Compiling TF-DF relies on the TensorFlow Pip package *and* the TensorFlow Bazel
222
- dependency. Only a small part of TensorFlow will be compiled.
223
- Compiling TF-DF on a single powerful workstation takes ~10 minutes.
273
+ For Windows users, [YDF](https://ydf.readthedocs.io) offers official Windows
274
+ builds and most of the functionality (and more! ) of TF-DF.
0 commit comments