Skip to content

Commit

Permalink
Merge pull request #39541 from bhack:partial_decorate
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 312132452
Change-Id: I6264d95cb73caf6ddca26567ddad035e94d3ac74
  • Loading branch information
tensorflower-gardener committed May 18, 2020
2 parents 6f19d50 + 64d839b commit dfd659d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
20 changes: 20 additions & 0 deletions tensorflow/python/kernel_tests/map_fn_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import numpy as np

from tensorflow.python.eager import def_function
from tensorflow.python.eager import context
from tensorflow.python.framework import constant_op
from tensorflow.python.framework import dtypes
Expand Down Expand Up @@ -186,6 +187,25 @@ def testMap_MultiInputSameStructureOutput(self):
self.assertAllEqual(-nums, received[1])
self.assertAllEqual(nums, received[2])

@test_util.run_in_graph_and_eager_modes
def testMap_autograph_indirect(self):

def test_function(x):
cond = constant_op.constant(-1)
if cond == 0:
result = x
else:
result = x
return result

@def_function.function
def map_call(x):
return map_fn.map_fn(test_function, x)

x = constant_op.constant([1])
y = map_call(x)
self.assertAllEqual([1], self.evaluate(y))

@test_util.run_in_graph_and_eager_modes
def testMapShape(self):
x = constant_op.constant([[1, 2, 3], [4, 5, 6]])
Expand Down
6 changes: 5 additions & 1 deletion tensorflow/python/ops/map_fn.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

import re

from tensorflow.python.autograph.core import ag_ctx as autograph_ctx
from tensorflow.python.autograph.impl import api as autograph
from tensorflow.python.eager import context
from tensorflow.python.framework import constant_op
from tensorflow.python.framework import ops
Expand Down Expand Up @@ -477,7 +479,9 @@ def compute(i, tas):
elems_value_flat = _elems_value_batchable_to_flat(elems_value_batchable,
elems_flat_signature)
elems_value = elems_unflatten(elems_value_flat)
result_value = fn(elems_value)
ag_ctx = autograph_ctx.control_status_ctx()
autographed_fn = autograph.tf_convert(fn, ag_ctx)
result_value = autographed_fn(elems_value)
nest.assert_same_structure(fn_output_signature or elems, result_value)
result_value_flat = nest.flatten(result_value)
result_value_batchable = _result_value_flat_to_batchable(
Expand Down

0 comments on commit dfd659d

Please sign in to comment.