AnandInguva commented on code in PR #24350: URL: https://github.com/apache/beam/pull/24350#discussion_r1032734852
########## sdks/python/apache_beam/examples/inference/large_language_modeling/main.py: ########## @@ -0,0 +1,129 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License + +""""A pipeline that uses RunInference to perform Translation +with T5 language model. + +This pipeline takes a list of english sentences and then uses +the T5ForConditionalGeneration from Hugging Face to translate the +english sentence into german. +""" +import argparse +import sys + +import apache_beam as beam +from apache_beam.ml.inference.base import RunInference +from apache_beam.options.pipeline_options import PipelineOptions +from pipeline_utils.utils import ModelHandlerWrapper +from pipeline_utils.utils import ModelWrapper +from pipeline_utils.utils import Postprocess +from pipeline_utils.utils import Preprocess +from transformers import AutoConfig +from transformers import AutoTokenizer + + +def parse_args(argv): + """Parses args for the workflow.""" + parser = argparse.ArgumentParser() + parser.add_argument( + "--model_state_dict_path", + required=True, + help="Path to the model's state_dict.", + ) + parser.add_argument( + "--model_name", + required=True, + help="Path to the model's state_dict.", + default="t5-small", + ) + parser.add_argument( + "-m", + "--mode", + help="Mode to run pipeline in.", + choices=["local", "cloud"], + default="local", + ) + parser.add_argument( + "-p", + "--project", + help="GCP project ID to run pipeline on.", + default="apache-beam-testing", + ) + parser.add_argument( + "-r", + "--region", + help="Default region for Dataflow Runner", + default="us-central1", + ) + + parser.add_argument( Review Comment: No, for example if I run the above pipeline in https://github.com/apache/beam/blob/09606de8779ca284666581c7c2da314df4f9ddb1/sdks/python/apache_beam/examples/inference/pytorch_image_classification.py#L123 with the command `python apache_beam/examples/inference/pytorch_image_classification.py --input=some_input --output=some_output --model_state_dict=some_dict --runner=DataflowRunner --project=some_project` **known_args** will have : `Namespace(images_dir=None, input='some_input', model_state_dict_path='some_dict', output='some_output')` **pipeline_args** will have: `['--runner=DataflowRunner', '--project=some_project']`. When we pass pipeline_args to the PipelineOptions, it will take care of parsing the pipeline_args. Likewise, we can do something in this current example and we can remove the options like `runner`, `project` as they are already parsed by PipelineOptions -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
