@@ -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
1111MYPY_PROTOBUF_VERSION=3.6.0
1212
1313# brew install coreutils wget
@@ -30,6 +30,9 @@ python3 -m venv .venv
3030source .venv/bin/activate
3131python3 -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
3437find " $REPO_ROOT /stubs/tensorflow/" -name " *_pb2.pyi" -delete
3538
@@ -38,32 +41,42 @@ find "$REPO_ROOT/stubs/tensorflow/" -name "*_pb2.pyi" -delete
3841PROTOC_VERSION=$( python3 -m grpc_tools.protoc --version)
3942echo $PROTOC_VERSION
4043python3 -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
5459rm -rf " $TMP_DIR "
60+
5561# Must be in a git repository to run pre-commit
5662cd " $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 = \"\
8194Partially generated using [mypy-protobuf==$MYPY_PROTOBUF_VERSION ](https:\/\/github.com\/nipunn1313\/mypy-protobuf\/tree\/v$MYPY_PROTOBUF_VERSION ) \
8295and $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
0 commit comments