Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,5 @@
--device=CPU
--input_file=gs://apache-beam-ml/testing/inputs/sentences_50k.txt
--runner=DataflowRunner
--dataflow_service_options=worker_accelerator=type:nvidia-tesla-t4;count:1;install-nvidia-driver
--model_path=distilbert-base-uncased-finetuned-sst-2-english
--model_state_dict_path=gs://apache-beam-ml/models/huggingface.sentiment.distilbert-base-uncased.pth
15 changes: 11 additions & 4 deletions sdks/python/apache_beam/examples/inference/pytorch_sentiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ def parse_known_args(argv):
required=True,
help="Path to the model's state_dict.")
parser.add_argument(
'--input', required=True, help='Path to input file on GCS')
'--input',
'--input_file',
dest='input',
required=True,
help='Path to input file on GCS (load tests pass --input_file).')
parser.add_argument(
'--pubsub_topic',
default='projects/apache-beam-testing/topics/test_sentiment_topic',
Expand All @@ -117,6 +121,11 @@ def parse_known_args(argv):
type=float,
default=None,
help='Elements per second to send to Pub/Sub')
parser.add_argument(
'--device',
default='CPU',
choices=['CPU', 'GPU'],
help='Device to use for inference. Choices are CPU or GPU.')
return parser.parse_known_args(argv)


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

def run_load_pipeline(known_args, pipeline_args):
"""Load data pipeline: read lines from GCS file and send to Pub/Sub."""

override_or_add(pipeline_args, '--device', 'CPU')
override_or_add(pipeline_args, '--num_workers', '5')
override_or_add(pipeline_args, '--max_num_workers', '10')
override_or_add(
Expand Down Expand Up @@ -238,7 +245,7 @@ def run(
model_class=DistilBertForSequenceClassification,
model_params={'config': DistilBertConfig(num_labels=2)},
state_dict_path=known_args.model_state_dict_path,
device='GPU')
device=known_args.device)

tokenizer = DistilBertTokenizerFast.from_pretrained(known_args.model_path)

Expand Down
Loading