Skip to content

Commit d89aeb9

Browse files
Dan Moldovancopybara-github
Dan Moldovan
authored andcommitted
Disable AutoGraph on method that uses mangled names.
PiperOrigin-RevId: 258883792
1 parent d2926e4 commit d89aeb9

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

tensorflow_datasets/core/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,13 @@
1414
# limitations under the License.
1515

1616
"""API to define datasets."""
17+
# Ensure TensorFlow is importable and its version is sufficiently recent. This
18+
# needs to happen before anything else, since the imports below will try to
19+
# import tensorflow, too.
20+
from tensorflow_datasets.core import tf_compat
21+
tf_compat.ensure_tf_install()
1722

18-
from tensorflow_datasets.core.dataset_builder import BeamBasedBuilder
23+
from tensorflow_datasets.core.dataset_builder import BeamBasedBuilder # pylint:disable=g-import-not-at-top
1924
from tensorflow_datasets.core.dataset_builder import BuilderConfig
2025
from tensorflow_datasets.core.dataset_builder import DatasetBuilder
2126
from tensorflow_datasets.core.dataset_builder import GeneratorBasedBuilder

tensorflow_datasets/core/features/top_level_feature.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,21 @@ def __init__(self, *args, **kwargs):
3939
self.__is_top_level = False
4040
super(TopLevelFeature, self).__init__(*args, **kwargs)
4141

42+
# AutoGraph doesn't support mangled names (__is_top_level), so we explicitly
43+
# disable it in methods that use them, to avoid the warning.
44+
# TODO(mdan): Remove decorator once AutoGraph supports mangled names.
45+
@tf.autograph.experimental.do_not_convert()
4246
def _set_top_level(self):
4347
"""Indicates that the feature is top level.
4448
4549
Internal function called by `DatasetInfo`.
4650
"""
4751
self.__is_top_level = True
4852

53+
# AutoGraph doesn't support mangled names (__is_top_level), so we explicitly
54+
# disable it in methods that use them, to avoid the warning.
55+
# TODO(mdan): Remove decorator once AutoGraph supports mangled names.
56+
@tf.autograph.experimental.do_not_convert()
4957
def decode_example(self, serialized_example, decoders=None):
5058
# pylint: disable=line-too-long
5159
"""Decode the serialize examples.

tensorflow_datasets/core/tf_compat.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ def _patch_for_tf1_13(tf):
109109
dataset_ops.get_legacy_output_shapes)
110110
tf.compat.v2.data.Dataset.output_types = property(
111111
dataset_ops.get_legacy_output_types)
112+
if not hasattr(tf.autograph.experimental, "do_not_convert"):
113+
tf.autograph.experimental.do_not_convert = (
114+
tf.contrib.autograph.do_not_convert)
112115

113116

114117
def is_dataset(ds):

0 commit comments

Comments
 (0)