tensorflow/tensorflow
Getting started
How to use, build, and test TensorFlow from this repository.
Use the published package (most users)
Installing TensorFlow from PyPI is the right path unless you need to modify C++ code. From README.md:
pip install tensorflow # CPU + GPU on Linux/Windows
pip install tensorflow-cpu # smaller, CPU onlyimport tensorflow as tf
print(tf.add(1, 2).numpy()) # 3For nightlies use tf-nightly / tf-nightly-cpu.
Build from source
TensorFlow uses Bazel. The full official guide is at tensorflow.org/install/source; the steps below summarize what this repo expects.
Prerequisites
- A supported Linux/macOS/Windows host. The CI uses Ubuntu 20.04+ images defined under
ci/official/. - Bazel at the version pinned in
.bazelversion(currently7.4.1-class — check the file). Usebazeliskto auto-pick the right version. - Python 3.10–3.14. Python toolchain pins live in
requirements_lock_3_10.txt…requirements_lock_3_14.txt. - Clang is the default C/C++ compiler; GCC is also supported. CUDA toolkit + cuDNN are required for GPU builds.
- NumPy at the major version compatible with the chosen Python.
Configure
The repo ships a top-level ./configure script that wraps configure.py. It asks about Python path, CUDA support, ROCm, optimisation flags, and writes .tf_configure.bazelrc:
./configureFor non-interactive use, you can pre-set environment variables (PYTHON_BIN_PATH, TF_NEED_CUDA, TF_CUDA_PATHS, etc.) — see configure.py for the full list.
Build the pip package
bazel build //tensorflow/tools/pip_package:wheel \
--repo_env=WHEEL_NAME=tensorflow
# The wheel ends up in bazel-bin/tensorflow/tools/pip_package/wheel_house/
pip install bazel-bin/tensorflow/tools/pip_package/wheel_house/tensorflow-*.whlFor a GPU build, configure with CUDA enabled and add --config=cuda to the bazel build invocation.
Build the C/C++ library
bazel build //tensorflow:libtensorflow.so # C API shared library
bazel build //tensorflow:libtensorflow_cc.so # C++ API shared libraryHeaders are exported in tensorflow/c/ and tensorflow/cc/.
Build TensorFlow Lite
bazel build //tensorflow/lite:libtensorflowlite.so
bazel build //tensorflow/lite/java:tensorflow-lite # Android AAR
bazel build //tensorflow/lite/tools/benchmark:benchmark_modelA separate CMake build also exists for tensorflow/lite (tensorflow/lite/CMakeLists.txt) for environments without Bazel.
Run tests
Bazel test targets live next to the code they test.
# A single Python test
bazel test //tensorflow/python/ops:math_ops_test
# All tests under a directory (will be many)
bazel test //tensorflow/python/ops/...
# C++ kernel tests
bazel test //tensorflow/core/kernels:matmul_op_test
# Tests with GPU
bazel test --config=cuda //tensorflow/core/kernels:matmul_op_testUseful Bazel tags:
--test_tag_filters=-gpu,-no_ossto skip GPU-only or internal-only tests--test_output=errorsto cut log noise--test_size_filters=small,mediumto skip slow tests during local iteration
Common entry points for development
- Define a new op kernel →
tensorflow/core/kernels/, register withREGISTER_KERNEL_BUILDERand add anOpDefundertensorflow/core/ops/. See systems/kernels-and-ops. - Add a Python wrapper → most are auto-generated from the
OpDef. Hand-written wrappers live intensorflow/python/ops/. - Modify the eager runtime →
tensorflow/core/common_runtime/eager/. - Touch
tf.data→tensorflow/core/data/andtensorflow/python/data/. - Hack on XLA bridge →
tensorflow/compiler/tf2xla/,tensorflow/compiler/jit/. - Touch TFLite →
tensorflow/lite/(note that TFLite kernels are independent ofcore/kernels— they re-implement many ops in a smaller library, seetensorflow/lite/kernels/).
Next steps
- development workflow — how PRs flow through Copybara into Google's monorepo and back.
- testing — Python and C++ test framework conventions.
- tooling — Bazel macros, code generators, doc generation.
- debugging —
tf.debugging, sanitizers,nvprof/profiler, common errors.
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.