You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The canonical Digits RandomForest row is parity-eligible but still has an absolute accuracy disparity of roughly 0.0194. Because the estimator compounds tree structure, bootstrap sampling, feature subsampling and per-tree RNG, aggregate accuracy alone is insufficient evidence.
Work
Persist and compare for the canonical split:
bootstrap sample indices per tree
per-tree random seeds / RNG consumption order
feature-subsampling choices
learned tree depth/node counts
per-tree predictions and ensemble vote margins
tie-breaking and class-order behavior
Match sklearn randomness semantics where practical, then identify whether remaining error comes from individual-tree semantics or ensemble construction.
Acceptance criteria
The first ensemble-level divergence is identified deterministically.
The current ~0.0194 predictive gap is materially reduced without widening tolerances.
Per-tree and ensemble-state disparities are emitted into the persistent disparity artifact so an eligible aggregate score cannot hide structural drift.
Verified against the frozen canonical evidence on main (c1e01df).
benchmarks/disparity_report.json, digits RandomForest accuracy: score_abs_diff is 0.01944444700000003, unchanged from the ~0.0194 figure this issue was filed against. Both final_parity_status and strict_diagnostic_status are "approximately equivalent". runtime_ratio_sklearn_over_flow is 0.2629, so Flow is about 3.8x slower.
model_state_diagnostics for this row is empty {}. No bootstrap indices, per-tree seeds, feature-subsampling choices, tree depths, per-tree predictions or vote margins are persisted by either implementation. benchmarks/bench_flow_v2.flow emits DETAIL| records only for KMeans and PCA.
lib/scikit/ensemble.flow does build bootstrap samples (bootstrap_indices at line 60), so the data exists in the implementation. It is simply never emitted for comparison.
No merged PR addresses ensemble randomness alignment.
This row is downstream of #204: the per-tree learner is the same DecisionTree, so the identical 0.0194 gap on both rows is suggestive and worth confirming before ensemble-level work starts.
Remaining work: emit per-tree bootstrap indices, RNG seeds and consumption order, feature-subsample selections, node counts and depths, plus per-tree predictions and ensemble vote margins as DETAIL| records on both sides; add an ensemble comparison to generate_disparity_report.py that reports the first divergent tree index and whether the divergence is in sampling or in the learner; then align sklearn's randomness semantics where the difference is accidental.
#207 is done for this row. PR #402 adds per-tree ensemble state on both sides and
the pairing logic that turns it into model_state_diagnostics.
What you can now read straight out of disparity_report.json
Digits RandomForest, score_abs_diff still 0.019444447:
Field
Flow
sklearn
n_trees
10
10
max_features_per_split
8
8
tree_node_counts
307,309,329,331,293,291,321,295,339,303
271,353,287,281,303,339,339,327,325,287
tree_leaf_counts
154,155,165,166,147,146,161,148,170,152
136,177,144,141,152,170,170,164,163,144
tree_max_depths
all 10
all 10
tree_root_features
53,36,38,21,33,10,21,60,58,33
21,58,33,21,42,26,34,38,58,26
bootstrap_unique_fractions
0.6193 to 0.6430
0.6200 to 0.6500
mean_vote_margin
0.638055563
0.624444444
mean_top_vote_fraction
0.762499988
0.762222222
unanimous_vote_fraction
0.252777785
0.197222222
Also emitted per tree: tree_root_thresholds, tree_root_impurities, bootstrap_index_sums and tree_feature_seeds.
Two things that read as substantive rather than noise:
Flow's forest is unanimous on 25.3% of test samples against sklearn's 19.7%,
while the mean top-vote fraction is the same to 4 decimal places. Flow's trees
are more correlated with each other than sklearn's, which is the expected
signature of a weaker feature-subsampling draw.
bootstrap_unique_fractions sits near 0.632 on both sides, so neither
bootstrap is broken. The samples themselves differ entirely, as bootstrap_index_sums shows.
On the bootstrap indices specifically
ensemble.flow:60 builds them and frees them; RandomForestClassifier retains
nothing. Rather than change the struct, #402 replays the draw order in the
benchmark: n_train calls of prng_int(state, n_train) per tree, then one
further draw whose resulting state seeds that tree's feature subsampling. The
emitted values are a per-tree index checksum and unique-sample fraction, not the
14370 raw indices, which would be ~120KB per side in a committed artifact.
Two caveats worth knowing before you build on it:
The replay mirrors ensemble.flow rather than being driven by it. If the draw
order changes, the replay has to change with it. A retained field on RandomForestClassifier would be sturdier and is the right fix if this becomes
load-bearing.
tree_feature_seeds on the Flow side is the low 31 bits of a xorshift32 state;
on the sklearn side it is a Mersenne Twister randint draw. They are the same
kind of value in the same range and role, and comparing them numerically is
meaningless until the two RNGs are deliberately aligned. Treat that field as
provenance, not as a delta.
What is still missing for this issue
Per-tree node-level structure. Only per-tree scalars are emitted. The
Digits DecisionTree row now emits its full preorder split vectors and resolves
to a first divergent node index; the same treatment per tree would be ~10x the
artifact size, so it was not applied here. Worth doing for one pinned tree if
you want the same pointer for the forest.
Per-tree predictions. Vote margins are aggregated over the test set. Which
tree disagrees with which on which sample is not emitted.
Feature subsets actually chosen at each node. Only the seed and max_features_per_split are emitted, not the sampled feature sets.
Cross-reference: the RandomForest digits disparity of 0.019444447 has the same cause as #204's DecisionTree 0.019444424, in the same shared builder in lib/scikit/tree.flow.
Full working is in #204 (comment). Short version: split selection ties are the common case on digits (68 of 122 split nodes have more than one feature at the exact f32 minimum, mean multiplicity 9.7). Flow scans features in ascending index order with a strict comparison so the lowest index wins; sklearn draws the same candidate set through a Fisher-Yates permutation seeded from random_state. Both are correct, and the resulting accuracy spread on this row is 0.8111 to 0.8444 for sklearn across its own seeds 0..59, which contains both sides' numbers.
Flow is the more accurate side here (0.955556 against 0.936111), so closing the gap means adopting sklearn's tie-break and losing accuracy, and it would require reproducing sklearn's our_rand_r stream and its constant-feature draw bookkeeping bit for bit.
PR #426 documents the rule at both the plain and the RandomForest split comparison and pins it with a test. It changes no behaviour.
Closing as diagnosed, for the same reason as #204 and with the same evidence.
The disparity is in Flow's favour
From the committed headline_result_v2.json:
Flow
sklearn
RandomForest / digits
0.955555558
0.936111111
The tracked 0.019444447 is Flow scoring higher. Reducing it means degrading the forest.
Cause is inherited from the tree builder
RandomForest is built on the same split selection as DecisionTree, so the analysis on #204 applies directly. Both implementations compute identical impurity at the first divergent node and differ only in which of several exactly-tied features they select: Flow takes the lowest index, sklearn takes the first drawn from a Fisher-Yates permutation. 68 of 122 split nodes on digits have multiple features at the exact f32 minimum.
Sweeping sklearn's random_state over 60 seeds spans 0.811111 to 0.844444 with std 0.008324 on the DecisionTree row, making the tracked gap about 2.3 sigma of tie-break noise rather than a systematic difference.
The bootstrap half was checked separately
This issue also asks to align bootstrap and per-tree randomness. Work during the optimization campaign confirmed the draw order is intact: PR #349 and the Bagging work in #389/#390 both verified the fitted forest is bit-identical for a given seed after their changes, with the same srand(seed) and the same number of rand() calls in the same order. Nothing has perturbed it.
What was delivered
Per-tree diagnostics landed in #402 and are emitted for every canonical row: per-tree node and leaf counts, depths, root splits and impurities, bootstrap index checksum, bootstrap unique-sample fraction, feature-subsample seed, mean vote margin, mean top-vote fraction and unanimous-vote fraction.
Those produced a genuine finding worth keeping: Flow is unanimous on 25.3% of Digits test samples against sklearn's 19.7% at the same mean top-vote fraction, so Flow's trees are more correlated with each other. That is a real structural difference and is now measurable, which is what the diagnostic half of this issue asked for.
What was deliberately not done
Reproducing sklearn's RNG bit for bit, for the reasons in #204. Note also that the higher tree correlation above is a legitimate follow-up in its own right, since correlated trees weaken the variance reduction bagging exists to provide. If someone wants that, it should be a new issue framed as "reduce inter-tree correlation", which is about the forest's quality rather than about agreeing with sklearn's arbitrary tie-breaks.
Activity
godofecht commentedon Aug 18, 2026
Triage: still open, nothing has landed
Verified against the frozen canonical evidence on
main(c1e01df).benchmarks/disparity_report.json, digits RandomForest accuracy:score_abs_diffis0.01944444700000003, unchanged from the ~0.0194 figure this issue was filed against. Bothfinal_parity_statusandstrict_diagnostic_statusare "approximately equivalent".runtime_ratio_sklearn_over_flowis0.2629, so Flow is about 3.8x slower.model_state_diagnosticsfor this row is empty{}. No bootstrap indices, per-tree seeds, feature-subsampling choices, tree depths, per-tree predictions or vote margins are persisted by either implementation.benchmarks/bench_flow_v2.flowemitsDETAIL|records only for KMeans and PCA.lib/scikit/ensemble.flowdoes build bootstrap samples (bootstrap_indicesat line 60), so the data exists in the implementation. It is simply never emitted for comparison.This row is downstream of #204: the per-tree learner is the same DecisionTree, so the identical 0.0194 gap on both rows is suggestive and worth confirming before ensemble-level work starts.
Remaining work: emit per-tree bootstrap indices, RNG seeds and consumption order, feature-subsample selections, node counts and depths, plus per-tree predictions and ensemble vote margins as
DETAIL|records on both sides; add an ensemble comparison togenerate_disparity_report.pythat reports the first divergent tree index and whether the divergence is in sampling or in the learner; then align sklearn's randomness semantics where the difference is accidental.godofecht commentedon Aug 18, 2026
#207 is done for this row. PR #402 adds per-tree ensemble state on both sides and
the pairing logic that turns it into
model_state_diagnostics.What you can now read straight out of
disparity_report.jsonDigits RandomForest,
score_abs_diffstill 0.019444447:n_treesmax_features_per_splittree_node_countstree_leaf_countstree_max_depthstree_root_featuresbootstrap_unique_fractionsmean_vote_marginmean_top_vote_fractionunanimous_vote_fractionAlso emitted per tree:
tree_root_thresholds,tree_root_impurities,bootstrap_index_sumsandtree_feature_seeds.Two things that read as substantive rather than noise:
while the mean top-vote fraction is the same to 4 decimal places. Flow's trees
are more correlated with each other than sklearn's, which is the expected
signature of a weaker feature-subsampling draw.
bootstrap_unique_fractionssits near 0.632 on both sides, so neitherbootstrap is broken. The samples themselves differ entirely, as
bootstrap_index_sumsshows.On the bootstrap indices specifically
ensemble.flow:60builds them and frees them;RandomForestClassifierretainsnothing. Rather than change the struct, #402 replays the draw order in the
benchmark:
n_traincalls ofprng_int(state, n_train)per tree, then onefurther draw whose resulting state seeds that tree's feature subsampling. The
emitted values are a per-tree index checksum and unique-sample fraction, not the
14370 raw indices, which would be ~120KB per side in a committed artifact.
Two caveats worth knowing before you build on it:
ensemble.flowrather than being driven by it. If the draworder changes, the replay has to change with it. A retained field on
RandomForestClassifierwould be sturdier and is the right fix if this becomesload-bearing.
tree_feature_seedson the Flow side is the low 31 bits of a xorshift32 state;on the sklearn side it is a Mersenne Twister
randintdraw. They are the samekind of value in the same range and role, and comparing them numerically is
meaningless until the two RNGs are deliberately aligned. Treat that field as
provenance, not as a delta.
What is still missing for this issue
Digits DecisionTree row now emits its full preorder split vectors and resolves
to a first divergent node index; the same treatment per tree would be ~10x the
artifact size, so it was not applied here. Worth doing for one pinned tree if
you want the same pointer for the forest.
tree disagrees with which on which sample is not emitted.
max_features_per_splitare emitted, not the sampled feature sets.TreeNode.valueis unwritten on internal nodes and the array is
malloc'd, so it holds heapgarbage. feat: learned-state diagnostics for every canonical benchmark row (3/19 -> 19/19) #402 does not read it.
fitted numeric;
score_abs_diffis unchanged at 0.019444447 by design.Reproducing
FLOW_HEADLINE_COMMAND="flow run benchmarks/bench_flow_v2.flow" \ python benchmarks/run_headline.py --repeats 3 cp benchmarks/headline_summary.json benchmarks/headline_result_v2.json python benchmarks/generate_disparity_report.pygodofecht commentedon Aug 19, 2026
Cross-reference: the RandomForest digits disparity of 0.019444447 has the same cause as #204's DecisionTree 0.019444424, in the same shared builder in
lib/scikit/tree.flow.Full working is in #204 (comment). Short version: split selection ties are the common case on digits (68 of 122 split nodes have more than one feature at the exact f32 minimum, mean multiplicity 9.7). Flow scans features in ascending index order with a strict comparison so the lowest index wins; sklearn draws the same candidate set through a Fisher-Yates permutation seeded from
random_state. Both are correct, and the resulting accuracy spread on this row is 0.8111 to 0.8444 for sklearn across its own seeds 0..59, which contains both sides' numbers.Flow is the more accurate side here (0.955556 against 0.936111), so closing the gap means adopting sklearn's tie-break and losing accuracy, and it would require reproducing sklearn's
our_rand_rstream and its constant-feature draw bookkeeping bit for bit.PR #426 documents the rule at both the plain and the RandomForest split comparison and pins it with a test. It changes no behaviour.
docs: document the tree split tie-break rule and pin it with a test
godofecht commentedon Aug 19, 2026
Closing as diagnosed, for the same reason as #204 and with the same evidence.
The disparity is in Flow's favour
From the committed
headline_result_v2.json:The tracked 0.019444447 is Flow scoring higher. Reducing it means degrading the forest.
Cause is inherited from the tree builder
RandomForest is built on the same split selection as DecisionTree, so the analysis on #204 applies directly. Both implementations compute identical impurity at the first divergent node and differ only in which of several exactly-tied features they select: Flow takes the lowest index, sklearn takes the first drawn from a Fisher-Yates permutation. 68 of 122 split nodes on digits have multiple features at the exact f32 minimum.
Sweeping sklearn's
random_stateover 60 seeds spans 0.811111 to 0.844444 with std 0.008324 on the DecisionTree row, making the tracked gap about 2.3 sigma of tie-break noise rather than a systematic difference.The bootstrap half was checked separately
This issue also asks to align bootstrap and per-tree randomness. Work during the optimization campaign confirmed the draw order is intact: PR #349 and the Bagging work in #389/#390 both verified the fitted forest is bit-identical for a given seed after their changes, with the same
srand(seed)and the same number ofrand()calls in the same order. Nothing has perturbed it.What was delivered
Per-tree diagnostics landed in #402 and are emitted for every canonical row: per-tree node and leaf counts, depths, root splits and impurities, bootstrap index checksum, bootstrap unique-sample fraction, feature-subsample seed, mean vote margin, mean top-vote fraction and unanimous-vote fraction.
Those produced a genuine finding worth keeping: Flow is unanimous on 25.3% of Digits test samples against sklearn's 19.7% at the same mean top-vote fraction, so Flow's trees are more correlated with each other. That is a real structural difference and is now measurable, which is what the diagnostic half of this issue asked for.
What was deliberately not done
Reproducing sklearn's RNG bit for bit, for the reasons in #204. Note also that the higher tree correlation above is a legitimate follow-up in its own right, since correlated trees weaken the variance reduction bagging exists to provide. If someone wants that, it should be a new issue framed as "reduce inter-tree correlation", which is about the forest's quality rather than about agreeing with sklearn's arbitrary tie-breaks.
Closing as diagnosed rather than fixed.