Pipelines, components and runs
You write your pipelines and model code your own way, in Kubeflow Pipelines v2. Pipewright needs a small contract at the edges, then releases the code, starts runs as your team’s identity and judges what they produce. A use case can also have no pipeline code at all: BigQuery ML use cases get Pipewright’s own pipelines.
Your code and Pipewright
| Your choice | The contract | |
|---|---|---|
| Layout | Pipeline file and function names, the components folder, how config is split into files (include:), table schema file names | usecases/<name>/usecase.yaml, with metadata.name equal to the folder; overrides in usecases/<name>/environments/<env>.yaml |
| Pipelines | Steps, libraries, frameworks, models; anything inside a step, including Ray jobs | Kubeflow Pipelines v2 (kfp pinned to the version Pipewright compiles with); every pipeline accepts project, region, source_uri and run_id; components take their image from COMPONENT_IMAGE |
| Configuration | Which sections you use; most have defaults | An optional ml_config parameter: a pipeline that declares it receives the resolved configuration (data contract, gates, monitoring, retraining) |
| Evaluation | How you compute metrics | Training writes an evaluation record, evaluation.json, next to the model files |
| Files | Configuration files end in .yaml; a .yml file is refused with a message to rename it |
pipewright new-usecase copies a complete example: --from churn (the default: training and inference pipelines, components, tests, sample data), minimal (training only, required keys only), features (feature tables), ray, bqml, or --from-bq <table> --label <column>, which drafts the data contract from a BigQuery table. The components in components/ are yours from then on.
The evaluation record
{
"metrics": {"auc": 0.81, "calibration_error": 0.03},
"slices": {"contract_length_months": {"12": {"rows": 400, "auc": 0.79}}},
"champion": {"auc": 0.80, "_version": "3"},
"decision": "approve"
}
Pipewright checks the gates itself. Your evaluation step may apply them, but Pipewright does not take its word for it: before a version becomes the champion (model approve) or is served (deploy-model), it recomputes every metric gate, slice gate and the champion margin from this record, against the rules of the release that trained the version. A rewritten evaluation step that drops a gate cannot promote a failing model. slices is needed for slice gates; champion holds the champion’s metrics on the same test rows, or null when there was none. More in Evaluation and approvals.
The component runtime
Components import helpers from pipewright_runtime, which the release puts in the component image:
| Helper | What it does |
|---|---|
read_source(...) | Reads the run’s rows from gs:// (CSV, Parquet) or bq://, with features joined point in time and the label window applied (labels=True) |
bigquery_client(project, ml_config) | A BigQuery client with the environment’s key applied to every query (private environments require one) |
write_table(...) | Writes rows to one of the use case’s tables, in BigQuery, Parquet or both (outputs.store) |
emit_event(...), log(...) | A lifecycle event, and a structured log line labelled with the use case and run |
write_snapshot(...) | Writes the rows a run read to data.snapshot_table, for replays |
write_lineage(...) | Writes lineage.json next to the evaluation record |
fairness_measures(...) | Group measures for fairness gates |
approved_download(...) | Downloads exactly the approved model files, each checked by SHA-256 (1.4.1) |
ray_cluster(...), ray_job(...) | A Ray cluster made for this step of this run, and a job on it |
Compute per step
steps:
train: { cpu: "8", memory: 32G, retries: 1 }
tune: { gpu: { type: NVIDIA_L4, count: 1 } } # within policies.accelerators
prepare: { cache: false }
Sizes are patched into the compiled template at release: no code change. They may differ per environment, so dev can run small and production large.
Ray steps
A step that needs a cluster asks for one in configuration; the cluster exists only for that step of that run.
steps:
tune-on-ray:
ray: { head_machine: n1-standard-16, workers: 1 } # within the platform's limits
components:
ray_requirements: ray-requirements.txt # extra packages for the nodes
from pipewright_runtime import ray_cluster, ray_job
with ray_cluster(ml_config, "tune-on-ray", run_id) as cluster: # made by the launcher, deleted after
ray_job(ml_config, cluster, f"python -m ray_tune_job {trials.uri}", run_id=run_id)
- Who makes it: the launcher, as your runner, from the live release, with the environment’s key and network. The step only names itself.
- What runs: a Ray image the release builds on the platform’s base image, with your component code and
ray_requirements. - Cleanup: the step deletes the cluster when it ends, even on errors; the launcher’s tick deletes any cluster whose run ended or whose
max_minutespassed. - Sizes: a head needs at least 16 vCPUs and more than 18 GB of memory (smaller heads run but their job API never answers); a Ray step does not size itself (no
cpu,memoryorgpu).validatechecks both. - On private GKE: the same calls get a KubeRay cluster; the platform may instead give a team a standing cluster that scales its workers to zero.
While developing, use a Ray cluster of your own from a notebook. Pipelines never use it: every run, dev to production, gets its own cluster.
What starts a run
| Trigger | In config/triggers.yaml | How it works |
|---|---|---|
| A file lands | landing: { suffixes: [.csv], pipeline: training } | A file under your tenant’s landing prefix starts the pipeline. Set landing: null for use cases fed from BigQuery |
| A schedule | schedules: [{ name, cron, timezone, pipeline, source_uri }] | pipewright schedules sync creates Cloud Scheduler jobs, or Kubernetes CronJobs where the manifest says so. pipeline: online_sync refreshes an online store |
| An API call | api: true | An upstream job posts {"usecase", "pipeline", "source_uri", "run_key"} to the launcher’s /run with an ID token |
| By hand | pipewright run --env dev --usecase churn --pipeline inference --source-uri bq://...; in a private environment it publishes to the run requests topic |
A run’s source is a gs:// object (CSV or Parquet) or a bq://project.dataset.table table or view. Every run uses the live release: the launcher looks up its contract and submits the pinned template with the pinned image, as your runner identity.
Run keys: retries never duplicate
A run’s ID is derived from its trigger: the file and its generation, the schedule and its time, or the run_key you pass. The same key always maps to the same run, so a redelivered message or a retried call never starts a second one (it records run.duplicate).
Reproducible runs and label windows
data:
snapshot_table: churn_raw_customers # rows each run read, tagged with run_id
label_source: # the label from a table of events, within a window
table: bq://${project}.sales.purchases
time_column: purchased_at
window_days: 20
- Replay a run:
pipewright run --replay <run_id>trains again on exactly the rows that run read, whatever changed in the source since. - Maturing labels are not negatives: a row is 1 when the event table has an event for its key within
window_daysafter its cut-off. Rows whose window has not closed by the newest event are dropped, so last week’s sign-up is not counted as a 0.
What the model predicts
data.label.task | Metrics | Default primary metric |
|---|---|---|
binary (default) | auc, pr_auc, accuracy, f1, precision, recall, log_loss, brier, calibration_error | auc |
multiclass | accuracy, balanced_accuracy, f1_macro, f1_weighted, precision_macro, recall_macro, log_loss | f1_macro |
regression | rmse, mae, mape, r2, median_absolute_error | rmse |
clustering, decomposition, forecast | BigQuery ML only: see BigQuery ML |
Errors (rmse, mae, mape, median_absolute_error, log_loss) are lower-is-better: a gate on them takes a max, the champion must have a lower value, and tuning minimises them.
Tables and outputs
config/tables.yaml lists the tables a use case owns, each with a schema file; pipewright tables sync creates them and later applies additive changes only. Tables live in BigQuery by default; outputs.store: gcs writes them as Parquet under the tenant’s outputs location instead (with BigQuery external tables of the same names), and both does both.
Two orchestrators, the same pipelines
One setting in the manifest, orchestrator: kfp, runs the same templates on Kubeflow Pipelines in a private GKE cluster, with Ray on KubeRay and serving on KServe. The CLI, contracts and everything outside the cluster stay the same. Tutorial 6 walks through it.