Ejemplo n.º 1
0
    def __init__(self,
                 project_id=None,
                 region=None,
                 training_scale_tier=None,
                 job_config=None,
                 use_stream_logs=False):
        """Creates an instance of GCPManagedBackend

        :param project_id: Google Cloud project ID to use.
        :param region: region in which the job has to be deployed.
            Ref: https://cloud.google.com/compute/docs/regions-zones/
        :param training_scale_tier: machine type to use for the job.
            Ref: https://cloud.google.com/ml-engine/docs/tensorflow/machine-types
        :param job_config: Custom job configuration options. If an option is specified
            in the job_config and as a top-level parameter, the parameter overrides
            the value in the job_config.
            Ref: https://cloud.google.com/ml-engine/reference/rest/v1/projects.jobs
        :param use_stream_logs: If true, when deploying a job, output the job stream
            log until the job ends.
        """

        super(GCPManagedBackend, self).__init__()
        self._project_id = project_id or gcp.guess_project_name()
        self._region = region or 'us-central1'
        self._training_scale_tier = training_scale_tier or 'BASIC'
        self._job_config = job_config
        self._use_stream_logs = use_stream_logs
Ejemplo n.º 2
0
    def __init__(self,
                 registry=None,
                 image_name=None,
                 base_image=constants.DEFAULT_BASE_IMAGE,
                 push=True,
                 preprocessor=None,
                 dockerfile_path=None):

        self.registry = registry
        self.image_name = image_name
        self.push = push
        if self.registry is None:
            # TODO(r2d4): Add more heuristics here...

            # If no push and no registry provided, use any registry name
            if not self.push:
                self.registry = 'local/fairing-image'
            else:
                self.registry = 'gcr.io/{}'.format(gcp.guess_project_name())

        self.base_image = base_image
        self.dockerfile_path = dockerfile_path
        self.preprocessor = preprocessor
        self.image_tag = None
        self.docker_client = None
Ejemplo n.º 3
0
def test_guess_project_name_application_default_file(tmp_path):
    creds_file = tmp_path / 'credentials'
    project_id = 'test_project'

    with creds_file.open('w') as f:
        json.dump({'project_id': project_id}, f)

    assert guess_project_name(str(creds_file)) == project_id
Ejemplo n.º 4
0
    def __init__(self, model_dir, model_name, version_name, project_id=None,
                 **deploy_kwargs):
        self._project_id = project_id or guess_project_name()

        self._model_dir = model_dir
        self._model_name = model_name
        self._version_name = version_name
        self._deploy_kwargs = deploy_kwargs
        self._ml = discovery.build('ml', 'v1')
        self._ml._http = http_utils.configure_http_instance(self._ml._http) #pylint:disable=protected-access

        # Set default deploy kwargs
        if 'runtime_version' not in self._deploy_kwargs:
            self._deploy_kwargs['runtime_version'] = '1.13'
        if 'python_version' not in self._deploy_kwargs:
            self._deploy_kwargs['python_version'] = '3.5'
Ejemplo n.º 5
0
 def __init__(self, project_id=None, region=None, scale_tier=None,
              job_config=None, use_stream_logs=False):
     """
     :param project_id: Google Cloud project ID to use.
     :param region: region in which the job has to be deployed.
         Ref: https://cloud.google.com/compute/docs/regions-zones/
     :param scale_tier: machine type to use for the job.
         Ref: https://cloud.google.com/ml-engine/docs/tensorflow/machine-types
     :param job_config: Custom job configuration options. If an option is specified
         in the job_config and as a top-level parameter, the parameter overrides
         the value in the job_config.
         Ref: https://cloud.google.com/ml-engine/reference/rest/v1/projects.jobs
     :param use_stream_logs: If true, when deploying a job, output the job stream
         log until the job ends.
     """
     self._project_id = project_id or guess_project_name()
     self._region = region or 'us-central1'
     self._job_config = job_config or {}
     self.scale_tier = scale_tier
     self._ml = discovery.build('ml', 'v1')
     self._ml._http = http_utils.configure_http_instance(self._ml._http) #pylint:disable=protected-access
     self._use_stream_logs = use_stream_logs
Ejemplo n.º 6
0
 def __init__(self, project_id=None, region=None, training_scale_tier=None):
     super(GCPManagedBackend, self).__init__()
     self._project_id = project_id or gcp.guess_project_name()
     self._region = region or 'us-central1'
     self._training_scale_tier = training_scale_tier or 'BASIC'
Ejemplo n.º 7
0
 def prepare(self, context_filename):  # pylint:disable=arguments-differ
     if self.gcp_project is None:
         self.gcp_project = gcp.guess_project_name()
     self.uploaded_context_url = self.upload_context(context_filename)
Ejemplo n.º 8
0
def test_guess_project_name_google_auth(tmp_path):  #pylint:disable=unused-argument
    project_id = 'test_project'

    with patch('google.auth.default', return_value=(None, project_id)):
        assert guess_project_name() == project_id