Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Import error for cloud_profiler #869

Merged
merged 12 commits into from Dec 1, 2021

Conversation

mkovalski
Copy link
Contributor

@mkovalski mkovalski commented Nov 29, 2021

Circular imports involving absolute imports with binding a submodule to a name was not supported in python 3.6, as documented here. Needed to update import.

  • Import initializer without alias
  • Move the ImportError to the tf profiler module.

Fixes #867

@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Nov 29, 2021
@product-auto-label product-auto-label bot added the api: aiplatform Issues related to the AI Platform API. label Nov 29, 2021
@mkovalski mkovalski marked this pull request as ready for review November 30, 2021 00:58
@mkovalski mkovalski requested a review from a team as a code owner November 30, 2021 17:57
setup.py Outdated
profiler_extra_require = ["tensorboard-plugin-profile", "tensorflow >=2.4.0"]
profiler_extra_require = [
"tensorboard-plugin-profile",
"werkzeug",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add constraints on this version. Also preferable on TB plugin profile above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -17,6 +17,15 @@

"""A plugin to handle remote tensoflow profiler sessions for Vertex AI."""

try:
from tensorboard_plugin_profile.profile_plugin import ProfilePlugin
from werkzeug import Response
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

initializer.py imports werkzeug before importing tf_profiler: https://github.com/googleapis/python-aiplatform/blob/main/google/cloud/aiplatform/training_utils/cloud_profiler/initializer.py#L21

Recommend catching on all optional imports or walking through all the imports to determine when they are first imported.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, I went with catching the imports at where they were first imported. The tests should catch the verbiage as well.

for mock_module in ["tensorboard_plugin_profile.profile_plugin", "werkzeug"]:
with self.subTest():
with mock.patch.dict("sys.modules", {mock_module: None}):
self.assertRaises(ImportError, reload, tf_profiler)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this test importing cloud_profiler as that's the prescribed usage?

Also, may want to use the context manager to get the exception object and ensure the raised exception includes the intended verbiage.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -25,16 +25,22 @@
import tensorboard.plugins.base_plugin as tensorboard_base_plugin
from typing import Callable, Dict, Optional
from urllib import parse
from werkzeug import Response

from google.cloud.aiplatform.tensorboard.plugins.tf_profiler import profile_uploader
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this would import Tensorflow and not be caught.

@sasha-gitg sasha-gitg merged commit 0f124e9 into googleapis:main Dec 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: aiplatform Issues related to the AI Platform API. cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The build failed
2 participants