aIbrahiim commented on code in PR #38917:
URL: https://github.com/apache/beam/pull/38917#discussion_r3504225880


##########
sdks/python/apache_beam/testing/benchmarks/inference/mltransform_image_embedding_benchmark.py:
##########
@@ -0,0 +1,227 @@
+#
+# 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.
+#
+
+import logging
+from typing import Optional
+
+from google.cloud import monitoring_v3
+from google.protobuf.duration_pb2 import Duration
+
+from apache_beam.examples.ml_transform import mltransform_image_embedding
+from apache_beam.options.pipeline_options import DebugOptions
+from apache_beam.options.pipeline_options import GoogleCloudOptions
+from apache_beam.options.pipeline_options import SetupOptions
+from apache_beam.options.pipeline_options import StandardOptions
+from apache_beam.options.pipeline_options import WorkerOptions
+from apache_beam.testing.load_tests import dataflow_cost_consts as costs
+from apache_beam.testing.load_tests.dataflow_cost_benchmark import 
DataflowCostBenchmark
+from apache_beam.testing.load_tests.load_test import LoadTestOptions
+
+
+class MLTransformImageEmbeddingOptions(
+    LoadTestOptions,
+    StandardOptions,
+    GoogleCloudOptions,
+    WorkerOptions,
+    DebugOptions,
+    SetupOptions,
+):
+  @classmethod
+  def _add_argparse_args(cls, parser):
+    parser.add_argument('--mode', default='batch')
+    parser.add_argument('--input', default='')
+    parser.add_argument('--input_file', default='')
+    parser.add_argument('--output_table', default='')
+    parser.add_argument('--artifact_location', default='')
+    parser.add_argument(
+        '--pretrained_model_name',
+        default=mltransform_image_embedding.DEFAULT_IMAGE_MODEL_NAME)
+    parser.add_argument('--device', default='CPU')
+    parser.add_argument('--min_batch_size', type=int, default=8)
+    parser.add_argument('--max_batch_size', type=int, default=64)
+    parser.add_argument(
+        '--embedding_accelerator',
+        default=mltransform_image_embedding.DEFAULT_ACCELERATOR)
+    parser.add_argument(
+        '--embedding_min_ram',
+        default=mltransform_image_embedding.DEFAULT_EMBEDDING_MIN_RAM)
+
+
+class MLTransformImageEmbeddingBenchmarkTest(DataflowCostBenchmark):
+  options_class = MLTransformImageEmbeddingOptions
+
+  def __init__(self):
+    self.metrics_namespace = 'BeamML_MLTransform'
+    super().__init__(
+        metrics_namespace=self.metrics_namespace,
+        pcollection='FormatOutput.out0')
+    self.opts = self.pipeline.get_pipeline_options().view_as(
+        MLTransformImageEmbeddingOptions)
+    if self.opts.device == 'GPU':
+      self.gpu = costs.Accelerator.T4
+
+  def _get_worker_time_interval(

Review Comment:
   Makes sense, I’d scoped it here because GPU jobs have two worker pools and 
the base class was stopping too early, so throughput was empty and CPU still 
uses the default path, I will do the refactor and move it into 
DataflowCostBenchmark



-- 
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]

Reply via email to