Skip to content
This repository was archived by the owner on Jun 9, 2021. It is now read-only.

Commit 35b44d0

Browse files
author
Hoyt Koepke
committed
Version 0.1alpha1.
TensorFlow: - Many bugfixes. Installation: - Resolved some installation issues. - Resolved grpc issue. - Checks for correct CPU subtype in python executable. README: - Clarified Python version requirements. - Added logging and debugging information.
1 parent f9c03c3 commit 35b44d0

File tree

3 files changed

+84
-19
lines changed

3 files changed

+84
-19
lines changed

Diff for: README.md

+58-13
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
## Mac-optimized TensorFlow and TensorFlow Addons
22

3+
34
### INTRODUCTION
45

5-
This pre-release delivers hardware-accelerated TensorFlow and TensorFlow Addons for macOS 11.0+. Native hardware acceleration is supported on Macs with M1 and Intel-based Macs through Apple’s [ML Compute](https://developer.apple.com/documentation/mlcompute) framework.
6+
This pre-release delivers hardware-accelerated TensorFlow and TensorFlow Addons for macOS 11.0+. Native hardware acceleration is supported on Macs with M1 and Intel-based Macs through Apple’s [ML Compute](https://developer.apple.com/documentation/mlcompute) framework.
7+
8+
### CURRENT RELEASE
9+
10+
- 0.1-alpha1
611

712
### SUPPORTED VERSIONS
813

@@ -12,45 +17,85 @@ This pre-release delivers hardware-accelerated TensorFlow and TensorFlow Addons
1217
### REQUIREMENTS
1318

1419
- macOS 11.0+
20+
- Python 3.8, available from the [Xcode Command Line Tools](https://developer.apple.com/download/more/?=command%20line%20tools).
1521

1622
### INSTALLATION
1723

1824
An archive containing Python packages and an installation script can be downloaded from the [releases](https://github.com/apple/tensorflow_macos/releases).
1925

2026
#### Details
2127

22-
- To quickly try this out, copy and paste the following into Terminal:
28+
- To quickly try this out, copy and paste the following into Terminal:
2329

24-
```
30+
```
2531
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/apple/tensorflow_macos/master/scripts/download_and_install.sh)"
2632
```
27-
This will verify your system, ask you for confirmation, then create a [virtual environment](https://docs.python.org/3.8/tutorial/venv.html) with TensorFlow for macOS installed.
2833

29-
- Alternatively, download the archive file from the [releases](https://github.com/apple/tensorflow_macos/releases). The archive contains an installation script,
30-
accelerated versions of TensorFlow, TensorFlow Addons, and needed dependencies.
34+
This will verify your system, ask you for confirmation, then create a virtual environment (https://docs.python.org/3.8/tutorial/venv.html) with TensorFlow for macOS installed.
35+
36+
- Alternatively, download the archive file from the [releases](https://github.com/apple/tensorflow_macos/releases). The archive contains an installation script, accelerated versions of TensorFlow, TensorFlow Addons, and needed dependencies.
3137

3238
#### Notes
3339

3440
For Macs with M1, the following packages are currently unavailable:
41+
3542
- SciPy and dependent packages
3643
- Server/Client TensorBoard packages
3744

3845
### ISSUES AND FEEDBACK
3946

40-
Feedback is welcomed!
41-
4247
Please submit feature requests or report issues via [GitHub Issues](https://github.com/apple/tensorflow_macos/issues).
4348

4449
### ADDITIONAL INFORMATION
45-
50+
4651
#### Device Selection (Optional)
4752

4853
It is not necessary to make any changes to your existing TensorFlow scripts to use ML Compute as a backend for TensorFlow and TensorFlow Addons.
4954

5055
There is an optional `mlcompute.set_mlc_device(device_name=’any')` API for ML Compute device selection. The default value for `device_name` is `'any’`, which means ML Compute will select the best available device on your system, including multiple GPUs on multi-GPU configurations. Other available options are `‘cpu’` and `‘gpu’`. Please note that in eager mode, ML Compute will use the CPU. For example, to choose the CPU device, you may do the following:
5156

52-
# Import mlcompute module to use the optional set_mlc_device API for device selection with ML Compute.
53-
from tensorflow.python.compiler.mlcompute import mlcompute
57+
```
58+
# Import mlcompute module to use the optional set_mlc_device API for device selection with ML Compute.
59+
from tensorflow.python.compiler.mlcompute import mlcompute
60+
61+
# Select CPU device.
62+
mlcompute.set_mlc_device(device_name=‘cpu’) # Available options are 'cpu', 'gpu', and ‘any'.
63+
```
64+
65+
66+
#### Logs and Debugging
67+
68+
##### Graph mode
69+
70+
Logging provides more information about what happens when a TensorFlow model is optimized by ML Compute. Turn logging on by setting the environment variable `TF_MLC_LOGGING=1` when executing the model script. The following is the list of information that is logged in graph mode:
71+
72+
- Device used by ML Compute.
73+
- Original TensorFlow graph without ML Compute.
74+
- TensorFlow graph after TensorFlow operations have been replaced with ML Compute.
75+
- Look for MLCSubgraphOp nodes in this graph. Each of these nodes replaces a TensorFlow subgraph from the original graph, encapsulating all the operations in the subgraph. This, for example, can be used to determine which operations are being optimized by ML Compute.
76+
- Number of subgraphs using ML Compute and how many operations are included in each of these subgraphs.
77+
- Having larger subgraphs that encapsulate big portions of the original graph usually results in better performance from ML Compute. Note that for training, there will usually be at least two MLCSubgraphOp nodes (representing forward and backward/gradient subgraphs).
78+
- TensorFlow subgraphs that correspond to each of the ML Compute graphs.
79+
80+
81+
##### Eager mode
82+
83+
Unlike graph mode, logging in eager mode is controlled by `TF_CPP_MIN_VLOG_LEVEL`. The following is the list of information that is logged in eager mode:
84+
85+
- The buffer pointer and shape of input/output tensor.
86+
- The key for associating the tensor’s buffer to built the `MLCTraining` or `MLCInference` graph. This key is used to retrieve the graph and run a backward pass or an optimizer update.
87+
- The weight tensor format.
88+
- Caching statistics, such as insertions and deletions.
89+
90+
91+
##### Tips for debugging
92+
93+
- Larger models being trained on the GPU may use more memory than is available, resulting in paging. If this happens, try decreasing the batch size or the number of layers.
94+
- TensorFlow is multi-threaded, which means that different TensorFlow operations, such as` MLCSubgraphOp`, can execute concurrently. As a result, there may be overlapping logging information. To avoid this during the debugging process, set TensorFlow to execute operators sequentially by setting the number of threads to 1 (see [`tf.config.threading.set_inter_op_parallelism_threads`](https://www.tensorflow.org/api_docs/python/tf/config/threading/set_inter_op_parallelism_threads)).
95+
96+
##### Additional tips for debugging in eager mode:
97+
98+
- To find information about a specific tensor in the log, search for its buffer pointer in the log. If the tensor is defined by an operation that ML Compute does not support, you will need to cast it to `size_t` and search for it in log entries with the pattern `MemoryLogTensorAllocation ... true ptr: <(size_t)ptr>`. You may also need to modify the `OpKernelContext::input()` to print out the input pointer so that you can see the entire use-def chain in the log.
99+
- You may disable the conversion of any eager operation to ML Compute by using `TF_DISABLE_MLC_EAGER=“;Op1;Op2;...”`. The gradient op may also need to be disabled by modifying the file `$PYTHONHOME/site-packages/tensorflow/python/ops/_grad.py` (this avoids TensorFlow recompilation).
100+
- To initialize allocated memory with a specific value, use `TF_MLC_ALLOCATOR_INIT_VALUE=<init-value>`.
54101

55-
# Select CPU device.
56-
mlcompute.set_mlc_device(device_name=‘cpu’) # Available options are 'cpu', 'gpu', and ‘any'.

Diff for: scripts/download_and_install.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
#/bin/bash
1+
#!/bin/bash
22

33
set -e
44

5-
VERSION=0.1alpha0
5+
VERSION=0.1alpha1
66
INSTALLER_PACKAGE=tensorflow_macos-$VERSION.tar.gz
7-
INSTALLER_PATH=https://github.com/apple/tensorflow_macos/releases/download/v0.1alpha0/tensorflow_macos-0.1alpha0.tar.gz
7+
INSTALLER_PATH=https://github.com/apple/tensorflow_macos/releases/download/$VERSION/$INSTALLER_PACKAGE
88
INSTALLER_SCRIPT=install_venv.sh
99

1010
echo

Diff for: scripts/install_venv.sh

+23-3
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ arch_list_arm64=( numpy-1.18.5-cp38-cp38-macosx_11_0_arm64.whl
5555
tensorflow_addons-0.11.2+mlcompute-cp38-cp38-macosx_11_0_arm64.whl )
5656

5757

58-
tensorflow_version=0.1a0
58+
tensorflow_version=0.1a1
59+
5960

6061
function usage() {
6162

@@ -242,7 +243,23 @@ else
242243

243244
fi
244245

246+
python_filetypes=$(file $python_bin | grep -o -E 'Mach-O 64-bit executable [a-zA-Z0-9_]+$' | sed -E 's|^.*Mach-O 64-bit executable ([a-zA-Z0-9_]+)$|\1|g')
247+
248+
is_present=0
249+
arm64e_present=0
250+
251+
for t in $python_filetypes ; do
252+
if [[ $t -eq $arch ]] ; then
253+
is_present=1
254+
fi
255+
if [[ $t -eq arm64e ]] ; then
256+
arm64e_present=1
257+
fi
258+
done
245259

260+
if [[ $is_present -eq 0 ]] && [[ $arm64e_present -eq 1 ]] && [[ $arch -eq arm64 ]] ; then
261+
error_exit "Python executable has CPU subtype arm64e; only arm64 CPU subtype is currently supported. Please use the Python version bundled in the Xcode Command Line Tools."
262+
fi
246263

247264

248265
# Print out confirmation of actions, run with it
@@ -302,7 +319,7 @@ fi
302319

303320
# Upgrade pip and base packages
304321
echo ">> Installing and upgrading base packages."
305-
"$python_bin" -m pip install --upgrade pip wheel setuptools cached-property six
322+
"$python_bin" -m pip install --force pip==20.2.4 wheel setuptools cached-property six
306323

307324
echo ">> Installing bundled binary dependencies."
308325

@@ -318,9 +335,12 @@ echo ">> Installing dependencies."
318335
# Install some convenience tools
319336
"$python_bin" -m pip install ipython
320337

321-
# Finally, install the tensorflow wheel itself
338+
# Install the tensorflow wheel itself
322339
"$python_bin" -m pip install --upgrade --force -t "$VIRTUAL_ENV/lib/python3.8/site-packages/" --no-dependencies "$package_dir"/tensorflow_macos*-cp38-cp38-macosx_11_0_$arch.whl
323340

341+
# Finally, upgrade pip to give the developers the correct version.
342+
"$python_bin" -m pip install --upgrade pip
343+
324344
echo '###########################################################################'
325345
echo
326346
echo "TensorFlow and TensorFlow Addons with ML Compute for macOS 11.0 successfully installed."

0 commit comments

Comments
 (0)