Open & Partner Models — Best Practices
Distilled from 34 notebooks tagged Open & Partner Models in the GoogleCloudPlatform/generative-ai repository. The From the notebooks section below cites the per-notebook source for grounding.
Do this
- Use environment variables or secure storage for project, region, provider API keys, Hugging Face tokens, and other sensitive configuration instead of hardcoding them.
- Check deployment options, region support, EULAs, gated-model license acceptance, IAM roles, and GPU or service quotas before starting long-running deployments.
- Smoke test every deployed endpoint or serving container with a minimal request before connecting it to agents, evaluation jobs, BigQuery, LiteLLM, or application code.
- Use Cloud Storage staging buckets for model artifacts, tuning datasets, evaluation outputs, and Vertex AI initialization, and keep buckets regional when the workflow requires region alignment.
- Use the same dataset, prompt template, baseline, and metrics when comparing model architectures, migration candidates, fine-tuned models, adapters, or prompt variants.
- Track evaluations with Vertex AI Experiments and inspect EvaluationDataset, EvaluationResult, explanations, score distributions, confusion matrices, and item-level agreement before trusting aggregate metrics.
- For structured outputs, constrain generation with low temperature, typed schemas, guided JSON, output_schema, response_schema, or explicit autorater output formats where the notebook path supports them.
- Apply model-specific prompt formatting such as tokenizer chat templates for TGI, Selene, Gemma, and other instruction-tuned Hugging Face endpoints.
- Use parameter-efficient and resource-aware fine-tuning techniques such as LoRA, 4-bit loading, 8-bit optimizers, gradient checkpointing, fixed seeds, train-validation splits, and GCS-backed output directories.
- For serving, explicitly configure health routes, predict routes, ports, timeouts, concurrency, keep-alive behavior, autoscaling targets, and startup checks so failures surface before traffic reaches the model.
- Keep private services private with IAM authentication, identity tokens, dedicated service accounts, private GKE nodes, internal load balancers, or no-allow-unauthenticated Cloud Run deployments as shown in the notebooks.
- Refresh Google Cloud access tokens before long benchmarks, OpenAI-compatible calls, LiteLLM calls, or private service requests when credentials may expire.
- Use realistic benchmarks and token accounting for performance work, including shared hardware, identical concurrency levels, local tokenizers, smoke tests, and median latency reporting.
- For BigQuery workflows, create Cloud resource connections, grant the connection service account Vertex AI access, filter NULL text before embedding generation, persist generated outputs when needed, and wait for IAM propagation.
- Delete or undeploy billable resources after tutorials, especially GPU endpoints, Cloud Run GPU services, GKE clusters, Model Registry entries, Agent Engine apps, experiments, buckets, BigQuery datasets, and BigQuery connections.
Avoid this
- Assuming APIs, billing, IAM, Cloud resource connections, model terms, or regional model availability are already configured; many workflows fail until these prerequisites are explicitly handled.
- Leaving GPU endpoints, Cloud Run services, GKE resources, Agent Engine apps, BigQuery assets, experiments, or staging buckets running after a tutorial, causing avoidable charges.
- Using gated Hugging Face or Model Garden models without accepting the license, passing a valid read-only token, or setting accept_eula=True where required.
- Ignoring quota and hardware constraints such as NVIDIA L4, H100, A100, machine type compatibility, Cloud Run GPU allocation, or regional accelerator availability.
- Treating small tutorial samples, 10-row demos, short training runs, or lightweight evaluations as rigorous benchmarks without expanding datasets and metrics.
- Forgetting that access tokens and identity tokens can expire, especially during long benchmark runs, private Cloud Run requests, OpenAI-compatible Vertex AI calls, or LiteLLM calls.
- Mismatching request and response shapes, such as missing prompt/image_base64/inputs fields, invalid function-call JSON, unexpected BYOM prediction response shapes, or missing reasoning_content handling.
- Skipping model-specific runtime details such as chat templates, thinking token budgets, LoRA rank limits, GCS FUSE paths, Ollama keep-alive settings, Cloud Run —no-cpu-throttling, or Vertex AI compatibility patches.
From the notebooks
Use Gemini and OSS Text-Embedding Models Against Your BigQuery Data
- Create a dedicated BigQuery dataset for demo tables and models.
- Filter out NULL text values before calling ML.GENERATE_EMBEDDING.
- Use the same ML.GENERATE_EMBEDDING interface for managed Gemini and deployed OSS remote models.
- Adjust min_replica_count, max_replica_count, and machine_type to balance scalability and cost.
- For batch workloads, deploy the OSS model, run inference, then immediately undeploy it.
Use Gen AI Evaluation SDK to Evaluate Models in Vertex AI Studio, Model Garden, and Model Registry
- Use the same EvalTask configuration with fixed dataset and metrics when comparing model architectures.
- Use prompt_template variables that match columns in the evaluation dataset.
- Use model-based pointwise, pairwise, and computation-based metrics for different evaluation needs.
- Inspect evaluation results and explanations with notebook_utils display helpers.
- Log prompt-template evaluations to an experiment and visualize comparisons with radar and bar plots.
Evaluating Third-Party LLMs with the Vertex AI Gen AI Evaluation SDK
- Use environment variables or secure storage for provider API keys.
- Enable Vertex AI API before running the workflow.
- Set project and region from parameters or GOOGLE_CLOUD_PROJECT and GOOGLE_CLOUD_REGION.
- Use the same dataset and metrics when comparing multiple models.
- Generate rubrics from prompts before rubric-based comparison evaluation.
Migrating Foundation Models: A Practical Guide with Gen AI Evaluation Serivce
- Use predefined rubric metrics such as GENERAL_QUALITY for structured model comparison.
- Compare multiple candidates by passing a list of datasets to evaluate().
- Use .show() on EvaluationDataset and EvaluationResult for in-notebook reports.
- Use batch_evaluate() for large datasets or when immediate results are not required.
- Use environment variables or secure storage for API keys instead of hardcoding them.
Introduction to Generative AI functions in BigQuery
- Create a Cloud resource connection for BigQuery access to Vertex AI services.
- Grant the connection service account the required BigQuery connection and Vertex AI roles.
- Wait for IAM changes to propagate before running model calls.
- Use model_params to control temperature, maxOutputTokens, and thinking_budget.
- Use output_schema when generated results need typed structure.
Building an ADK agent using QWEN 3 on Vertex AI
- Smoke test the deployed model endpoint with LiteLLM before building the full ADK agent.
- Use InMemorySessionService and adk.Runner to test agent behavior locally before deployment.
- Wrap Python functions with FunctionTool so ADK can call them as tools.
- Use reasoning_engines.AdkApp before deploying the ADK agent to Agent Engine.
- Delete the Vertex AI Endpoint and Agent Engine after use to avoid ongoing charges.
Accelerate LLM Inference with EAGLE Speculative Decoding on Vertex AI
- Pin package versions for reproducibility.
- Deploy baseline and EAGLE endpoints on identical hardware for a fair comparison.
- Run 100-prompt smoke tests before the full benchmark.
- Use ShareGPT conversations as a realistic benchmark workload.
- Use the model tokenizer locally so prompt and response token lengths are measured accurately.
Qwen 3 evaluation - Bring your own data eval
- Use a custom dataset for domain-specific model assessment.
- Compare a candidate response against a baseline_model_response row by row.
- Use pairwise_summarization_quality for summary quality comparison.
- Log evaluation runs to a Vertex AI Experiment for tracking and comparison.
- Optionally clean up experiments after running evaluations.
Using open autorater for running evaluations with Vertex AI Gen AI Evaluation
- Test the deployed judge endpoint with a sample prediction before running evaluation.
- Use a structured evaluation dataset with user_input, ground_truth, assistant_response, and human rating columns.
- Define the scoring rubric and required autorater output format explicitly in the metric prompt.
- Use tokenizer.apply_chat_template for prompts sent to the Selene model.
- Compare autorater scores against human ratings with evaluate_autorater before trusting judge alignment.
Hugging Face DLCs: Using Gemma for running evaluations with Vertex AI Gen AI Evaluation
- Initialize Vertex AI with project and location before creating models, endpoints, and evaluations.
- Use a tokenizer chat template before sending prompts to the Hugging Face TGI endpoint.
- Wrap endpoint prediction in a model function so EvalTask can call it consistently.
- Track evaluation runs with Vertex AI Experiments through experiment and experiment_run_name.
- Combine reference-based metrics such as rouge_l_sum with model-based metrics such as summarization_quality and fluency.
MetaMath with Vertex AI Open Source Model Tuning
- Use an 80/20 train-validation split with a fixed seed for reproducibility.
- Limit validation rows to satisfy the Vertex AI validation dataset requirement.
- Upload JSONL files to Cloud Storage because the Vertex AI tuning service cannot access local notebook files directly.
- Use the same MetaMath prompt template for tuned-model testing and official-model comparison.
- Use low temperature, top_p 1.0, and top_k 1 for factual math output.
Fine-tuning GPT-OSS 20B with Unsloth on Vertex AI Colab Enterprise and Nvidia A100 40GB GPU
- Use 4-bit loading to reduce memory usage for the 20B model.
- Use LoRA adapters for parameter-efficient fine-tuning instead of full fine-tuning.
- Use Unsloth gradient checkpointing to reduce VRAM and support longer context.
- Pin package versions and git revisions for compatibility in the managed notebook environment.
- Track GPU memory before and after training.
Hugging Face DLCs: Fine-tuning Gemma with Transformer Reinforcement Learning (TRL) on Vertex AI
- Use a Hugging Face PyTorch training DLC instead of manually building the training environment.
- Use LoRA and an 8-bit optimizer to reduce VRAM requirements for fine-tuning.
- Set output_dir under the /gcs mounted bucket path so trainer outputs are uploaded to Cloud Storage.
- Pass logging environment variables so container logs stream cleanly to Google Cloud Logs Explorer.
- Use a read-only or fine-grained Hugging Face token for gated model access.
Get started with Vertex AI Model Garden SDK
- Use list_deployable_models before selecting a model ID.
- Use list_deploy_options to verify supported deployment configurations before deploying.
- Use environment variables for project and region defaults.
- Accept model EULAs explicitly when required.
- Wrap deployment attempts in try/except to surface deployment errors.
Import, Deploy, and Serve custom open models on Vertex AI using Vertex AI Model Garden SDK.
- Use environment variables as fallbacks for project and region.
- Enable hf_transfer for faster Hugging Face downloads.
- Upload large model files to Cloud Storage with parallel chunk transfers.
- Call list_deploy_options before deployment to verify supported configurations and resource needs.
- Use a dedicated endpoint for prediction calls.
Get started with Model Garden Terraform Deployment
- Store Terraform configurations in Git.
- Use remote state such as Google Cloud Storage for team environments.
- Separate dev, staging, and prod environments.
- Use variables for reusable configuration.
- Add labels to resources for organization and cost tracking.
Handling Reasoning with MaaS Models on Vertex AI using vLLM
- Use Google Cloud default credentials with the cloud-platform scope.
- Configure the Vertex AI endpoint with the model’s specific location.
- Use streaming for long reasoning chains.
- Cache credentials to avoid repeated authentication.
- Choose appropriate model locations for latency.
Serving Gemma 3 with Ollama on Cloud Run
- Keep the Cloud Run service private with —no-allow-unauthenticated and use IAM authentication.
- Use a dedicated service account for the Cloud Run service.
- Embed model weights in the container image with ollama pull during build.
- Set OLLAMA_KEEP_ALIVE=-1 so model weights are not unloaded from GPU.
- Set Cloud Run concurrency to match OLLAMA_NUM_PARALLEL and tune it for GPU utilization.
Running Qwen 3 with Ollama in Cloud Run for Agents
- Keep the Cloud Run service private with —no-allow-unauthenticated and use IAM authentication.
- Use a dedicated service account for the Cloud Run service.
- Set OLLAMA_KEEP_ALIVE=-1 so model weights are not unloaded from GPU memory.
- Warm the model at startup with a dummy ollama run request.
- Set temperature=0.1 for stable function calling.
Serving Gemma 3 with vLLM on Cloud Run
- Use Secret Manager to pass the Hugging Face token to Cloud Build instead of baking it into code.
- Download model weights at image build time and set HF_HUB_OFFLINE=1 for cached runtime loading.
- Keep the Cloud Run service private and rely on IAM authentication.
- Set max instances according to available NVIDIA L4 GPU quota.
- Use Artifact Registry for the built serving image.
Deploying Multiple LoRA Adapters on Vertex AI with vLLM
- Store model files in Cloud Storage instead of baking them into a large Docker image.
- Enable parallel composite uploads for faster Cloud Storage transfers.
- Use a startup entrypoint that fails fast when GCS downloads fail before starting vLLM.
- Set temperature to 0.0 for deterministic SQL generation.
- Configure Vertex AI health and predict routes explicitly for the serving container.
Running a Gemma 2-based agentic RAG with Ollama on Vertex AI and LangGraph
- Use a Cloud Storage staging bucket when initializing Vertex AI SDK.
- Use Artifact Registry and Cloud Build to build and store the custom serving image.
- Expose Vertex AI-compatible health and predict routes in the custom container.
- Validate prediction requests and return consistent error responses in the FastAPI proxy.
- Test the serving container locally with Vertex AI LocalModel before deploying when debugging.
Hugging Face DLCs: Serving PaliGemma using Pytorch Inference on Vertex AI with Custom Handler
- Test the handler logic locally before packaging it as handler.py.
- Use HF_HOME to control the local Hugging Face cache location.
- Upload large model files to Cloud Storage with gsutil parallel composite uploads.
- Validate request instances contain both prompt and image_base64.
- Use torch.inference_mode() for generation.
Hugging Face DLCs: Serving PLLuM using Pytorch Inference on Vertex AI with Custom Handler
- Test the custom handler logic locally before packaging it as handler.py.
- Use HF_HOME to keep Hugging Face cache artifacts in the tutorial directory.
- Copy the model snapshot and handler.py to Cloud Storage before Vertex AI upload.
- Use gsutil -m and parallel composite upload settings for large model directories.
- Validate the serving container locally with LocalModel before deploying to Vertex AI.
Hugging Face DLCs: Serving Gemma with Text Generation Inference (TGI) on Vertex AI
- Use environment variables for PROJECT_ID and GOOGLE_CLOUD_REGION with us-central1 as the default region.
- Use a read-only or fine-grained Hugging Face token for google/gemma-7b-it.
- Set TGI runtime variables such as NUM_SHARD, MAX_INPUT_TOKENS, MAX_TOTAL_TOKENS, and MAX_BATCH_PREFILL_TOKENS.
- Apply the tokenizer chat template before sending prompts to an instruction-following model.
- Undeploy endpoints, delete endpoints, and delete registered models to avoid unnecessary costs.
- Test the custom handler logic locally before packaging handler.py for serving.
- Use response_mime_type application/json and a response_schema for the Gemini router output.
- Validate that each prediction instance contains the inputs key.
- Use gsutil -m and parallel_composite_upload_threshold=150M for large model artifact uploads.
- Store handler.py and requirements.txt with the model artifacts in Cloud Storage.
Use Any OSS Gen AI Model Against Your BigQuery Data
- Check accelerator quota before deploying the model endpoint.
- Use a dedicated Cloud Storage bucket or create a temporary regional bucket for experiment artifacts.
- Grant only the needed service accounts access to Cloud Storage and Vertex AI.
- Use low temperature and constrained output tokens for structured extraction.
- Persist generated outputs to a BigQuery table before downstream analytics.
Cloud Run GPU Inference: Gemma 2 RAG Q&A with Ollama and LangChain
- Store Gemma 2 9B and similarly sized model weights directly in the container image for startup time and scalability.
- Consider storage requirements before placing larger model weights in the image.
- Use e2-highcpu-32 for Cloud Build to speed up parallel downloads.
- Set OLLAMA_KEEP_ALIVE=-1 to avoid unloading model weights from GPU memory.
- Use a dummy startup request to load the model into GPU memory.
Deploying Llama 3 on Google Kubernetes Engine with Cloud Functions and vLLM
- Uses private GKE nodes and an internal load balancer for the model service.
- Separates the model server from the API layer by putting Cloud Functions in front of GKE.
- Uses a VPC connector so the Cloud Function can reach the private GKE endpoint.
- Passes the internal endpoint IP through an environment variable instead of hardcoding it in function code.
- Creates a dedicated service account for the Cloud Function and grants required IAM roles.
Guess who or what app using Hugging Face Deep Learning container model on Vertex AI
- Initialize aiplatform and vertexai with explicit project and location values.
- Retrieve the Hugging Face token with get_token instead of hardcoding it in the notebook.
- Register the Hugging Face model in Vertex AI Model Registry before deploying it to an endpoint.
- Use separate helper functions for Gemini content generation, subject extraction, prompt generation, and image generation.
- Use temperature 0 and candidate_count 1 for Gemini riddle solving and prompt generation.
Serving Open-Source LLMs on Vertex AI with LiteLLM and OpenAI-Compatible APIs
- Check list_deploy_options() before deployment to verify supported configurations and resource needs.
- Use environment variables for project and region defaults.
- Validate the endpoint resource name before configuring LiteLLM.
- Keep backend or external API execution separate from model tool-call argument generation.
- Append assistant tool calls and tool responses to the message history before the second model call.
Build and deploy a Hugging Face smolagent using DeepSeek-r1 on Vertex AI
- Use environment variables GOOGLE_CLOUD_PROJECT and GOOGLE_CLOUD_REGION as fallbacks for project and location.
- Initialize vertexai with project, location, and staging_bucket before creating Vertex AI resources.
- Use Vertex AI Model Registry to manage the imported Hugging Face model lifecycle.
- Use a dedicated endpoint display name derived from the model ID.
- Set explicit serving container predict route, health route, port, and environment variables for the vLLM container.
Multimodal Function Calling with Claude Models
- Select a Claude model before creating the AnthropicVertex client because models have different location availability.
- Use environment variables GOOGLE_CLOUD_PROJECT and GOOGLE_CLOUD_REGION when explicit project or region values are not provided.
- Define tools with a name, description, and input_schema.
- Append the assistant tool-use response and a user tool_result message before asking Claude for the final answer.
- Pass tools again in the follow-up messages.create call.
Open Source Models (Gemma) as a agent with Gemini Enterprise
- Deploy the open-source model first, then integrate it through a tool function before agent deployment.
- Keep the Cloud Run model endpoint private and authenticate with an ID token.
- Test the ADK app locally with a session and stream_query before creating the remote Agent Engine app.
- Pin runtime requirements when deploying the agent to Agent Engine.
- Use a staging bucket when initializing Vertex AI for Agent Engine deployment.
Back to Open & Partner Models · Best Practices Map