Skip to content

Commit 20c90e5

Browse files
yinghsienwuTensorflow Cloud maintainers
authored andcommitted
Fix dataset auto shard policy to ensure DistributingCloudTuner works for the latest TFX version
PiperOrigin-RevId: 367046579
1 parent d509c23 commit 20c90e5

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/python/tensorflow_cloud/tuner/cloud_fit_remote.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@ def _input_fn(file_pattern: List[Text],
9595
reader=_gzip_reader_fn,
9696
label_key=_transformed_name(label_key))
9797

98+
# If the input dataset is file-based but the number of files is less than
99+
# the number of workers, an error will be raised. Turning off auto shard
100+
# policy here so that Dataset will sharded by data instead of by file.
101+
options = tf.data.Options()
102+
options.experimental_distribute.auto_shard_policy = (
103+
tf.data.experimental.AutoShardPolicy.DATA)
104+
dataset = dataset.with_options(options)
105+
98106
return dataset
99107

100108

0 commit comments

Comments
 (0)