Skip to content
Permalink
Browse files Browse the repository at this point in the history
Always do safe parsing
PiperOrigin-RevId: 433016287
  • Loading branch information
mihaimaruseac authored and tensorflower-gardener committed Mar 7, 2022
1 parent 0f23954 commit c5da7af
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
Expand Up @@ -684,7 +684,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
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 @@ -629,7 +592,7 @@ def testRunCommandInvalidInputKeyError(self, use_tfrt):
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]'
] + (['--use_tfrt'] if use_tfrt else []))
with self.assertRaises(ValueError):
saved_model_cli.run(args)
Expand All @@ -640,7 +603,7 @@ def testRunCommandInvalidSignature(self, use_tfrt):
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]'
] + (['--use_tfrt'] if use_tfrt else []))
with self.assertRaisesRegex(ValueError,
'Could not find signature "INVALID_SIGNATURE"'):
Expand Down

0 comments on commit c5da7af

Please sign in to comment.