Skip to content

Commit

Permalink
Adding callback test
Browse files Browse the repository at this point in the history
  • Loading branch information
tatianacv committed Dec 4, 2023
1 parent 929f69b commit 6866aab
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# From https://www.tensorflow.org/versions/r2.9/api_docs/python/tf/distribute/Strategy#example_usage_2.

import tensorflow as tf

strategy = tf.distribute.MirroredStrategy(["GPU:0", "GPU:1"])
tensor_input = tf.constant(3.0)


@tf.function
def replica_fn(input):
return input * 2.0


# Indirect call to replica_fun().
result = strategy.run(replica_fn, (tensor_input,))
print(result)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tensorflow==2.9.3
Original file line number Diff line number Diff line change
Expand Up @@ -4395,6 +4395,33 @@ public void testHasLikelyTensorParameter147() throws Exception {
testHasLikelyTensorParameterHelper(false, false);
}

/**
* Test for https://github.com/ponder-lab/Hybridize-Functions-Refactoring/issues/280.
*/
@Test
public void testHasLikelyTensorParameter148() throws Exception {
Set<Function> functions = this.getFunctions();
assertNotNull(functions);
assertEquals(1, functions.size());
Function function = functions.iterator().next();
assertNotNull(function);
assertEquals(true, function.getIsHybrid());

argumentsType params = function.getParameters();

// two params.
exprType[] actualParams = params.args;
assertEquals(1, actualParams.length);

exprType actualParameter = actualParams[0];
assertNotNull(actualParameter);

String paramName = NodeUtils.getRepresentationString(actualParameter);
assertEquals("input", paramName);

assertTrue("Expecting function with likely tensor parameter.", function.getLikelyHasTensorParameter());
}

// TODO: Test arbitrary expression.
// TODO: Test cast/assert statements?
// TODO: https://www.tensorflow.org/guide/function#pass_tensors_instead_of_python_literals. How do we deal with union types? Do we want
Expand Down

0 comments on commit 6866aab

Please sign in to comment.