Skip to content

Commit

Permalink
Merge pull request #55653 from pranve/cherrypick-c5da7af048611aa29e93…
Browse files Browse the repository at this point in the history
…82371f0aed5018516cac-on-r2.8

Always do safe parsing
  • Loading branch information
mihaimaruseac committed Apr 19, 2022
2 parents f66d251 + 6ae6193 commit c112f65
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 40 deletions.
2 changes: 1 addition & 1 deletion tensorflow/python/tools/saved_model_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ def load_inputs_from_input_arg_string(inputs_str, input_exprs_str,
tensor_key_feed_dict = {}

inputs = preprocess_inputs_arg_string(inputs_str)
input_exprs = preprocess_input_exprs_arg_string(input_exprs_str, safe=False)
input_exprs = preprocess_input_exprs_arg_string(input_exprs_str)
input_examples = preprocess_input_examples_arg_string(input_examples_str)

for input_tensor_key, (filename, variable_name) in inputs.items():
Expand Down
41 changes: 2 additions & 39 deletions tensorflow/python/tools/saved_model_cli_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,43 +486,6 @@ def testInputParserPickle(self):
self.assertTrue(np.all(feed_dict['y'] == pkl1))
self.assertTrue(np.all(feed_dict['z'] == pkl2))

def testInputParserPythonExpression(self):
x1 = np.ones([2, 10])
x2 = np.array([[1], [2], [3]])
x3 = np.mgrid[0:5, 0:5]
x4 = [[3], [4]]
input_expr_str = ('x1=np.ones([2,10]);x2=np.array([[1],[2],[3]]);'
'x3=np.mgrid[0:5,0:5];x4=[[3],[4]]')
feed_dict = saved_model_cli.load_inputs_from_input_arg_string(
'', input_expr_str, '')
self.assertTrue(np.all(feed_dict['x1'] == x1))
self.assertTrue(np.all(feed_dict['x2'] == x2))
self.assertTrue(np.all(feed_dict['x3'] == x3))
self.assertTrue(np.all(feed_dict['x4'] == x4))

def testInputParserBoth(self):
x0 = np.array([[1], [2]])
input_path = os.path.join(test.get_temp_dir(), 'input.npz')
np.savez(input_path, a=x0)
x1 = np.ones([2, 10])
input_str = 'x0=' + input_path + '[a]'
input_expr_str = 'x1=np.ones([2,10])'
feed_dict = saved_model_cli.load_inputs_from_input_arg_string(
input_str, input_expr_str, '')
self.assertTrue(np.all(feed_dict['x0'] == x0))
self.assertTrue(np.all(feed_dict['x1'] == x1))

def testInputParserBothDuplicate(self):
x0 = np.array([[1], [2]])
input_path = os.path.join(test.get_temp_dir(), 'input.npz')
np.savez(input_path, a=x0)
x1 = np.ones([2, 10])
input_str = 'x0=' + input_path + '[a]'
input_expr_str = 'x0=np.ones([2,10])'
feed_dict = saved_model_cli.load_inputs_from_input_arg_string(
input_str, input_expr_str, '')
self.assertTrue(np.all(feed_dict['x0'] == x1))

def testInputParserErrorNoName(self):
x0 = np.array([[1], [2]])
x1 = np.array(range(5))
Expand Down Expand Up @@ -623,7 +586,7 @@ def testRunCommandInvalidInputKeyError(self):
base_path = test.test_src_dir_path(SAVED_MODEL_PATH)
args = self.parser.parse_args([
'run', '--dir', base_path, '--tag_set', 'serve', '--signature_def',
'regress_x2_to_y3', '--input_exprs', 'x2=np.ones((3,1))'
'regress_x2_to_y3', '--input_exprs', 'x2=[1,2,3]'
])
with self.assertRaises(ValueError):
saved_model_cli.run(args)
Expand All @@ -633,7 +596,7 @@ def testRunCommandInvalidSignature(self):
base_path = test.test_src_dir_path(SAVED_MODEL_PATH)
args = self.parser.parse_args([
'run', '--dir', base_path, '--tag_set', 'serve', '--signature_def',
'INVALID_SIGNATURE', '--input_exprs', 'x2=np.ones((3,1))'
'INVALID_SIGNATURE', '--input_exprs', 'x2=[1,2,3]'
])
with self.assertRaisesRegex(ValueError,
'Could not find signature "INVALID_SIGNATURE"'):
Expand Down

0 comments on commit c112f65

Please sign in to comment.