Manual / Guides

A/B testing of models

A gate tells you a candidate scores better on held-out data. It does not tell you the candidate is better for the business: more renewals, fewer complaints, more revenue. An A/B test answers that on live traffic. Some customers are scored by the champion (the control), some by the candidate (the treatment), and a business outcome is compared between the groups against a plan fixed before the test starts. A person concludes. New in 1.4.3, and off until ab_test.enabled is true: a use case that sets none of it scores and serves exactly as in 1.4.2.

QuestionAnswered by
Who sees which model?sticky assignment: a hash of the test’s name and the unit, the same in batch, SQL and online
Is the comparison clean?share checks before any metric is read
Is the candidate better?the metric per arm with a 95% interval, at the planned sample
Is it doing harm?technical and business guardrails, which stop the treatment
Who decides?named approver groups, one person one voice

How it works

Sticky assignment. Each unit (a customer, an account, a device: a column of the data contract) is assigned by a hash of the test’s name and the unit, compared with the treatment’s share in basis points. The same function runs in batch scoring, in BigQuery ML SQL and in the online gateway, so a customer keeps its arm wherever it is scored. A different test name gives an independent split.

Batch. A scoring run of a use case with a running test scores each unit with its arm’s model and writes ab_test and arm beside each score. Being scored is the exposure. The treatment’s files are checked against its approval before any customer is scored with it; when they cannot be checked, everyone is scored with the control and the run says why.

Online. pipewright ab start deploys the treatment on its own endpoint, <usecase>-ab-endpoint (dedicated machines, or the use case’s shared pool at no extra machine cost). The lookup gateway becomes the router: it assigns each call’s units, sends each group to its arm, answers with each unit’s arm and writes one exposure line per unit to Cloud Logging, off the request path. A log sink copies the lines into the team’s dataset. Callers that send their own features get a router-only gateway for the test.

On KServe (private GKE) the treatment is a second InferenceService and the router runs in the team’s serving namespace; a NetworkPolicy admits only the router to the treatment, so nobody can call it around the assignment. A pause or a lower allocation reaches every router pod within 30 seconds.

Shadow. mode: shadow sends every call to the control, which answers, and a copy to the treatment in the background. Only a comparison is logged. A shadow shows how a candidate behaves on live calls; it cannot show it is better for the business, so it always ends with the control.

Turn it on

The test is part of the use case, reviewed and released like the rest, in config/ab_test.yaml:

ab_test:
  enabled: false                       # on per environment, below
  name: lapse-v7                       # once per use case and environment
  unit: customer_id
  allocation: { treatment_bp: 1000 }   # 10% of customers
  metric:
    name: renewed
    source: bq://my-project.my_dataset.renewals
    time_column: renewed_at
    window_days: 30
    minimum_effect: 0.03
  guardrails:
    business:
      - { name: complaints, source: bq://my-project.my_dataset.complaints, time_column: raised_at,
          direction: lower, max_drop: 0.05 }
  decision:
    approvals: { required: [model-risk] }

Switch it on in the environment that runs it, with that environment’s candidate, in environments/prod.yaml:

ab_test:
  enabled: true
  arms: { treatment: { model_version: "7" } }

Only enabled, arms, allocation, layer, duration, publish and decision may differ per environment. For a batch test, add ab_test and arm (STRING, NULLABLE) to the predictions table; validate says so when they are missing. pipewright explain ab_test describes every key.

Run a test

pipewright ab plan --env prod --usecase churn --baseline 0.30 --per-day 400   # units needed, days, cost
pipewright ab start --env prod --usecase churn                                # needs approvals.deploy_model
pipewright ab status --env prod --usecase churn                               # ends with the next step
pipewright ab analyse --env prod --usecase churn                              # now, as you
pipewright ab set --allocation 500 --reason "fewer customers" ...             # only down
pipewright ab pause | resume | stop --reason "..." ...
pipewright ab decide --winner treatment --reason "..." --group model-risk ...
pipewright ab conclude --reason "..." ...

start refuses a treatment without passed gates or files that match its approval, a second test on the same use case, a test during a closed retrain loop, forecasts and unsupervised models, and a unit that is not a contract column. The configuration is fixed at the start by its digest: change the metric or the arms and the analysis refuses. Stop the test and start a new one instead.

The analysis

The launcher runs the analysis on analysis.schedule as the team’s runner; each run appends a row of aggregates to <usecase>_ab_results and never writes a unit.

  1. Share checks first. The share per arm against the plan (chi-square and a binomial bound), the gateway’s unassigned, dropped and mismatched calls, and calls to the treatment that bypassed the router. Any of them blocks a decision. Units moved to the control by a lower allocation, a pause or the breaker are reported as moved; only a unit that went from control to treatment, impossible by design, blocks.
  2. The metric per arm on exposed units, outcomes within window_days of each unit’s first exposure: the difference and lift with a 95% interval (proportions, means and ratios).
  3. The sample. ab plan sizes the test from minimum_effect, alpha, power and the baseline. A decision is due at the planned sample after min_days, or at max_days.
  4. CUPED removes variance the treatment could not have caused, with a covariate from before the test: the same confidence with fewer units.
  5. Sequential testing (mSPRT): a p-value you may look at every day without inflating false positives, so a clear result can end a test early.
  6. Segments: the result per value of contract columns, for batch tests.

Guardrails

Technical (online). The gateway keeps a breaker on the treatment’s last calls: above breaker.max_error_rate its units go to the control at once. Each hour the launcher compares the arms as a canary does (error rate and latency); a confirmed breach sets the allocation to 0 everywhere, opens the decision and emits ab_test.guardrail_breached.

Business. Each guardrails.business metric is analysed like the primary one and breached when the treatment is worse by more than max_drop and the harm is significant.

Decisions and the record

A test needs a person to end it. Every group in decision.approvals.required decides with ab decide; groups that disagree leave the decision open, and ab status says so. pipewright decisions pending lists ab-decide and ab-conclude items for GitHub environments. Concluding with the treatment as winner makes it the default through the normal approval (gates checked again, files checked); deploy it as usual. Any other outcome removes the treatment.

Events ab_test.started to ab_test.stopped record every step, pipewright lineage shows the tests a version was in, and the test’s record (digest, allocation history, newest analyses, decision and approvers) is kept in the artifacts bucket. ab_test.publish copies the events, and where the platform allows pseudonymised exposures, to a feed topic for the team’s own tools.

Tests that share customers: layers

A churn test and an upsell test on the same customers contaminate each other. policies.ab_test.overlap (allow, warn or refuse) judges that at start. Layers keep such tests apart: ab_test.layer: { name: customers, share_bp: 3000 } claims a range of the layer’s customers that no other running test in the layer can claim, so a customer is in at most one of them. The price is a smaller sample; ab plan --per-day divides by the share.

For the platform team

In the starter, give the team ab_test in terraform.tfvars (tenants = { churn = { ab_test = {} } }): the exposure sink, the gateway’s identity, the analysis job and the launcher’s reads. The manifest’s policies.ab_test sets the rules every test is held to: allowed, required_approvers, max_treatment_bp, min_days, required_guardrails, overlap and feed_exposures. A running test can always be read, paused, analysed, decided and stopped, even after the rules tighten.

Pipewright Enterprise builds the same in its blueprint (customer-managed keys on the feed), shows every test in Fleet View’s Experiments pages with tests that share a unit across use cases and environments, and adds evidence control EV-18: a version’s tests ran as promised and were decided by every required group.

What it costs (list prices)

ItemPrice
A dedicated treatment armabout $80 a month per n1-standard-2 replica; nothing extra on a shared pool
The gateway as routerabout $0.40 per million calls plus its CPU time
Exposures in BigQueryabout 7 cents a month per million lines kept; log routing is free
The analysisone query per run
The feed (optional)$40 per TiB published

Limits

  • One active test per use case.
  • Forecasts and unsupervised models have no unit-level outcome to compare, and are refused.
  • On KServe, callers send features (router-only mode) and reach the router inside the cluster.

Related: Serving health and live quality, Evaluation and approvals, Events.