Repository navigation
Treat only a standalone baseline as a relative outcome constraint - #5337
Open
uditstocks wants to merge 2 commits into
Open
uditstocks wants to merge 2 commits into
uditstocks wants to merge 2 commits into
Conversation
An outcome constraint was marked relative whenever the text "baseline" appeared anywhere in its expression, including inside a metric name. So "baseline_latency <= 10" was parsed as a relative constraint with a bound of +900% instead of an absolute bound of 10, and names such as "model.baseline" were rewritten to "model.1". Match "baseline" only as a standalone token, as the parser did before the expression refactor, where only a SymPy symbol named exactly "baseline" made a constraint relative. Signed-off-by: Udit Sharma <uditsharma9981@gmail.com>
The standalone-token check treated any hyphen before "baseline" as part of a metric name, so "qps >= -baseline" lost its relative marker and "baseline" became a second metric. sanitize_name joins a hyphen into a name only after a word character, so match that: "qps-baseline" stays a metric name and "-baseline" stays a sign. Signed-off-by: Udit Sharma <uditsharma9981@gmail.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
An outcome constraint is treated as relative whenever the text
baselineappears anywhere in its expression, also inside a metric name. Sobaseline_latency <= 10becomes a relative constraint of +900% instead of an absolute bound of 10, andlatency_vs_baseline >= 2becomes +100%. The constraint still prints asOutcomeConstraint(baseline_latency <= 10), so nothing shows the change. Without a status quo arm, the optimization then stops at the first Bayesian optimization trial withDataRequiredError: Optimization config has relative constraint, but model was not fit with status quo.With a status quo arm (client.attach_baseline,baseline_latencyof 10), the first Bayesian optimization trial fails instead withValueError: StandardizeY transform does not support relative constraint OutcomeConstraint(baseline_latency <= 100):Derelativizeturns +900% into 100, and its rebuilt expression is again read as relative. On this branch the same run completes its Bayesian optimization trials.The same check has two more effects:
cost + baseline_cost <= 5is rejected byClient.configure_optimizationwith "Scalarized outcome constraints cannot be relative".model.baseline <= 10(ormodel/baseline) becomes the metricmodel.1with a bound of +900%, because the standalone replacement\bbaseline\b->1also matches after a dot or a slash.Cause
_parse_constraint_expressioninax/core/outcome_constraint.pystarts withif "baseline" in expression_str:. It came with the expression refactor in #5000. Before that,parse_outcome_constraintinfrom_string.pytreated only a SymPy symbol named exactlybaselineas the relative marker, so these metric names worked.Fix
Match
baselineonly as a standalone token: not next to a word character or one of the separators thatsanitize_namekeeps inside metric names (.,:,/,|,~,@,-, and(after it). A-beforebaselinecounts as part of a name only after a word character, as insanitize_name, soqps-baselineis a metric name whileqps >= -baselinestays relative. The same pattern is used for the check, for stripping* baseline, and for the standalonebaseline->1replacement. Expressions that usebaselineas intended (qps >= 0.95 * baseline,qps >= baseline) parse exactly as before. The library change is 10 lines added and 3 removed in one file; the rest is tests.flowchart TD A[Constraint baseline_latency at most 10] --> B{Parse the expression} B -->|Before| C[Text baseline found inside the metric name] C --> D[Relative bound of 900 percent] B -->|After| E[Only a standalone baseline counts] E --> F[Absolute bound of 10]Narrated recording, before then after (sound on):
evidence.mp4
Repro, as typed in the recording
On
main(08aa942), five trials complete, then:On this branch, all six trials complete (the sixth is the first Bayesian optimization trial), then:
The recording is a plain Python REPL with this branch's Ax. Before the session starts, Ax's INFO logs are turned off and
sys.tracebacklimitis set to 0, so an error shows as its last line only. Repeated typing is cut; nothing else is edited.Edge cases and unchanged behaviour checked
Shown in the third part of the recording, in a fresh
Clienton this branch with these constraints:latency_vs_baseline >= 2stays absolute,>= 2.0(onmain:>= 100.0%).model.baseline <= 10keeps its name and its bound,<= 10.0(onmain: metricmodel.1,<= 900.0%).cost + baseline_cost <= 5is accepted as an absolute two-metric constraint (onmain:UserInputError: Scalarized outcome constraints cannot be relative).qps >= 0.95 * baselineis still relative,>= -5.0%.cpu <= baselineis still relative,<= 0.0%.latency <= 10is still absolute,<= 10.0.Checked by the new unit test only:
model/baseline <= 3andqps-baseline <= 3(absolute),baseline_qps >= 0.95 * baseline(relative, -5%),model.baseline >= baseline(relative, 0%) andqps >= -baseline(still relative, as onmain).Not covered: a multi-word metric name with
baselineas a separate word, such aslatency vs baseline, still counts as relative, as onmain.Tests
test_BaselineInMetricNameinax/core/tests/test_outcome_constraint.py, and one more case intest_relative_scalarized_constraints(a + 2 * baseline_b <= 1.0) inax/api/utils/instantiation/tests/test_from_string.py. Onmainthey fail (900.0 != 10.0,100.0 != 2.0,['model.1'] != ['model.baseline'],['model/1'] != ['model/baseline'],['qps-1'] != ['qps-baseline'],400.0 != 5.0, andUserInputError: Scalarized outcome constraints cannot be relative). On this branch they pass.pytest ax/core/tests/test_outcome_constraint.py ax/api/utils/instantiation/tests/test_from_string.py ax/core/tests/test_optimization_config.py ax/utils/common/tests/test_sympy.py ax/utils/common/tests/test_string_utils.py ax/adapter/transforms/tests/test_relativize_transform.py ax/adapter/transforms/tests/test_derelativize_transform.py: 86 passed, 77 subtests passed.pytest ax/api/tests/test_client.py -k "configure or constraint or baseline": 13 passed.pytest ax/storage/json_store/tests/test_json_store.py -k "constraint or Constraint or relative": 2 passed, 5 subtests passed.ufmt check(black 25.11.0 and usort 1.1.0 as in.pre-commit-config.yaml, and again with theruff-apiformatter set inpyproject.toml) andflake87.0.0 on the changed files: clean.TestCaseinstalls aSIGALRMhandler, which Windows does not have, so pytest ran through a small wrapper that mapsSIGALRMtoSIGTERMand makessignal.alarma no-op. Pyre was not run.