Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

5.1 KB
Raw Blame
# Granite Guardian on our own GPU: IBM's open-weight guardrail model
# (ibm-granite/granite-guardian-3.3-8b, Apache 2.0) served by vLLM's
# OpenAI-compatible server on a Cloud Run L4.
#
# This is the second lane behind watsonx.ai for /api/guardian/assess and the
# identity integrity check (api/_lib/granite-guardian.js). It lets governance
# run on real Granite Guardian on a deployment with no IBM Cloud account.
#
#   gcloud builds submit --config workers/granite-guardian/cloudbuild.yaml \
#     --region europe-west4 --project aerial-vehicle-466722-p5 \
#     --no-source
#
# Region: europe-west4 holds an L4 grant nothing else uses, so a warm pin here
# does not starve the 3D lanes in us-central1 (see docs/ops/gcp-credits-plan.md).
serviceAccount: projects/aerial-vehicle-466722-p5/serviceAccounts/[email protected]

substitutions:
  _REGION: europe-west4
  _SERVICE: granite-guardian
  _REPO: granite-guardian
  # Same runtime identity and bearer secret as every other GPU worker, so the
  # API reaches it with the GCP_RECONSTRUCTION_KEY it already holds.
  _RUN_SA: avatar-reconstruction-sa@aerial-vehicle-466722-p5.iam.gserviceaccount.com
  _WEIGHTS_BUCKET: three-ws-model-weights
  _HF_REPO: ibm-granite/granite-guardian-3.3-8b
  # Pinned model revision: a silent upstream weight change must not alter
  # verdicts without a deploy.
  _HF_REVISION: b3421eda4ba6fc9f9a71121d7e62de08827469a4
  _WEIGHTS_PATH: granite-guardian-3.3-8b
  _VLLM_TAG: v0.29.0
  _MIN_INSTANCES: "1"
  _MAX_INSTANCES: "2"

steps:
  # Stage the weights into the shared weights bucket once. Re-runs skip the
  # 16 GB download when the pinned revision is already there.
  - id: check-weights
    name: gcr.io/google.com/cloudsdktool/cloud-sdk:slim
    entrypoint: bash
    args:
      - -ceu
      - |
        if gcloud storage cat "gs://${_WEIGHTS_BUCKET}/${_WEIGHTS_PATH}/REVISION" 2>/dev/null | grep -qx "${_HF_REVISION}"; then
          echo "weights already staged on ${_HF_REVISION}"
          touch /workspace/weights-staged
        fi

  - id: download-weights
    name: python:3.12-slim
    entrypoint: bash
    args:
      - -ceu
      - |
        [ -f /workspace/weights-staged ] && exit 0
        pip install -q "huggingface_hub[hf_transfer]>=0.34,<1"
        HF_HUB_ENABLE_HF_TRANSFER=1 huggingface-cli download "${_HF_REPO}" \
          --revision "${_HF_REVISION}" --local-dir /workspace/weights \
          --exclude "*.gguf" ".gitattributes" "README.md"
        rm -rf /workspace/weights/.cache
        echo "${_HF_REVISION}" > /workspace/weights/REVISION

  - id: upload-weights
    name: gcr.io/google.com/cloudsdktool/cloud-sdk:slim
    entrypoint: bash
    args:
      - -ceu
      - |
        [ -f /workspace/weights-staged ] && exit 0
        gcloud storage rsync --recursive --delete-unmatched-destination-objects \
          /workspace/weights "gs://${_WEIGHTS_BUCKET}/${_WEIGHTS_PATH}"

  # Mirror the pinned vLLM image into Artifact Registry so a Docker Hub pull
  # limit can never block a cold start.
  - id: mirror-vllm
    name: gcr.io/cloud-builders/docker
    entrypoint: bash
    args:
      - -ceu
      - |
        docker pull vllm/vllm-openai:${_VLLM_TAG}
        docker tag vllm/vllm-openai:${_VLLM_TAG} ${_REGION}-docker.pkg.dev/$PROJECT_ID/${_REPO}/vllm-openai:${_VLLM_TAG}
        docker push ${_REGION}-docker.pkg.dev/$PROJECT_ID/${_REPO}/vllm-openai:${_VLLM_TAG}

  - id: deploy
    name: gcr.io/google.com/cloudsdktool/cloud-sdk:slim
    entrypoint: gcloud
    args:
      - run
      - deploy
      - ${_SERVICE}
      - --image=${_REGION}-docker.pkg.dev/$PROJECT_ID/${_REPO}/vllm-openai:${_VLLM_TAG}
      - --region=${_REGION}
      - --service-account=${_RUN_SA}
      - --platform=managed
      - --port=8080
      - --gpu=1
      - --gpu-type=nvidia-l4
      - --no-gpu-zonal-redundancy
      - --no-cpu-throttling
      - --cpu=8
      - --memory=32Gi
      - --concurrency=32
      - --min-instances=${_MIN_INSTANCES}
      - --max-instances=${_MAX_INSTANCES}
      - --timeout=120
      - --allow-unauthenticated
      - --labels=lane=guardian-gpu,program=gcp-credits
      - --add-volume=name=weights,type=cloud-storage,bucket=${_WEIGHTS_BUCKET},readonly=true
      - --add-volume-mount=volume=weights,mount-path=/weights
      # vLLM only opens its port once the 16 GB of weights are on the GPU, so
      # the probe allows up to 20 minutes before declaring the start failed.
      - --startup-probe=httpGet.path=/health,httpGet.port=8080,periodSeconds=20,timeoutSeconds=10,failureThreshold=60
      - --command=vllm
      - --args=serve,/weights/${_WEIGHTS_PATH},--served-model-name,${_HF_REPO},--host,0.0.0.0,--port,8080,--dtype,bfloat16,--max-model-len,8192,--gpu-memory-utilization,0.92,--max-logprobs,20,--disable-log-requests
      # vLLM rejects any request without this bearer (VLLM_API_KEY). The API
      # sends GCP_RECONSTRUCTION_KEY, which resolves to the same secret.
      - --set-secrets=VLLM_API_KEY=avatar-reconstruction-key:latest
      - --set-env-vars=HF_HUB_OFFLINE=1

options:
  machineType: E2_HIGHCPU_8
  diskSizeGb: 100
  logging: CLOUD_LOGGING_ONLY

timeout: 3600s