Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f0706ba

Browse filesBrowse files
authored
feat(model_garden): add new samples to list models and deploy a model (GoogleCloudPlatform#13236)
* feat(generative-ai): add samples for the new Model Garden SDK * chore: move Model Garden SDK samples from generative_ai/model_garden/sdk to model_garden/sdk. * refactor: clean up the code to address lint errors * refactor: clean up the code to address more lint errors * feature: remove sdk/ folder, add deploy/ folder and add test with mock. * chore: delete files in sdk/ folder * fix lint issues * fix lint issues * address comments * add some comments * remove trailing whitespace * fixing a few more things * fixing a few more things * fix import names * fix import names * fix import names
1 parent 00d4be8 commit f0706ba
Copy full SHA for f0706ba

File tree

Expand file treeCollapse file tree

7 files changed

+263
-0
lines changed
Filter options
Expand file treeCollapse file tree

7 files changed

+263
-0
lines changed

‎model_garden/gemma/gemma3_deploy.py

Copy file name to clipboard
+52Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Google Cloud Vertex AI sample for deploying Gemma 3 in Model Garden.
16+
"""
17+
import os
18+
19+
from google.cloud import aiplatform
20+
21+
22+
PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT")
23+
24+
25+
def deploy() -> aiplatform.Endpoint:
26+
# [START aiplatform_modelgarden_gemma3_deploy]
27+
28+
import vertexai
29+
from vertexai.preview import model_garden
30+
31+
# TODO(developer): Update and un-comment below lines
32+
# PROJECT_ID = "your-project-id"
33+
vertexai.init(project=PROJECT_ID, location="us-central1")
34+
35+
open_model = model_garden.OpenModel("google/gemma3@gemma-3-12b-it")
36+
endpoint = open_model.deploy(
37+
machine_type="g2-standard-48",
38+
accelerator_type="NVIDIA_L4",
39+
accelerator_count=4,
40+
accept_eula=True,
41+
)
42+
43+
# Optional. Run predictions on the deployed endoint.
44+
# endpoint.predict(instances=[{"prompt": "What is Generative AI?"}])
45+
46+
# [END aiplatform_modelgarden_gemma3_deploy]
47+
48+
return endpoint
49+
50+
51+
if __name__ == "__main__":
52+
deploy()
+67Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Google Cloud Vertex AI sample for listing verified deploy
16+
options for models in Model Garden.
17+
"""
18+
import os
19+
from typing import List
20+
21+
from google.cloud.aiplatform_v1beta1 import types
22+
23+
24+
PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT")
25+
26+
27+
def list_deploy_options(model : str) -> List[types.PublisherModel.CallToAction.Deploy]:
28+
# [START aiplatform_modelgarden_models_deployables_options_list]
29+
30+
import vertexai
31+
from vertexai.preview import model_garden
32+
33+
# TODO(developer): Update and un-comment below lines
34+
# PROJECT_ID = "your-project-id"
35+
# model = "google/gemma3@gemma-3-1b-it"
36+
vertexai.init(project=PROJECT_ID, location="us-central1")
37+
38+
# For Hugging Face modelsm the format is the Hugging Face model name, as in
39+
# "meta-llama/Llama-3.3-70B-Instruct".
40+
# Go to https://console.cloud.google.com/vertex-ai/model-garden to find all deployable
41+
# model names.
42+
43+
model = model_garden.OpenModel(model)
44+
deploy_options = model.list_deploy_options()
45+
print(deploy_options)
46+
# Example response:
47+
# [
48+
# dedicated_resources {
49+
# machine_spec {
50+
# machine_type: "g2-standard-12"
51+
# accelerator_type: NVIDIA_L4
52+
# accelerator_count: 1
53+
# }
54+
# }
55+
# container_spec {
56+
# ...
57+
# }
58+
# ...
59+
# ]
60+
61+
# [END aiplatform_modelgarden_models_deployables_options_list]
62+
63+
return deploy_options
64+
65+
66+
if __name__ == "__main__":
67+
list_deploy_options("google/gemma3@gemma-3-1b-it")
+47Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Google Cloud Vertex AI sample for listing deployable models in
16+
Model Garden.
17+
"""
18+
import os
19+
from typing import List
20+
21+
22+
PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT")
23+
24+
25+
def list_deployable_models() -> List[str]:
26+
# [START aiplatform_modelgarden_models_deployables_list]
27+
28+
import vertexai
29+
from vertexai.preview import model_garden
30+
31+
# TODO(developer): Update and un-comment below lines
32+
# PROJECT_ID = "your-project-id"
33+
vertexai.init(project=PROJECT_ID, location="us-central1")
34+
35+
# List deployable models, optionally list Hugging Face models only or filter by model name.
36+
deployable_models = model_garden.list_deployable_models(list_hf_models=False, model_filter="gemma")
37+
print(deployable_models)
38+
# Example response:
39+
# ['google/gemma2@gemma-2-27b','google/gemma2@gemma-2-27b-it', ...]
40+
41+
# [END aiplatform_modelgarden_models_deployables_list]
42+
43+
return deployable_models
44+
45+
46+
if __name__ == "__main__":
47+
list_deployable_models()

‎model_garden/gemma/noxfile_config.py

Copy file name to clipboard
+42Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copyright 2021 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Default TEST_CONFIG_OVERRIDE for python repos.
16+
17+
# You can copy this file into your directory, then it will be imported from
18+
# the noxfile.py.
19+
20+
# The source of truth:
21+
# https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/noxfile_config.py
22+
23+
TEST_CONFIG_OVERRIDE = {
24+
# You can opt out from the test for specific Python versions.
25+
"ignored_versions": ["2.7", "3.7", "3.8", "3.10", "3.11", "3.13"],
26+
# Old samples are opted out of enforcing Python type hints
27+
# All new samples should feature them
28+
"enforce_type_hints": True,
29+
# An envvar key for determining the project id to use. Change it
30+
# to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a
31+
# build specific Cloud project. You can also use your own string
32+
# to use your own Cloud project.
33+
"gcloud_project_env": "GOOGLE_CLOUD_PROJECT",
34+
# 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT',
35+
# If you need to use a specific version of pip,
36+
# change pip_version_override to the string representation
37+
# of the version number, for example, "20.2.4"
38+
"pip_version_override": None,
39+
# A dictionary you want to inject into your test. Don't put any
40+
# secrets here. These values will override predefined values.
41+
"envs": {},
42+
}
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
backoff==2.2.1
2+
google-api-core==2.19.0
3+
pytest==8.2.0
4+
pytest-asyncio==0.23.6

‎model_garden/gemma/requirements.txt

Copy file name to clipboard
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
google-cloud-aiplatform[all]==1.84.0
+50Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from unittest.mock import MagicMock, patch
16+
17+
from google.cloud import aiplatform
18+
19+
import gemma3_deploy
20+
import models_deploy_options_list
21+
import models_deployable_list
22+
23+
24+
def test_list_deployable_models() -> None:
25+
models = models_deployable_list.list_deployable_models()
26+
assert len(models) > 0
27+
assert "gemma" in models[0]
28+
29+
30+
def test_list_deploy_options() -> None:
31+
deploy_options = models_deploy_options_list.list_deploy_options(
32+
model="google/gemma3@gemma-3-1b-it"
33+
)
34+
assert len(deploy_options) > 0
35+
36+
37+
@patch("vertexai.preview.model_garden.OpenModel")
38+
def test_gemma3_deploy(mock_open_model: MagicMock) -> None:
39+
# Mock the deploy response.
40+
mock_endpoint = aiplatform.Endpoint(endpoint_name="test-endpoint-name")
41+
mock_open_model.return_value.deploy.return_value = mock_endpoint
42+
endpoint = gemma3_deploy.deploy()
43+
assert endpoint
44+
mock_open_model.assert_called_once_with("google/gemma3@gemma-3-12b-it")
45+
mock_open_model.return_value.deploy.assert_called_once_with(
46+
machine_type="g2-standard-48",
47+
accelerator_type="NVIDIA_L4",
48+
accelerator_count=4,
49+
accept_eula=True,
50+
)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.