Skip to content

Commit 707b48d

Browse files
authored
Fix table row inference benchmark using wrong model path (#38569)
* Fix table row inference benchmark model_path * refactor * fix formatter
1 parent 65e8b65 commit 707b48d

2 files changed

Lines changed: 27 additions & 21 deletions

File tree

sdks/python/apache_beam/testing/benchmarks/inference/table_row_inference_benchmark.py

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -72,32 +72,36 @@ def __init__(self):
7272
metrics_namespace=self.metrics_namespace,
7373
is_streaming=False,
7474
pcollection='RunInference/BeamML_RunInference_Postprocess-0.out0')
75-
self.is_streaming = ((self.pipeline.get_option('mode') or
76-
'batch') == 'streaming')
75+
self.opts = self.pipeline.get_pipeline_options().view_as(
76+
TableRowInferenceOptions)
77+
mode = self.opts.mode or 'batch'
78+
self.is_streaming = mode == 'streaming'
7779
if self.is_streaming:
78-
self.subscription = self.pipeline.get_option('input_subscription')
80+
self.subscription = self.opts.input_subscription
7981

8082
def test(self):
8183
"""Execute the table row inference pipeline for benchmarking."""
82-
extra_opts = {}
83-
84-
mode = self.pipeline.get_option('mode') or 'batch'
85-
extra_opts['mode'] = mode
84+
mode = self.opts.mode or 'batch'
85+
extra_opts = {'mode': mode}
8686

8787
if mode == 'streaming':
88-
extra_opts['input_subscription'] = self.pipeline.get_option(
89-
'input_subscription')
90-
extra_opts['window_size_sec'] = int(
91-
self.pipeline.get_option('window_size_sec') or 60)
92-
extra_opts['trigger_interval_sec'] = int(
93-
self.pipeline.get_option('trigger_interval_sec') or 30)
94-
else:
95-
extra_opts['input_file'] = self.pipeline.get_option('input_file')
96-
97-
for opt in ['output_table', 'model_path', 'feature_columns']:
98-
val = self.pipeline.get_option(opt)
99-
if val:
100-
extra_opts[opt] = val
88+
if self.opts.input_subscription:
89+
extra_opts['input_subscription'] = self.opts.input_subscription
90+
extra_opts['window_size_sec'] = (
91+
self.opts.window_size_sec
92+
if self.opts.window_size_sec is not None else 60)
93+
extra_opts['trigger_interval_sec'] = (
94+
self.opts.trigger_interval_sec
95+
if self.opts.trigger_interval_sec is not None else 30)
96+
elif self.opts.input_file:
97+
extra_opts['input_file'] = self.opts.input_file
98+
99+
if self.opts.output_table:
100+
extra_opts['output_table'] = self.opts.output_table
101+
if self.opts.model_path:
102+
extra_opts['model_path'] = self.opts.model_path
103+
if self.opts.feature_columns:
104+
extra_opts['feature_columns'] = self.opts.feature_columns
101105

102106
self.result = table_row_inference.run(
103107
self.pipeline.get_full_options_as_args(**extra_opts),

sdks/python/apache_beam/testing/test_pipeline.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,9 @@ def get_option(self, opt_name, bool_option=False):
209209
None if option is not found in existing option list which is generated
210210
by parsing value of argument `test-pipeline-options`.
211211
"""
212-
parser = argparse.ArgumentParser()
212+
# Parse one flag at a time; disable prefix matching so e.g. --mode does
213+
# not satisfy --model_path when both appear in options_list.
214+
parser = argparse.ArgumentParser(allow_abbrev=False)
213215
opt_name = opt_name[:2] if opt_name[:2] == '--' else opt_name
214216
# Option name should start with '--' when it's used for parsing.
215217
if bool_option:

0 commit comments

Comments
 (0)