Skip to content

Commit

Permalink
fix(python): add compatibility with NumPy 2 (#2733)
Browse files Browse the repository at this point in the history
Upgrade the pinned packages used in the Bazel build environment to make
the Python extension module compatible with NumPy 2 in addition to NumPy
1. Modules built against NumPy 1 are not compatible with runtime
environments that use NumPy 2, but modules built against NumPy 2 should
be compatible with both.

The python_requirements.txt defining the Bazel build environment is was
upgraded via the command:

    bazel run //third_party:python_requirements.update -- --upgrade

See third_party/python_requirements.in for details.

This change upgraded a number of other packages as well, notably
Tensorflow, from 2.17 to 2.18. In fact, Tensorflow 2.18 is also required
for compatibility with NumPy 2.

Also update the path to the header files within the NumPy wheel, used by
the :numpy_cc_deps target. Our method of including header files shipped
in Python packages is sensitive to the internal details of those
packages, and NumPy moved their headers during this major version
change.

This fixes #2731, in which //python/tflite_micro:whl_test began failing.
:whl_test installs the newly built tflite_micro package, which packages
our Python extension module, and its dependencies into a clean virtual
environment and performs tests. The tflite_micro package has unversioned
dependencies on the tensorflow and numpy packages. Within the last 24
hours, tensorflow in PyPI was upgraded from 2.17 to 2.18. The 2.18
release upgraded tensorflow's versioned dependency on numpy from 1 to 2,
forcing the environment created by :whl_test to use NumPy 2 instead of
NumPy 1; thereby exposing the incompatibility of the extension module
that was built against NumPy 1, and causing :whl_test to fail.

BUG=#2731
  • Loading branch information
rkuester authored Oct 25, 2024
1 parent e86d97b commit 78e5467
Show file tree
Hide file tree
Showing 2 changed files with 830 additions and 732 deletions.
2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ load("//python:py_pkg_cc_deps.bzl", "py_pkg_cc_deps")

py_pkg_cc_deps(
name = "numpy_cc_deps",
includes = ["numpy/core/include"],
includes = ["numpy/_core/include"],
pkg = requirement("numpy"),
)

Expand Down
Loading

0 comments on commit 78e5467

Please sign in to comment.