agentleFS
Google CloudKnown publisherGoogleCloudPlatform/cloud-solutions/projects/legacy-detox-demo/skills/unified-model-registry/SKILL.md

unified-model-registry

Skill135 starsChanged 6 months agoApache-2.0View on GitHub

This skill codifies the deployment and serving of models trained via Spark and BigQuery ML. It emphasizes "detoxing" the serving layer by choosing the most lightweight and cost-effective serving method based on model complexity. It supports three serving paths: 1. Lean JSON Serving (Spark - Simple Models): Extracting model parameters (weights, vocabulary maps) to a JSON file and serving via a pure Python/Numpy container (microsecond latency, no JVM). 2. ONNX Serving (Spark - Complex Models): Exporting the Spark ML pipeline…

The file

We split this skill into the rules it gives an agent

5 rules. About 0 are common, 5 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈5

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    When generating deployment code:

    line 34
  2. Distinctive:

    If the model is a simple linear model (e.g., Logistic Regression) trained in Spark, always propose the Lean JSON export.

    line 37
  3. Distinctive:

    If the model is complex (e.g., Random Forest) trained in Spark, propose

    line 39
  4. Distinctive:

    If the model is trained in BQML, always use the native Vertex AI deployment path.

    line 41
  5. Distinctive:

    Avoid Heavy Containers: Do not package Spark or Java into the serving container unless absolutely necessary.

    line 43

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Skill: Unified Model Registry & MLOps Serving

<!-- Disabling markdownlint MD029 to provide explicit ordering to avoid confusing the LLM. --><!-- markdownlint-disable MD029 -->

1. Description & Rationale

This skill codifies the deployment and serving of models trained via Spark and BigQuery ML. It emphasizes "detoxing" the serving layer by choosing the most lightweight and cost-effective serving method based on model complexity.

It supports three serving paths:

  1. Lean JSON Serving (Spark - Simple Models): Extracting model parameters (weights, vocabulary maps) to a JSON file and serving via a pure Python/Numpy container (microsecond latency, no JVM).
  2. ONNX Serving (Spark - Complex Models): Exporting the Spark ML pipeline to ONNX format and serving via ONNX Runtime.
  3. Native Vertex AI Serving (BQML - All Models): Exporting BQML models to GCS (TensorFlow/XGBoost) and deploying to Vertex AI Endpoints using pre-built containers.

2. Environment Prerequisites

  • Libraries: google-cloud-aiplatform (Vertex AI SDK).
  • For ONNX: onnxmltools, onnxruntime (in the serving environment).
  • For Lean Serving: numpy (in the serving environment).

3. Agent Execution Guidelines (System Prompts)

When generating deployment code:

  1. Assess Complexity:
    • If the model is a simple linear model (e.g., Logistic Regression) trained in Spark, always propose the Lean JSON export.
    • If the model is complex (e.g., Random Forest) trained in Spark, propose ONNX export or a custom container.
    • If the model is trained in BQML, always use the native Vertex AI deployment path.
  2. Avoid Heavy Containers: Do not package Spark or Java into the serving container unless absolutely necessary.

4. Opinionated Code Patterns

A. Lean JSON Export (Spark - Simple Models)

Extract parameters from the Spark pipeline to bypass JVM/MLeap requirements.

import json

# Extract metadata and parameters from pipeline stages
# (Assumes: 0: GenderIndexer, 1: CountryIndexer, 2: LabelIndexer, 4: Scaler, 5: LR)
gender_map = pipeline_model.stages[0].labels
country_map = pipeline_model.stages[1].labels
label_map = pipeline_model.stages[2].labels

scaler_std = pipeline_model.stages[4].std.toArray().tolist()

lr_model = pipeline_model.stages[5]
coefficients = lr_model.coefficientMatrix.toArray().tolist()
intercept = lr_model.interceptVector.toArray().tolist()

model_data = {
    "gender_map": gender_map,
    "country_map": country_map,
    "label_map": label_map,
    "scaler_std": scaler_std,
    "coefficients": coefficients,
    "intercept": intercept,
}

# Save locally and upload to GCS
with open("/tmp/model.json", "w") as f:
    json.dump(model_data, f, indent=2)
# !gcloud storage cp /tmp/model.json gs://{BUCKET_NAME}/models/model.json

B. ONNX Export (Spark - Complex Models)

For complex models, convert the Spark ML pipeline to ONNX.

import onnxmltools
from onnxmltools.convert.sparkml import convert_sparkml
from onnxmltools.convert.sparkml.utils import SparkSessionForTest # Or use active session

# Define input schema for ONNX
from onnxmltools.convert.common.data_types import FloatTensorType, StringTensorType
initial_types = [
    ('age', FloatTensorType([None, 1])),
    ('gender', StringTensorType([None, 1])),
    ('country', StringTensorType([None, 1]))
]

# Convert the model
onnx_model = convert_sparkml(pipeline_model, 'SparkML_Pipeline', initial_types)

# Save the ONNX model
onnxmltools.utils.save_model(onnx_model, '/tmp/model.onnx')
# Upload to GCS...

C. Native Vertex AI Deployment (BQML)

Export the BQML model and deploy to a Vertex AI Endpoint.

from google.cloud import aiplatform
import bigframes.pandas as bpd

# 1. Export BQML model to GCS (BQML exports as TF SavedModel or XGBoost depending on model type)
bq_client = bpd.get_global_session().bqclient
export_sql = f"EXPORT MODEL `{MODEL_NAME}` OPTIONS(URI = 'gs://{BUCKET_NAME}/models/bq_model')"
bq_client.query(export_sql).result()

# 2. Upload to Vertex AI Model Registry
# (Choose the appropriate container, e.g., TF serving for Logistic Regression)
serving_container_image_uri = "us-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-15:latest"

uploaded_model = aiplatform.Model.upload(
    display_name="bq_model",
    artifact_uri=f"gs://{BUCKET_NAME}/models/bq_model",
    serving_container_image_uri=serving_container_image_uri,
)

# 3. Deploy to Endpoint
endpoint = uploaded_model.deploy(
    machine_type="n1-standard-2",
    min_replica_count=1,
    max_replica_count=1,
)

5. Verification Checklist

  • Serving Path Selected: Verify the serving path matches the model complexity.
  • No JVM in Lean: If using Lean JSON, ensure the serving container has no Java dependency.
  • Vertex AI Upload: Verify the correct container image is used for the model type (e.g., TensorFlow vs XGBoost).

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.