Skip to content

Commit d5e71ff

Browse files
yyyu-googlecopybara-github
authored andcommitted
feat: migrate model garden to agentplatform
PiperOrigin-RevId: 910885525
1 parent f63bb91 commit d5e71ff

10 files changed

Lines changed: 3848 additions & 6 deletions

File tree

.kokoro/docker/docs/Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ ENV PATH /usr/local/bin:$PATH
2121

2222
# Install dependencies.
2323
RUN apt-get update \
24-
&& apt-get install -y --no-install-recommends \
24+
&& apt-get install -y ca-certificates --fix-missing \
25+
&& update-ca-certificates
26+
27+
RUN apt-get install -y --no-install-recommends \
2528
apt-transport-https \
2629
build-essential \
2730
ca-certificates \

agentplatform/__init__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,26 @@
1414
#
1515
"""The agentplatform module."""
1616

17+
import importlib
1718
from google.cloud.aiplatform import init
1819
from google.cloud.aiplatform import version as aiplatform_version
1920

2021
__version__ = aiplatform_version.__version__
2122

23+
24+
def __getattr__(name): # type: ignore[no-untyped-def]
25+
if name == "preview":
26+
# We need to import carefully to avoid `RecursionError`.
27+
# This won't work since it causes `RecursionError`:
28+
# `from agentplatform import preview`
29+
# This won't work due to Copybara lacking a transform:
30+
# `import google.cloud.aiplatform.agentplatform.preview as`
31+
# `agentplatform_preview`
32+
return importlib.import_module(".preview", __name__)
33+
raise AttributeError(f"module '{__name__}' has no attribute '{name}'")
34+
35+
2236
__all__ = [
2337
"init",
38+
"preview",
2439
]
Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
# Gemini Enterprise Agent Platform Model Garden SDK for Python
2+
3+
The Gemini Enterprise Agent Platform Model Garden SDK helps developers use [Model Garden](https://cloud.google.com/model-garden) open models to build AI-powered features and applications.
4+
The SDKs support use cases like the following:
5+
6+
- Deploy an open model
7+
- Export open model weights
8+
9+
## Installation
10+
11+
To install the
12+
[google-cloud-aiplatform](https://pypi.org/project/google-cloud-aiplatform/)
13+
Python package, run the following command:
14+
15+
```shell
16+
pip3 install --upgrade --user "google-cloud-aiplatform>=1.84"
17+
```
18+
19+
## Usage
20+
21+
For detailed instructions, see [deploy an open model](https://cloud.google.com/vertex-ai/generative-ai/docs/model-garden/use-models#deploy_an_open_model) and [deploy notebook tutorial](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/community/model_garden/model_garden_deployment_tutorial.ipynb).
22+
23+
## Quick Start: Default Deployment
24+
25+
This is the simplest way to deploy a model. If you provide just a model name, the SDK will use the default deployment configuration.
26+
27+
```python
28+
from agentplatform import model_garden
29+
30+
model = model_garden.OpenModel("google/paligemma@paligemma-224-float32")
31+
endpoint = model.deploy()
32+
```
33+
34+
**Use case:** Fast prototyping, first-time users evaluating model outputs.
35+
36+
## List Deployable Models
37+
38+
You can list all models that are currently deployable via Model Garden:
39+
40+
```python
41+
from agentplatform import model_garden
42+
43+
models = model_garden.list_deployable_models()
44+
```
45+
46+
To filter only Hugging Face models or by keyword:
47+
48+
```python
49+
models = model_garden.list_deployable_models(list_hf_models=True, model_filter="stable-diffusion")
50+
```
51+
52+
**Use case:** Discover available models before deciding which one to deploy.
53+
54+
## Hugging Face Model Deployment
55+
56+
Deploy a model directly from Hugging Face using the model ID.
57+
58+
```python
59+
model = model_garden.OpenModel("Qwen/Qwen2-1.5B-Instruct")
60+
endpoint = model.deploy()
61+
```
62+
63+
**Use case:** Leverage community or third-party models without custom container setup. If the model is gated, you may need to provide a Hugging Face access token:
64+
65+
```python
66+
endpoint = model.deploy(hugging_face_access_token="your_hf_token")
67+
```
68+
69+
**Use case:** Deploy gated Hugging Face models requiring authentication.
70+
71+
## List Deployment Configurations
72+
73+
You can inspect available deployment configurations for a model:
74+
75+
```python
76+
model = model_garden.OpenModel("google/paligemma@paligemma-224-float32")
77+
deploy_options = model.list_deploy_options()
78+
```
79+
80+
**Use case:** Evaluate compatible machine specs and containers before deployment.
81+
82+
## Select a Verified Deployment: By Container Image
83+
84+
Specify a container image from the list of verified deployment configurations.
85+
86+
```python
87+
endpoint = model.deploy(
88+
serving_container_image_uri="us-docker.pkg.dev/vertex-ai/vertex-vision-model-garden-dockers/pytorch-vllm-serve:20250430_0916_RC00_maas",
89+
)
90+
```
91+
92+
## Select a Verified Deployment: By Hardware
93+
94+
Specify a hardware configuration from the list of verified deployment configurations.
95+
96+
```python
97+
endpoints = model.deploy(
98+
machine_type="a3-highgpu-1g",
99+
accelerator_type="NVIDIA_H100_80GB",
100+
accelerator_count=1,
101+
)
102+
```
103+
104+
## Select a Verified Deployment: By Container and Hardware
105+
106+
Specify both a container image and a hardware configuration from the list of verified deployment configurations.
107+
108+
```python
109+
endpoint = model.deploy(
110+
serving_container_image_uri="us-docker.pkg.dev/vertex-ai/vertex-vision-model-garden-dockers/pytorch-vllm-serve:20250430_0916_RC00_maas",
111+
machine_type="a3-highgpu-1g",
112+
accelerator_type="NVIDIA_H100_80GB",
113+
accelerator_count=1,
114+
)
115+
```
116+
117+
**Use case:** Production configuration, performance tuning, scaling.
118+
119+
## EULA Acceptance
120+
121+
Some models require acceptance of a license agreement. Pass `eula=True` if prompted.
122+
123+
```python
124+
model = model_garden.OpenModel("google/gemma2@gemma-2-27b-it")
125+
endpoint = model.deploy(eula=True)
126+
```
127+
128+
**Use case:** First-time deployment of EULA-protected models.
129+
130+
## Spot VM Deployment
131+
132+
Schedule workloads on Spot VMs for lower cost.
133+
134+
```python
135+
endpoint = model.deploy(spot=True)
136+
```
137+
138+
**Use case:** Cost-sensitive development and batch workloads.
139+
140+
## Fast Tryout Deployment
141+
142+
Enable experimental fast-deploy path for popular models.
143+
144+
```python
145+
endpoint = model.deploy(fast_tryout_enabled=True)
146+
```
147+
148+
**Use case:** Interactive experimentation without full production setup.
149+
150+
## Dedicated Endpoints
151+
152+
Create a dedicated DNS-isolated endpoint.
153+
154+
```python
155+
endpoint = model.deploy(use_dedicated_endpoint=True)
156+
```
157+
158+
**Use case:** Traffic isolation for enterprise or regulated workloads.
159+
160+
## Reservation Affinity
161+
162+
Use shared or specific Compute Engine reservations.
163+
164+
```python
165+
endpoint = model.deploy(
166+
reservation_affinity_type="SPECIFIC_RESERVATION",
167+
reservation_affinity_key="compute.googleapis.com/reservation-name",
168+
reservation_affinity_values="projects/YOUR_PROJECT/zones/YOUR_ZONE/reservations/YOUR_RESERVATION"
169+
)
170+
```
171+
172+
**Use case:** Optimized resource usage with pre-reserved capacity.
173+
174+
## Custom Container Image
175+
176+
Override the default container with a custom image.
177+
178+
```python
179+
endpoint = model.deploy(
180+
serving_container_image_uri="us-docker.pkg.dev/vertex-ai/custom-container:latest"
181+
)
182+
```
183+
184+
**Use case:** Use of custom inference servers or fine-tuned environments.
185+
186+
## Advanced Full Container Configuration
187+
188+
Further customize startup probes, health checks, shared memory, and gRPC ports.
189+
190+
```python
191+
endpoint = model.deploy(
192+
serving_container_image_uri="us-docker.pkg.dev/vertex-ai/custom-container:latest",
193+
container_command=["python3"],
194+
container_args=["serve.py"],
195+
container_ports=[8888],
196+
container_env_vars={"ENV": "prod"},
197+
container_predict_route="/predict",
198+
container_health_route="/health",
199+
serving_container_shared_memory_size_mb=512,
200+
serving_container_grpc_ports=[9000],
201+
serving_container_startup_probe_exec=["/bin/check-start.sh"],
202+
serving_container_health_probe_exec=["/bin/health-check.sh"]
203+
)
204+
```
205+
206+
**Use case:** Production-grade deployments requiring deep customization of runtime behavior and monitoring.
207+
208+
## Contributing
209+
210+
See [Contributing](https://github.com/googleapis/python-aiplatform/blob/main/CONTRIBUTING.rst) for more information on contributing to the Gemini Enterprise Agent Platform Python SDK.
211+
212+
## License
213+
214+
The contents of this repository are licensed under the [Apache License, version 2.0](http://www.apache.org/licenses/LICENSE-2.0).
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
# 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+
16+
"""Classes and functions for working with Model Garden."""
17+
18+
# We just want to re-export certain classes
19+
# pylint: disable=g-multiple-import,g-importing-member
20+
from agentplatform.model_garden import _model_garden
21+
22+
OpenModel = _model_garden.OpenModel
23+
PartnerModel = _model_garden.PartnerModel
24+
list_deployable_models = _model_garden.list_deployable_models
25+
list_models = _model_garden.list_models
26+
27+
__all__ = ("OpenModel", "PartnerModel", "list_deployable_models", "list_models")

0 commit comments

Comments
 (0)