Skip to content

perf: reuse verified tree adapter snapshots - #15

Merged
UlloaSP merged 2 commits into
developfrom
perf/tree-adapters
Oct 12, 2026
Merged

UlloaSP merged 2 commits into
developfrom
perf/tree-adapters

Conversation

@UlloaSP

@UlloaSP UlloaSP commented Oct 12, 2026 •

Copy link
Copy Markdown
Owner

RandomForest export/load previously rebuilt structure solely to decide where the state commitment belongs, and repeatedly validated/digested the same skops state. XGBoost rebuilt identical native tree structures through the copy and serialization round trips. This change shares verified operation-local snapshots while retaining received/native-state comparison and canonical claim/structure verification.

  • Sklearn main payload validation/digest: export 7 -> 2; load 5 -> 2. Structure extraction: export 4 -> 2; load 3 -> 1. Existing native storage checks remain.
  • XGBoost preflight: export 6 -> 2; load 2 -> 1. Structure extraction: export 4 -> 1; load 1 -> 1, keyed by immutable native bytes plus names/types/importance. Numeric UBJSON buffers stay views.
  • Preserve format, state commitment and structure bytes. The native serializers are unchanged. No dependency, trust-list, limit or core pipeline changes.

Warm medians of three runs, imports/training excluded, 3,000 x 12 seeded inputs:

Model Export before -> after Inspect before -> after Load before -> after
XGBClassifier (600 trees, depth 6) 10.147 -> 4.410 s 0.444 -> 0.448 s 2.973 -> 2.291 s
RandomForestClassifier (200 trees, depth 9) 15.918 -> 4.519 s 0.407 -> 0.303 s 11.340 -> 3.182 s
Control forest (1 tree, depth 2) 0.178 -> 0.058 s 0.009 -> 0.006 s 0.117 -> 0.018 s
GradientBoostingClassifier (300 trees, depth 3) 19.764 -> 3.867 s 0.101 -> 0.092 s 13.330 -> 3.181 s
ExtraTreesClassifier (200 trees, depth 9) 14.879 -> 4.328 s 0.290 -> 0.299 s 10.612 -> 3.099 s
RandomForestRegressor (200 trees, depth 9) 13.901 -> 3.995 s 0.399 -> 0.288 s 9.768 -> 2.794 s
XGBRegressor (600 trees, depth 6) 15.024 -> 6.134 s 0.716 -> 0.797 s 4.422 -> 3.362 s
Scaler → RandomForestClassifier (200 trees, depth 9) 9.223 -> 2.569 s 0.061 -> 0.047 s 7.228 -> 2.255 s

The requested RF 3 s export/2 s load and XGBoost 3 s export/1.5 s load targets are not met. Remaining cost is bounded skops preflight/audit/construction and shared canonical JSON verification. Final profiles: RF load 28.53 -> 8.32 s under profiler,45.53M -> 15.61M calls; XGBoost 8.72 -> 6.39 s,17.72M -> 13.13M calls. RF Merkle hashing 289,430 -> 5,426 calls; XGBoost bounded JSON decodes 622 -> 22. Closing the remaining gap needs further shared JSON comparison/encoding and sklearn reference/preflight optimization.

Validation:

  • Old/new differential proof across 15 model configurations: identical model members, claims, structure, commitments and whole bundles; old bundles load new and new bundles load old; predictions exactly equal.
  • Skops embeds temporary IDs/filenames and timestamps, so whole-byte proof replays one captured serializer output and fixes UUID/time. Fresh constructed-model serializations independently match the unchanged state commitments. XGBoost native bytes compare directly.
  • 38 hostile payload/structure/state cases have the same rejection class in old/new adapters.
  • 24 focused regression tests cover legacy digest encoding, allocation preflight, snapshot counts and mutation/cache isolation; all 24 ran in 2.82 s including imports; slowest test 0.12 s.
  • Acceptance scripts retain expected results: sklearn 18/19 (only HistGradientBoosting rejected), ONNX 10/10, owner's MLP pipeline both variants with zero probability difference, CatBoost four estimators with zero probability difference.
  • uv run ruff check .: all checks passed. uv run ruff format --check .: 140 files already formatted. uv run pyright: zero errors/warnings. uv run pytest: 1,270 passed, 91.89% coverage, 133.15 s. uv build: wheel and source archive produced.
  • Independent invariance review found one pre-allocation arithmetic defect, fixed and covered; no remaining findings. Every source/test/doc file remains below 300 lines.

Final validation also compared all 8 full-size benchmark models byte for byte, loaded both reader directions,and loaded the actual 8 pre-change benchmark artifacts. The complete final matrix was rerun after timing variance in unchanged XGBoost/inspect paths; all run sets are retained in Temp.

CI on 4a952a7:all six jobs successful,including Ubuntu/Windows tests and base-wheel smoke checks. https://github.com/UlloaSP/mlbundle/actions/runs/38257554841

@coderabbitai

coderabbitai Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4d3d3e1b-c994-44cc-966f-7875fda6a7b6

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@UlloaSP
UlloaSP merged commit 174385a into develop Oct 12, 2026
9 checks passed
@UlloaSP
UlloaSP deleted the perf/tree-adapters branch October 12, 2026 14:26
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.

1 participant