Exemple #1
0
    def deploy(self, pod_template_spec):
        """Deploys the training job"""
        # TODO: Update deploy interface to pass image directly instad of
        # PodTemplateSpec.
        # Retrieve image uri from pod template spec.
        image_uri = pod_template_spec.containers[0].image
        self._job_name = 'fairing_job_{}'.format(utils.random_tag())

        request_dict = {
            'jobId': self._job_name,
            'trainingInput': {
                'scaleTier': self.scale_tier,
                'masterConfig': {
                    'imageUri': image_uri,
                },
                'region': self._region
            }
        }

        try:
            response = self._ml.projects().jobs().create(
                parent='projects/{}'.format(self._project_id),
                body=request_dict).execute()
            print('Job submitted successfully.')
            self.get_logs()
        except errors.HttpError as err:
            print('There was an error submitting the job.')
            print(err._get_reason())
Exemple #2
0
    def create_request_dict(self, pod_template_spec):
        """Return the request to be sent to the ML Engine API."""
        # TODO: Update deploy interface to pass image directly instad of
        # PodTemplateSpec.
        # Retrieve image uri from pod template spec.
        image_uri = pod_template_spec.containers[0].image
        self._job_name = 'fairing_job_{}'.format(utils.random_tag())

        # Merge explicitly specified parameters with the job config dictionary
        request_dict = self._job_config
        request_dict['jobId'] = self._job_name
        if 'trainingInput' not in request_dict:
            request_dict['trainingInput'] = {}

        if self.scale_tier:
            request_dict['trainingInput']['scaleTier'] = self.scale_tier

        if 'masterConfig' not in request_dict['trainingInput']:
            request_dict['trainingInput']['masterConfig'] = {}
        request_dict['trainingInput']['masterConfig']['imageUri'] = image_uri

        if self._region:
            request_dict['trainingInput']['region'] = self._region

        return request_dict