Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing callbacks related to datasets #83

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,12 @@ public void testCallbacks2()
test("tf2_test_callbacks2.py", "replica_fn", 1, 1, 2);
}

@Test
public void testCallbacks3()
throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException {
test("tf2_test_callbacks3.py", "dataset_fn", 0, 0);
}

@Test
public void testGanTutorial()
throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException {
Expand Down
21 changes: 21 additions & 0 deletions com.ibm.wala.cast.python.test/data/tf2_test_callbacks3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# From https://www.tensorflow.org/tutorials/distribute/input#tfdistributestrategydistribute_datasets_from_function.

import tensorflow as tf

global_batch_size = 16
strategy = tf.distribute.MirroredStrategy(["GPU:0", "GPU:1"])


def dataset_fn(input_context):
batch_size = input_context.get_per_replica_batch_size(global_batch_size)
dataset = tf.data.Dataset.from_tensors(([1.0], [1.0])).repeat(64).batch(16)
dataset = dataset.shard(
input_context.num_input_pipelines, input_context.input_pipeline_id
)
dataset = dataset.batch(batch_size)
dataset = dataset.prefetch(2) # This prefetches 2 batches per device.
return dataset


dist_dataset = strategy.distribute_datasets_from_function(dataset_fn)
print(dist_dataset)
Loading