-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
vertex-ai
: add :UPLOAD
support for model resource
#12075
base: vertex-ai-model-resource
Are you sure you want to change the base?
Changes from all commits
8904529
56505c3
7443668
f16163d
fa16d1b
2fd47f0
65315b4
5cbf3b9
46696d8
df82514
6eedf63
9f04d1c
f20f07e
8d7d880
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
func vertexAiModelDiffSuppress(ctx context.Context, diff *schema.ResourceDiff, meta interface{}) error { | ||
// we require diffSuppress on COPY method and not UPLOAD | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is included so that we can fill out the description field on create when wanting to upload. As a reminder this diffsuppress was created because of copy not supporting description field on create. More info can be found in this thread. #12074 (comment) |
||
if _, ok := diff.GetOkExists("model_name"); ok { | ||
return nil | ||
} | ||
// If the resource has no id then it hasn't been created yet | ||
// Check to see if any fields are set in the config at create time that shouldn't be there | ||
if diff.Id() == "" { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
func flatten{{$.GetPrefix}}{{$.TitlelizeProperty}}(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { | ||
if d.Get("name").(string) == "" { | ||
return v.(string) | ||
} | ||
|
||
return d.Get("name") | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,17 @@ | ||
return obj, nil | ||
// Copy encoder | ||
if obj["sourceModel"] != nil { | ||
delete(obj, "labels") | ||
delete(obj, "metadata") | ||
return obj, nil | ||
} | ||
|
||
// Upload encoder | ||
obj["displayName"] = obj["modelName"] | ||
delete(obj, "modelName") | ||
|
||
newObj := make(map[string]interface{}) | ||
newObj["model"] = obj | ||
newObj["modelId"] = obj["modelId"] | ||
delete(obj, "modelId") | ||
|
||
return newObj, nil |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,31 @@ | ||
resource "google_vertex_ai_model" "{{$.PrimaryResourceId}}" { | ||
project = "{{index $.TestEnvVars "project_name"}}" | ||
source_model = "projects/{{index $.TestEnvVars "project_name"}}/locations/us-central1/models/tf-static-1" | ||
source_model = google_vertex_ai_model.model_upload.name | ||
|
||
region = "us-central1" | ||
} | ||
|
||
resource "google_vertex_ai_model" "model_upload" { | ||
model_name = "tf_test_model_upload_source_1" | ||
description = "basic upload model for source testing" | ||
region = "us-central1" | ||
|
||
container_spec { | ||
image_uri = "us-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-12:latest" | ||
command = ["/usr/bin/python3"] | ||
args = ["model_server.py"] | ||
|
||
env { | ||
name = "MODEL_NAME" | ||
value = "example-model" | ||
} | ||
|
||
health_route = "/health" | ||
predict_route = "/predict" | ||
ports { | ||
container_port = 8080 | ||
} | ||
} | ||
artifact_uri = "gs://cloud-samples-data/ai-platform/mnist_tfrecord/pretrained" | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,32 @@ | ||
resource "google_vertex_ai_model" "{{$.PrimaryResourceId}}" { | ||
model_id = "{{index $.Vars "model_id"}}" | ||
project = "{{index $.TestEnvVars "project_name"}}" | ||
source_model = "projects/{{index $.TestEnvVars "project_name"}}/locations/us-central1/models/tf-static-1" | ||
source_model = google_vertex_ai_model.model_upload.name | ||
|
||
region = "us-central1" | ||
} | ||
|
||
resource "google_vertex_ai_model" "model_upload" { | ||
model_name = "tf_test_model_upload_source_1" | ||
description = "basic upload model for source testing" | ||
region = "us-central1" | ||
|
||
container_spec { | ||
image_uri = "us-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-12:latest" | ||
command = ["/usr/bin/python3"] | ||
args = ["model_server.py"] | ||
|
||
env { | ||
name = "MODEL_NAME" | ||
value = "example-model" | ||
} | ||
|
||
health_route = "/health" | ||
predict_route = "/predict" | ||
ports { | ||
container_port = 8080 | ||
} | ||
} | ||
artifact_uri = "gs://cloud-samples-data/ai-platform/mnist_tfrecord/pretrained" | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
resource "google_vertex_ai_model" "{{$.PrimaryResourceId}}" { | ||
model_name = "{{index $.Vars "model_name"}}" | ||
description = "basic upload model" | ||
|
||
version_aliases = ["v2beta1"] | ||
model_id = "id_upload_test" | ||
|
||
metadata_schema_uri = "gs://google-cloud-aiplatform/schema/model/metadata/custom_1.0.0.yaml" | ||
|
||
region = "us-central1" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
obj["displayName"] = obj["modelName"] | ||
delete(obj, "modelName") | ||
delete(obj, "sourceModel") | ||
return obj, nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This update_encoder is necessary due to source_model being included in PATCH. The API Reference doesn't include any mention of source_model for patching existing models (such as for updating the description for a copied model) Reference: https://cloud.google.com/vertex-ai/docs/reference/rest/v1/projects.locations.models/patch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently trying to resolve the diff we get on versionAliases where a user inputs their field
[v2beta2]
but get returned a diff on a second apply due todefault_from_api
returning[default, v2beta2]
although we could remove default_from_api this is necessary for copy to work since we don't input
versionAlias
yet we still expect a value from the model we want to copy.In this case we can input the value but we should expect it to have default already as part of the config. I haven't been able to figure out a proper solution. A DiffSuppress was the first idea but because this is an array we are unable to use it (unless there's a hacky way that I don't know about. Leaving this for suggestions @SarahFrench
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After some further investigation we may want to consider removing this for the time being, there is currently no way to include suppot of
StateFunc
which would help with supporting this (more can be found here). A Diff_suppress_func can't be applied due to lack of support on Lists.I was almost convinced to leave it with
ignore_read: true
though this leaves us with a case where we don't receive the version_aliases when copying (e.g the target model contains v1beta1 but instead is set as null when attempting to copy)Because of the reasons above it may be best to remove this field. Any thoughts on this would be appreciated.