Skip to content

Use discovery for ML API client instead of static file #381

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/python/tensorflow_cloud/core/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def deploy_job(
enable_stream_logs,
job_labels=None,
service_account=None,
region=None,
):
"""Deploys job with the given parameters to Google Cloud.

Expand All @@ -57,12 +58,15 @@ def deploy_job(
to be used for training instead of the service account that AI
Platform Training uses by default. See [custom service account](
https://cloud.google.com/ai-platform/training/docs/custom-service-account)
region: Target region for running the AI Platform job.
Returns:
ID of the invoked remote Cloud AI Platform job.

Raises:
RuntimeError, if there was an error submitting the job.
"""
region = region or gcp.get_region()

job_id = _generate_job_id()
project_id = gcp.get_project_name()
ml_apis = discovery.build(
Expand All @@ -74,7 +78,7 @@ def deploy_job(

request_dict = _create_request_dict(
job_id,
gcp.get_region(),
region,
image_uri,
chief_config,
worker_count,
Expand Down
6 changes: 6 additions & 0 deletions src/python/tensorflow_cloud/core/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from . import containerize
from . import deploy
from . import docker_config as docker_config_module
from . import gcp
from . import machine_config
from . import preprocess
from . import validate
Expand Down Expand Up @@ -73,6 +74,7 @@ def run_cloudtuner(num_jobs=1, **kwargs):
stream_logs = kwargs.pop("stream_logs", False)
job_labels = kwargs.pop("job_labels", None)
service_account = kwargs.pop("service_account", None)
region = kwargs.pop("region", gcp.get_region())

job_ids = [run_results["job_id"]]
for _ in range(1, num_jobs):
Expand All @@ -96,6 +98,7 @@ def run_cloudtuner(num_jobs=1, **kwargs):
stream_logs,
job_labels=job_labels,
service_account=service_account,
region=region,
)
])

Expand All @@ -117,6 +120,7 @@ def run(
stream_logs=False,
job_labels=None,
service_account=None,
region=None,
**kwargs
):
"""Runs your Tensorflow code in Google Cloud Platform.
Expand Down Expand Up @@ -195,6 +199,7 @@ def run(
to be used for training instead of the service account that AI
Platform Training uses by default. see [custom-service-account](
https://cloud.google.com/ai-platform/training/docs/custom-service-account)
region: Target region for running the AI Platform Training job.
**kwargs: Additional keyword arguments.

Returns:
Expand Down Expand Up @@ -329,6 +334,7 @@ def run(
stream_logs,
job_labels=job_labels,
service_account=service_account,
region=region,
)

# Call `exit` to prevent training the Keras model in the local env.
Expand Down
Loading