AnandInguva commented on code in PR #28927:
URL: https://github.com/apache/beam/pull/28927#discussion_r1355124218


##########
sdks/python/apache_beam/ml/transforms/base.py:
##########
@@ -230,3 +244,26 @@ def _validate_transform(self, transform):
       raise TypeError(
           'transform must be a subclass of BaseOperation. '
           'Got: %s instead.' % type(transform))
+
+
+class MLTransformMetricsUsage(beam.PTransform):
+  def __init__(self, ml_transform: MLTransform):
+    self._ml_transform = ml_transform
+    self._ml_transform._counter.inc()
+
+  def expand(self, pipeline):
+    def _increment_counters():
+      # increment for MLTransform.
+      self._ml_transform._counter.inc()
+      # increment if data processing transforms are passed.
+      transforms = (
+          self._ml_transform.transforms or
+          self._ml_transform._process_handler.transforms)
+      if transforms:
+        for transform in transforms:
+          transform.get_counter().inc()
+
+    _ = (
+        pipeline
+        | beam.Create([None])

Review Comment:
   In this context, we only need to update the metrics once and i find this to 
be the easy way to do it.  This is similar to how TFT does it. I needed the 
same behavior but in our MLTransform so I replicated it from 
https://source.corp.google.com/piper///depot/google3/third_party/py/tensorflow_transform/beam/impl.py;l=922?q=tft_mapper_



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