You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by "kerrydc (via GitHub)" <gi...@apache.org> on 2023/05/09 14:52:45 UTC

[GitHub] [beam] kerrydc opened a new pull request, #26603: More tests and docs update for env_vars in ModelHandler

kerrydc opened a new pull request, #26603:
URL: https://github.com/apache/beam/pull/26603

   Adds more tests for env_vars in model handlers. Also updates documentation to show how to use the env_vars keyword argument.
   
   ------------------------
   
   Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
   
    - [ ] Mention the appropriate issue in your description (for example: `addresses #123`), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment `fixes #<ISSUE NUMBER>` instead.
    - [ ] Update `CHANGES.md` with noteworthy changes.
    - [ ] If this contribution is large, please file an Apache [Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
   
   See the [Contributor Guide](https://beam.apache.org/contribute) for more tips on [how to make review process smoother](https://beam.apache.org/contribute/get-started-contributing/#make-the-reviewers-job-easier).
   
   To check the build health, please visit [https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md](https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md)
   
   GitHub Actions Tests Status (on master branch)
   ------------------------------------------------------------------------------------------------
   [![Build python source distribution and wheels](https://github.com/apache/beam/workflows/Build%20python%20source%20distribution%20and%20wheels/badge.svg?branch=master&event=schedule)](https://github.com/apache/beam/actions?query=workflow%3A%22Build+python+source+distribution+and+wheels%22+branch%3Amaster+event%3Aschedule)
   [![Python tests](https://github.com/apache/beam/workflows/Python%20tests/badge.svg?branch=master&event=schedule)](https://github.com/apache/beam/actions?query=workflow%3A%22Python+Tests%22+branch%3Amaster+event%3Aschedule)
   [![Java tests](https://github.com/apache/beam/workflows/Java%20Tests/badge.svg?branch=master&event=schedule)](https://github.com/apache/beam/actions?query=workflow%3A%22Java+Tests%22+branch%3Amaster+event%3Aschedule)
   [![Go tests](https://github.com/apache/beam/workflows/Go%20tests/badge.svg?branch=master&event=schedule)](https://github.com/apache/beam/actions?query=workflow%3A%22Go+tests%22+branch%3Amaster+event%3Aschedule)
   
   See [CI.md](https://github.com/apache/beam/blob/master/CI.md) for more information about GitHub Actions CI.
   


-- 
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: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] AnandInguva commented on a diff in pull request #26603: More tests and docs update for env_vars in ModelHandler

Posted by "AnandInguva (via GitHub)" <gi...@apache.org>.
AnandInguva commented on code in PR #26603:
URL: https://github.com/apache/beam/pull/26603#discussion_r1192682455


##########
sdks/python/apache_beam/ml/inference/base.py:
##########
@@ -836,7 +838,12 @@ def get_metrics_collector(self, prefix: str = ''):
 
   def setup(self):
     self._metrics_collector = self.get_metrics_collector()
-    self._model_handler.set_environment_vars()
+    try:
+      self._model_handler.set_environment_vars()
+    except AttributeError:
+      logging.warning(
+          "ModelHander should call super().__init__ or set _env_vars.")

Review Comment:
   We are checking `if '_env_vars` in self.__dict__ in ModelHandler's set_environment_vars, if that attribute is not in the dict, then we skip it right? 
   But we expect that case to show warning right but it actually doesn't 



##########
sdks/python/apache_beam/ml/inference/base.py:
##########
@@ -836,7 +838,12 @@ def get_metrics_collector(self, prefix: str = ''):
 
   def setup(self):
     self._metrics_collector = self.get_metrics_collector()
-    self._model_handler.set_environment_vars()
+    try:
+      self._model_handler.set_environment_vars()
+    except AttributeError:
+      logging.warning(
+          "ModelHander should call super().__init__ or set _env_vars.")

Review Comment:
   We are checking `if '_env_vars in self.__dict__` in ModelHandler's set_environment_vars, if that attribute is not in the dict, then we skip it right? 
   But we expect that case to show warning right but it actually doesn't 



-- 
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: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] kerrydc commented on a diff in pull request #26603: More tests and docs update for env_vars in ModelHandler

Posted by "kerrydc (via GitHub)" <gi...@apache.org>.
kerrydc commented on code in PR #26603:
URL: https://github.com/apache/beam/pull/26603#discussion_r1192738304


##########
sdks/python/apache_beam/ml/inference/base.py:
##########
@@ -836,7 +838,12 @@ def get_metrics_collector(self, prefix: str = ''):
 
   def setup(self):
     self._metrics_collector = self.get_metrics_collector()
-    self._model_handler.set_environment_vars()
+    try:
+      self._model_handler.set_environment_vars()
+    except AttributeError:
+      logging.warning(
+          "ModelHander should call super().__init__ or set _env_vars.")

Review Comment:
   Yes, I removed this catch.



-- 
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: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] kerrydc commented on pull request #26603: More tests and docs update for env_vars in ModelHandler

Posted by "kerrydc (via GitHub)" <gi...@apache.org>.
kerrydc commented on PR #26603:
URL: https://github.com/apache/beam/pull/26603#issuecomment-1542762157

   assign set of reviewers


-- 
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: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] AnandInguva merged pull request #26603: More tests and docs update for env_vars in ModelHandler

Posted by "AnandInguva (via GitHub)" <gi...@apache.org>.
AnandInguva merged PR #26603:
URL: https://github.com/apache/beam/pull/26603


-- 
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: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] codecov[bot] commented on pull request #26603: More tests and docs update for env_vars in ModelHandler

Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #26603:
URL: https://github.com/apache/beam/pull/26603#issuecomment-1542576894

   ## [Codecov](https://app.codecov.io/gh/apache/beam/pull/26603?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#26603](https://app.codecov.io/gh/apache/beam/pull/26603?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (af9b19c) into [master](https://app.codecov.io/gh/apache/beam/commit/8b0b16552b14527f0c9eb0a1bee4b3b1083586cd?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (8b0b165) will **increase** coverage by `0.00%`.
   > The diff coverage is `n/a`.
   
   ```diff
   @@           Coverage Diff           @@
   ##           master   #26603   +/-   ##
   =======================================
     Coverage   72.06%   72.06%           
   =======================================
     Files         745      745           
     Lines      101225   101223    -2     
   =======================================
   - Hits        72951    72950    -1     
   + Misses      26814    26813    -1     
     Partials     1460     1460           
   ```
   
   
   [see 4 files with indirect coverage changes](https://app.codecov.io/gh/apache/beam/pull/26603/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   
   :mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   


-- 
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: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] kerrydc commented on a diff in pull request #26603: More tests and docs update for env_vars in ModelHandler

Posted by "kerrydc (via GitHub)" <gi...@apache.org>.
kerrydc commented on code in PR #26603:
URL: https://github.com/apache/beam/pull/26603#discussion_r1192737735


##########
sdks/python/apache_beam/ml/inference/base.py:
##########
@@ -201,9 +201,11 @@ def get_postprocess_fns(self) -> Iterable[Callable[[Any], Any]]:
 
   def set_environment_vars(self):
     """Sets environment variables using a dictionary provided via kwargs.
-    Keys are the env variable name, and values are the env variable value."""
-    for env_variable, env_value in self._env_vars.items():
-      os.environ[env_variable] = env_value
+    Keys are the env variable name, and values are the env variable value.
+    Child ModelHandler classes should set _env_vars via kwargs in __init__"""
+    if '_env_vars' in self.__dict__:

Review Comment:
   I changed it to:
    env_vars = getattr(self, '_env_vars', {})
   for env_variable, env_value in env_vars:
   
   otherwise I got errors about getattr not being iterable.



-- 
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: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] kerrydc commented on pull request #26603: More tests and docs update for env_vars in ModelHandler

Posted by "kerrydc (via GitHub)" <gi...@apache.org>.
kerrydc commented on PR #26603:
URL: https://github.com/apache/beam/pull/26603#issuecomment-1546114714

   R:@robertwb


-- 
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: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] kerrydc commented on a diff in pull request #26603: More tests and docs update for env_vars in ModelHandler

Posted by "kerrydc (via GitHub)" <gi...@apache.org>.
kerrydc commented on code in PR #26603:
URL: https://github.com/apache/beam/pull/26603#discussion_r1192738151


##########
sdks/python/apache_beam/ml/inference/base.py:
##########
@@ -836,7 +838,12 @@ def get_metrics_collector(self, prefix: str = ''):
 
   def setup(self):
     self._metrics_collector = self.get_metrics_collector()
-    self._model_handler.set_environment_vars()
+    try:
+      self._model_handler.set_environment_vars()
+    except AttributeError:
+      logging.warning(
+          "ModelHander should call super().__init__ or set _env_vars.")

Review Comment:
   Yes, I removed it because it is fully redundant. I removed the warning, updating the pydoc instead.



-- 
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: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] robertwb commented on a diff in pull request #26603: More tests and docs update for env_vars in ModelHandler

Posted by "robertwb (via GitHub)" <gi...@apache.org>.
robertwb commented on code in PR #26603:
URL: https://github.com/apache/beam/pull/26603#discussion_r1192679459


##########
sdks/python/apache_beam/ml/inference/base.py:
##########
@@ -201,9 +201,11 @@ def get_postprocess_fns(self) -> Iterable[Callable[[Any], Any]]:
 
   def set_environment_vars(self):
     """Sets environment variables using a dictionary provided via kwargs.
-    Keys are the env variable name, and values are the env variable value."""
-    for env_variable, env_value in self._env_vars.items():
-      os.environ[env_variable] = env_value
+    Keys are the env variable name, and values are the env variable value.
+    Child ModelHandler classes should set _env_vars via kwargs in __init__"""
+    if '_env_vars' in self.__dict__:

Review Comment:
   Accessing self.__dict__ directly is a bit hacky, and doesn't always work. Intead, maybe do
   
   ```
   for env_variable, env_value in getattr(self, '_env_vars', {}).items():
   ```
   
   or guard with `hasattr(self, '_env_vars')`



##########
sdks/python/apache_beam/ml/inference/base.py:
##########
@@ -836,7 +838,12 @@ def get_metrics_collector(self, prefix: str = ''):
 
   def setup(self):
     self._metrics_collector = self.get_metrics_collector()
-    self._model_handler.set_environment_vars()
+    try:
+      self._model_handler.set_environment_vars()
+    except AttributeError:
+      logging.warning(
+          "ModelHander should call super().__init__ or set _env_vars.")

Review Comment:
   This is redundant with the guard above, right? Also, arbitrary catching of `AttributeError` can be dangerous as it masks a lot of other potential problems (like typos). 
   
   Also, if we want this warning, I would suggest calling `super().__init__` rather than setting `_env_vars` directly, as that is better practice (and will avoid issues if we add anything else to the base init). 



-- 
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: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] github-actions[bot] commented on pull request #26603: More tests and docs update for env_vars in ModelHandler

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #26603:
URL: https://github.com/apache/beam/pull/26603#issuecomment-1544171200

   Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control


-- 
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: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] github-actions[bot] commented on pull request #26603: More tests and docs update for env_vars in ModelHandler

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #26603:
URL: https://github.com/apache/beam/pull/26603#issuecomment-1541019805

   Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment `assign set of reviewers`


-- 
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: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] kerrydc commented on pull request #26603: More tests and docs update for env_vars in ModelHandler

Posted by "kerrydc (via GitHub)" <gi...@apache.org>.
kerrydc commented on PR #26603:
URL: https://github.com/apache/beam/pull/26603#issuecomment-1544169212

   R: @AnandInguva 


-- 
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: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] AnandInguva commented on pull request #26603: More tests and docs update for env_vars in ModelHandler

Posted by "AnandInguva (via GitHub)" <gi...@apache.org>.
AnandInguva commented on PR #26603:
URL: https://github.com/apache/beam/pull/26603#issuecomment-1546450766

   MacOS tests timing out are not related to this PR


-- 
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: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org