Skip to content

Commit afb3ffe

Browse files
committed
Fix PyTorch sentiment Dataflow inference device and CLI args
Parse --device and --input_file in the example, stop injecting --device into Beam pipeline args, and default inference to CPU. Drop T4 worker_accelerator from the streaming load-test options so CPU jobs do not request GPUs. Made-with: Cursor
1 parent a1f260b commit afb3ffe

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

.github/workflows/load-tests-pipeline-options/beam_Inference_Python_Benchmarks_Dataflow_Pytorch_Sentiment_Streaming_DistilBert_Base_Uncased.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,5 @@
3131
--device=CPU
3232
--input_file=gs://apache-beam-ml/testing/inputs/sentences_50k.txt
3333
--runner=DataflowRunner
34-
--dataflow_service_options=worker_accelerator=type:nvidia-tesla-t4;count:1;install-nvidia-driver
3534
--model_path=distilbert-base-uncased-finetuned-sst-2-english
3635
--model_state_dict_path=gs://apache-beam-ml/models/huggingface.sentiment.distilbert-base-uncased.pth

sdks/python/apache_beam/examples/inference/pytorch_sentiment.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,11 @@ def parse_known_args(argv):
9898
required=True,
9999
help="Path to the model's state_dict.")
100100
parser.add_argument(
101-
'--input', required=True, help='Path to input file on GCS')
101+
'--input',
102+
'--input_file',
103+
dest='input',
104+
required=True,
105+
help='Path to input file on GCS (load tests pass --input_file).')
102106
parser.add_argument(
103107
'--pubsub_topic',
104108
default='projects/apache-beam-testing/topics/test_sentiment_topic',
@@ -117,6 +121,11 @@ def parse_known_args(argv):
117121
type=float,
118122
default=None,
119123
help='Elements per second to send to Pub/Sub')
124+
parser.add_argument(
125+
'--device',
126+
default='CPU',
127+
choices=['CPU', 'GPU'],
128+
help='Device to use for inference. Choices are CPU or GPU.')
120129
return parser.parse_known_args(argv)
121130

122131

@@ -183,8 +192,6 @@ def override_or_add(args, flag, value):
183192

184193
def run_load_pipeline(known_args, pipeline_args):
185194
"""Load data pipeline: read lines from GCS file and send to Pub/Sub."""
186-
187-
override_or_add(pipeline_args, '--device', 'CPU')
188195
override_or_add(pipeline_args, '--num_workers', '5')
189196
override_or_add(pipeline_args, '--max_num_workers', '10')
190197
override_or_add(
@@ -238,7 +245,7 @@ def run(
238245
model_class=DistilBertForSequenceClassification,
239246
model_params={'config': DistilBertConfig(num_labels=2)},
240247
state_dict_path=known_args.model_state_dict_path,
241-
device='GPU')
248+
device=known_args.device)
242249

243250
tokenizer = DistilBertTokenizerFast.from_pretrained(known_args.model_path)
244251

0 commit comments

Comments
 (0)