Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b3bfdad

Browse files
authored
Bump tensorflow to 2.16.* (#11696)
1 parent 17f1c46 commit b3bfdad

56 files changed

Lines changed: 4061 additions & 917 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

scripts/sync_tensorflow_protobuf_stubs.sh

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ set -euxo pipefail
77

88
# Whenever you update TENSORFLOW_VERSION here, version should be updated
99
# in stubs/tensorflow/METADATA.toml and vice-versa.
10-
TENSORFLOW_VERSION=2.12.1
10+
TENSORFLOW_VERSION=2.16.1
1111
MYPY_PROTOBUF_VERSION=3.6.0
1212

1313
# brew install coreutils wget
@@ -30,6 +30,9 @@ python3 -m venv .venv
3030
source .venv/bin/activate
3131
python3 -m pip install grpcio-tools pre-commit mypy-protobuf=="$MYPY_PROTOBUF_VERSION"
3232

33+
# Empty target folders or the mv command below will fail
34+
rm -rf "$REPO_ROOT/stubs/tensorflow/tensorflow/tsl/"
35+
rm -rf "$REPO_ROOT/stubs/tensorflow/tensorflow/compiler/xla/"
3336
# Remove existing pyi
3437
find "$REPO_ROOT/stubs/tensorflow/" -name "*_pb2.pyi" -delete
3538

@@ -38,32 +41,42 @@ find "$REPO_ROOT/stubs/tensorflow/" -name "*_pb2.pyi" -delete
3841
PROTOC_VERSION=$(python3 -m grpc_tools.protoc --version)
3942
echo $PROTOC_VERSION
4043
python3 -m grpc_tools.protoc \
44+
--proto_path="$TENSORFLOW_DIR/third_party/xla/third_party/tsl" \
45+
--proto_path="$TENSORFLOW_DIR/third_party/xla" \
4146
--proto_path="$TENSORFLOW_DIR" \
4247
--mypy_out "relax_strict_optional_primitives:$REPO_ROOT/stubs/tensorflow" \
43-
$TENSORFLOW_DIR/tensorflow/compiler/xla/*.proto \
44-
$TENSORFLOW_DIR/tensorflow/compiler/xla/service/*.proto \
48+
$TENSORFLOW_DIR/third_party/xla/xla/*.proto \
49+
$TENSORFLOW_DIR/third_party/xla/xla/service/*.proto \
4550
$TENSORFLOW_DIR/tensorflow/core/example/*.proto \
4651
$TENSORFLOW_DIR/tensorflow/core/framework/*.proto \
4752
$TENSORFLOW_DIR/tensorflow/core/protobuf/*.proto \
4853
$TENSORFLOW_DIR/tensorflow/core/protobuf/tpu/*.proto \
4954
$TENSORFLOW_DIR/tensorflow/core/util/*.proto \
5055
$TENSORFLOW_DIR/tensorflow/python/keras/protobuf/*.proto \
51-
$TENSORFLOW_DIR/tensorflow/tsl/protobuf/*.proto \
56+
$TENSORFLOW_DIR/third_party/xla/third_party/tsl/tsl/protobuf/*.proto \
5257

5358
# Cleanup after ourselves, this is a temp dir, but it can still grow fast if run multiple times
5459
rm -rf "$TMP_DIR"
60+
5561
# Must be in a git repository to run pre-commit
5662
cd "$REPO_ROOT"
5763

58-
# These protos exist in a folder with protos used in python, but are not
59-
# included in the python wheel. They are likely only used for other
60-
# language builds. stubtest was used to identify them by looking for
61-
# ModuleNotFoundError.
62-
rm \
64+
# Move third-party and fix imports
65+
mv stubs/tensorflow/tsl/ stubs/tensorflow/tensorflow/
66+
find stubs/tensorflow/ -name '*_pb2.pyi' | xargs sed --in-place="" -r "s/(\[|\s)tsl\./\1tensorflow\.tsl\./"
67+
mv stubs/tensorflow/xla/ stubs/tensorflow/tensorflow/compiler/
68+
find stubs/tensorflow/ -name '*_pb2.pyi' | xargs sed --in-place="" -r "s/(\[|\s)xla\./\1tensorflow\.compiler\.xla\./"
69+
70+
# These protos exist in a folder with protos used in python,
71+
# but are not included in the python wheel.
72+
# They are likely only used for other language builds.
73+
# stubtest was used to identify them by looking for ModuleNotFoundError.
74+
# (comment out ".*_pb2.*" from the allowlist)
75+
rm -r \
76+
stubs/tensorflow/tensorflow/compiler/xla/autotune_results_pb2.pyi \
77+
stubs/tensorflow/tensorflow/compiler/xla/autotuning_pb2.pyi \
78+
stubs/tensorflow/tensorflow/compiler/xla/service/buffer_assignment_pb2.pyi \
6379
stubs/tensorflow/tensorflow/compiler/xla/service/hlo_execution_profile_data_pb2.pyi \
64-
stubs/tensorflow/tensorflow/compiler/xla/service/hlo_profile_printer_data_pb2.pyi \
65-
stubs/tensorflow/tensorflow/compiler/xla/service/test_compilation_environment_pb2.pyi \
66-
stubs/tensorflow/tensorflow/compiler/xla/xla_pb2.pyi \
6780
stubs/tensorflow/tensorflow/core/protobuf/autotuning_pb2.pyi \
6881
stubs/tensorflow/tensorflow/core/protobuf/conv_autotuning_pb2.pyi \
6982
stubs/tensorflow/tensorflow/core/protobuf/critical_section_pb2.pyi \
@@ -80,7 +93,7 @@ sed --in-place="" \
8093
"s/extra_description = .*$/extra_description = \"\
8194
Partially generated using [mypy-protobuf==$MYPY_PROTOBUF_VERSION](https:\/\/github.com\/nipunn1313\/mypy-protobuf\/tree\/v$MYPY_PROTOBUF_VERSION) \
8295
and $PROTOC_VERSION \
83-
on tensorflow==$TENSORFLOW_VERSION.\"/" \
96+
on tensorflow==$TENSORFLOW_VERSION .\"/" \
8497
stubs/tensorflow/METADATA.toml
8598

8699
# use `|| true` so the script still continues even if a pre-commit hook

stubs/tensorflow/@tests/stubtest_allowlist.txt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,9 @@ tensorflow._aliases
4949
# tf.initializers at runtime is <module 'keras.api._v2.keras.initializers' from '...'>
5050
tensorflow.initializers
5151
# Other cursed import magic similar to the one above.
52-
tensorflow.keras.layers.preprocessing
53-
tensorflow.keras.layers.preprocessing.index_lookup
54-
# Another cursed import magic similar to the one above.
52+
tensorflow.distribute.coordinator
5553
tensorflow.distribute.experimental.coordinator
5654

57-
# Layer constructor's always have **kwargs, but only allow a few specific values. PEP 692
58-
# would allow us to specify this with **kwargs and remove the need for these exceptions.
59-
tensorflow.keras.layers.*.__init__
60-
6155
# __call__ in tensorflow classes often allow keyword usage, but
6256
# when you subclass those classes it is not expected to handle keyword case. As an example,
6357
# class MyLayer(tf.keras.layers.Layer):

stubs/tensorflow/METADATA.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
version = "2.15.*"
1+
# Whenever you update version here, TENSORFLOW_VERSION should be updated
2+
# in scripts/sync_tensorflow_protobuf_stubs.sh and vice-versa.
3+
version = "2.16.*"
24
upstream_repository = "https://github.com/tensorflow/tensorflow"
35
# requires a version of numpy with a `py.typed` file
46
requires = ["numpy>=1.20", "types-protobuf", "types-requests"]
5-
extra_description = "Partially generated using [mypy-protobuf==3.6.0](https://github.com/nipunn1313/mypy-protobuf/tree/v3.6.0) and libprotoc 25.1 on tensorflow==2.12.1."
7+
extra_description = "Partially generated using [mypy-protobuf==3.6.0](https://github.com/nipunn1313/mypy-protobuf/tree/v3.6.0) and libprotoc 25.1 on tensorflow==2.16.1 ."
68
partial_stub = true
79

810
[tool.stubtest]

stubs/tensorflow/tensorflow/__init__.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import abc
12
from _typeshed import Incomplete, Unused
23
from abc import ABC, ABCMeta, abstractmethod
34
from builtins import bool as _bool
@@ -17,6 +18,7 @@ from tensorflow import (
1718
io as io,
1819
keras as keras,
1920
math as math,
21+
types as types,
2022
)
2123
from tensorflow._aliases import AnyArray, DTypeLike, ShapeLike, Slice, TensorCompatible
2224
from tensorflow.autodiff import GradientTape as GradientTape
@@ -257,7 +259,7 @@ class IndexedSlices(metaclass=ABCMeta):
257259
def __neg__(self) -> IndexedSlices: ...
258260
def consumers(self) -> list[Operation]: ...
259261

260-
class name_scope:
262+
class name_scope(metaclass=abc.ABCMeta):
261263
def __init__(self, name: str) -> None: ...
262264
def __enter__(self) -> str: ...
263265
def __exit__(self, typ: type[BaseException] | None, value: BaseException | None, traceback: TracebackType | None) -> None: ...

stubs/tensorflow/tensorflow/compiler/xla/autotune_results_pb2.pyi

Lines changed: 0 additions & 92 deletions
This file was deleted.

0 commit comments

Comments
 (0)