Skip to content

Read the prediction stage for predict rows in the roadmap (#481) - #514

Merged
godofecht merged 5 commits into
mainfrom
perf/481-kernel-svc-predict
Nov 19, 2026
Merged

godofecht merged 5 commits into
mainfrom
perf/481-kernel-svc-predict

Conversation

@godofecht

Copy link
Copy Markdown
Owner

Closes #481

Reproduction

There is no remaining inference loss to reproduce. On main at 645e6e4, one machine (Apple M4 Max, Accelerate, Flow toolchain at the CI pin 88aac509, -O3), with python benchmarks/run_headline.py --repeats 7:

row stage scikit-learn ms Flow ms speedup
KernelSVC_RBF iris predict 0.066 0.012 5.52x
KernelSVC_RBF iris fit 0.284 0.080 3.55x
KernelSVC_RBF digits predict 17.090 1.166 14.66x
KernelSVC_RBF digits fit 24.161 14.029 1.72x

The frozen CI artifact agrees in direction: predict at 6.87x on Iris and 3.33x on Digits. A CI run from today on the same prediction code (run 44422898477, AMD EPYC 9V45) measured 3.09x on Iris and 4.37x on Digits.

This PR changes no prediction code, so there is no before and after timing for the estimator. It adds the prediction-only evidence the issue asks for and fixes the generator that reported fit time as predict evidence.

Prediction-only curves

benchmarks/bench_predict_kernel_svc.flow and benchmarks/bench_predict_kernel_svc.py build bit-identical float32 inputs, fit outside the timing window, and time predict alone. Three classes, C=1, gamma = 1 / n_features, max_iter=1000 on both sides. The training-set size moves the support-vector count, and each row reports the count each side ended with.

axis queries train rows features support (sklearn / Flow) scikit-learn ms Flow ms speedup accuracy (sklearn / Flow)
batch 1 300 16 214 / 214 0.0423 0.0022 19.08x 1.000 / 1.000
batch 10 300 16 214 / 214 0.0833 0.0105 7.93x 1.000 / 1.000
batch 100 300 16 214 / 214 0.5094 0.0631 8.07x 0.990 / 0.990
batch 1000 300 16 214 / 214 4.8073 0.5272 9.12x 0.995 / 0.995
batch 10000 300 16 214 / 214 47.3627 5.2640 9.00x 0.995 / 0.995
train 1000 60 16 58 / 58 1.3900 0.1768 7.86x 0.794 / 0.794
train 1000 120 16 108 / 108 2.5006 0.2878 8.69x 0.992 / 0.992
train 1000 1000 16 416 / 416 9.1716 0.9673 9.48x 1.000 / 1.000
features 1000 300 4 267 / 267 5.8926 0.6456 9.13x 0.593 / 0.593
features 1000 300 64 208 / 208 7.8774 0.5404 14.58x 1.000 / 1.000
features 1000 300 256 267 / 268 20.2516 0.9279 21.82x 1.000 / 1.000

No regime measured here loses. The thinnest is 7.86x. The two sides keep the same support vectors in ten of eleven cases and differ by one row in the other, and accuracy matches to three places everywhere.

The stale claim

benchmarks/OPTIMIZATION_ROADMAP.md listed SVC.predict at 2.20x. That number was the mean end-to-end speedup of the two KernelSVC rows, and end to end is dominated by fit. rank_optimization_opportunities.py gave every operation of an estimator the same end-to-end figure.

The generator now reads the stage that times the operation:

  • fit reads the fit stage,
  • predict, predict_proba, decision_function and transform read the prediction stage,
  • each row records its observed_flow_speedup_basis, and the Markdown table has a Basis column,
  • the end-to-end mean stays in the JSON as end_to_end_flow_speedup and is not used for ranking,
  • a stage with no resolved timing yields no evidence. A prediction faster than the clock resolution is recorded as 0 ms and was otherwise at risk of reading as an infinite speedup.

Regenerated from the committed inputs with python benchmarks/rank_optimization_opportunities.py:

operation before after basis
SVC.predict 2.20x 5.10x prediction stage
SVC.predict_proba, SVC.decision_function 2.20x 5.10x prediction stage
SVC.fit 2.20x 2.56x fit stage
KernelRidge.predict 3.88x 1.85x prediction stage
KernelRidge.fit 3.88x 4.11x fit stage
GaussianNB.predict 45.66x 29.31x prediction stage
GaussianNB.fit 45.66x 101.65x fit stage

The correction runs in both directions. KernelRidge.predict and GaussianNB.predict were overstated by a fast fit.

predict_proba and decision_function are not timed by the headline benchmark. They take the prediction-stage ratio as the nearest measured evidence, and the basis field says so.

Tests

benchmarks/test_rank_optimization_stages.py pins the operation to stage mapping, the separation of stages on a row where fit loses and prediction wins, the exclusion of parity-unresolved rows, the handling of an unresolved stage, and runs the generator on the committed inputs to confirm SVC.predict carries the prediction-stage mean. Against the generator on main it fails at import. On this branch all 24 checks pass.

It is added to the existing validation step in .github/workflows/flow.yml, one line. No workflow is added.

The other checks in that step all pass locally: fixtures.py, verify_fixtures.py, test_generate_headline_summary.py, test_disparity_regression_policy.py, test_config_equivalence.py, publish_headline_v2.py --check, validate_execution_substrate.py, and validate_published_claims.py.

No file under lib/, tests/ or examples/ changes, so the Flow test suite is the same as on main, where it passed 106 of 106.

Not done here

  • architecture_performance_map.json is left as committed. It reports one end-to-end figure per headline row against the fit substrate and makes no predict claim. Regenerating it locally would also move the substrate means that README.md quotes, which is the freeze job's work.
  • Only optimization_roadmap.json and OPTIMIZATION_ROADMAP.md are regenerated here. The freeze job on main will rewrite both from the CI run.
  • The curves come from one shared machine at a load average near 7. They are not committed as an artifact and no CI gate reads them.
  • KernelSVC prediction still calls libm exp once per query and support-vector pair. The vectorizable exponential added for [Perf #478] KernelRidge RBF predict: eliminate ~7.7x inference gap with batched kernel evaluation #488 would apply here once that lands. It is left out so this PR does not depend on that one.
  • The end-to-end KernelSVC rows at 1000 training rows in scaled_ci_history.json lost in two of five CI runs. Fit dominates those rows and belongs to [Perf #478] KernelSVC fit: match libsvm training efficiency without changing semantics #480.

The optimization roadmap gave every operation of an estimator the same
end-to-end speedup. End to end is dominated by fit wherever fit is the
slower stage, so SVC.predict was listed at 2.20x while the prediction
stage of the same two headline rows ran at 6.87x and 3.33x.

rank_optimization_opportunities.py now reads the fit stage for fit and the
prediction stage for predict, predict_proba, decision_function and
transform. Each row records which stage its number came from, and the
end-to-end mean is kept beside it without feeding the ranking. A stage
with no resolved timing yields no evidence.

benchmarks/bench_predict_kernel_svc.flow and its .py counterpart time
KernelSVC prediction alone across batch size, training-set size and
feature count, and report the support-vector count on each side. No
regime measured loses; the thinnest is 7.86x.

benchmarks/test_rank_optimization_stages.py pins the stage mapping and
runs in the existing validation step.

The roadmap JSON and Markdown are regenerated from the committed inputs.
@godofecht

Copy link
Copy Markdown
Owner Author

CI on this PR, runs 44429778111 and 44429777955.

Passing: Run all tests and examples (117 of 117), Canonical benchmark contract, Canonical 19/19 KMeans parity, FLOW syntax and imports, Python native package, sklearn execution architecture map, disparity-audit. The FLOW syntax and imports job ran the new benchmarks/test_rank_optimization_stages.py and printed all roadmap stage checks passed.

Two jobs fail, and both fail the same way on unmodified main in run 44425142857, which I started read-only to check:

job failure on this PR failure on main
Scaled benchmark report RandomForest fit_ms over the September baseline at two sizes RandomForest fit_ms over the baseline at three sizes
Wide estimator matrix linear_svr at 0.99x linear_svr at 0.69x

This PR changes no file under lib/, so neither row can have moved because of it. I have not changed the baselines.

@godofecht
godofecht merged commit 2a0523d into main Nov 19, 2026
11 checks passed
@godofecht
godofecht deleted the perf/481-kernel-svc-predict branch November 19, 2026 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Perf #478] KernelSVC predict: eliminate remaining small-shape inference loss and preserve Digits win

1 participant