Open-Source Wikis

/

TensorFlow

/

TensorFlow

/

Getting started

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 only
import tensorflow as tf
print(tf.add(1, 2).numpy())   # 3

For 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 (currently 7.4.1-class — check the file). Use bazelisk to auto-pick the right version.
  • Python 3.10–3.14. Python toolchain pins live in requirements_lock_3_10.txtrequirements_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:

./configure

For 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-*.whl

For 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 library

Headers 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_model

A 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_test

Useful Bazel tags:

  • --test_tag_filters=-gpu,-no_oss to skip GPU-only or internal-only tests
  • --test_output=errors to cut log noise
  • --test_size_filters=small,medium to skip slow tests during local iteration

Common entry points for development

  • Define a new op kernel → tensorflow/core/kernels/, register with REGISTER_KERNEL_BUILDER and add an OpDef under tensorflow/core/ops/. See systems/kernels-and-ops.
  • Add a Python wrapper → most are auto-generated from the OpDef. Hand-written wrappers live in tensorflow/python/ops/.
  • Modify the eager runtime → tensorflow/core/common_runtime/eager/.
  • Touch tf.datatensorflow/core/data/ and tensorflow/python/data/.
  • Hack on XLA bridge → tensorflow/compiler/tf2xla/, tensorflow/compiler/jit/.
  • Touch TFLite → tensorflow/lite/ (note that TFLite kernels are independent of core/kernels — they re-implement many ops in a smaller library, see tensorflow/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.
  • debuggingtf.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.

Getting started – TensorFlow wiki | Factory