Last active
July 2, 2019 15:08
-
-
Save gidutz/70b126b2a7d561e9d5f7f232d8f754eb to your computer and use it in GitHub Desktop.
chicago taxi deploy model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create_model(cloudml_client): | |
""" | |
Creates a Model entity in AI Platform | |
:param cloudml_client: discovery client | |
""" | |
models = cloudml_client.projects().models() | |
create_spec = {'name': model_name} | |
models.create(body=create_spec, | |
parent=project_name).execute() | |
def deploy_version(cloudml_client, job_results): | |
""" | |
Deploying the best trail's model to AI platform | |
:param cloudml_client: discovery client | |
:param job_results: response of the finished AI platform job | |
""" | |
models = cloudml_client.projects().models() | |
training_outputs = job_results['trainingOutput'] | |
version_spec = { | |
"name": model_version, | |
"isDefault": False, | |
"runtimeVersion": training_outputs['builtInAlgorithmOutput']['runtimeVersion'], | |
# Assuming the trials are sorted by performance (best is first) | |
"deploymentUri": training_outputs['trials'][0]['builtInAlgorithmOutput']['modelPath'], | |
"framework": training_outputs['builtInAlgorithmOutput']['framework'], | |
"pythonVersion": training_outputs['builtInAlgorithmOutput']['pythonVersion'], | |
"autoScaling": { | |
'minNodes': 0 | |
} | |
} | |
versions = models.versions() | |
response = versions.create(body=version_spec, | |
parent='{}/models/{}'.format(project_name, model_name)).execute() | |
return response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment