← Back to Pull requests

test(df): require the same forest from two fits with the same seed #3937

Open
Alexandr-Solovev opened this pull request with 105 lines diff across 2 files
View on GitHub
Alexandr-Solovev Alexandr-Solovev commented on Oct 26, 2026 09:16 UTC
Author

Description

Adds a oneAPI decision forest test that fits the same data twice with the same seed and requires bitwise-identical trees (feature index, threshold, leaf response and sample count of every node) and inference responses. It covers classification and regression, the best and random splitters, and float and double.

This came out of the reproducibility report in uxlfoundation/scikit-learn-intelex#1916. The DF suite has no same-seed check: the existing engine tests only require different streams to give different forests.

On CPU the test passes on main without any change. The trees depend only on the seed and the tree index, since every tree gets its own engine before the parallel loop. So the test is a regression guard there: it passed on all host CPUs and with the test pinned to 1 CPU. Its main value is the DPC++ run on GPU, where the histogram kernels accumulate with floating-point atomics and near-tie splits could differ between runs. If it fails there, the fix goes in a follow-up PR.

The OOB results and variable importance are not compared: on CPU they currently depend on the merge order of the thread-local buffers, which #3911 fixes and tests.

Tests: bazel test --config=host //cpp/oneapi/dal/algo/decision_forest:test_batch_host (8 new cases). The DPC++ cases need a GPU run.

No public API or ABI changes.

---

<details>
<summary>Checklist:</summary>

Completeness and readability

  • I have commented my code, particularly in hard-to-understand areas.

  • I have updated the documentation to reflect the changes or created a separate PR with updates and provided its number in the description, if necessary. (not applicable)

  • Git commit message contains an appropriate signed-off-by string _(see CONTRIBUTING.md for details)_.

  • I have resolved any merge conflicts that might occur with the base branch.
  • Testing

  • I have run it locally and tested the changes extensively.

  • All CI jobs are green or I have provided justification why they aren't.

  • I have extended testing suite if new functionality was introduced in this PR.
  • Performance

  • I have measured performance for affected algorithms using scikit-learn_bench and provided at least a summary table with measured data, if performance change is expected. (test-only change)

  • I have provided justification why performance and/or quality metrics have changed or why changes are not expected.

  • I have extended the benchmarking suite and provided a corresponding scikit-learn_bench PR if new measurable functionality was introduced in this PR. (not applicable)
  • </details>

    🤖 Generated with Claude Code

    Diff: 105 lines (+105 / -0) across 2 files Reviewer: david-cortes-intel Review duration: 29555m
    All Vouch review confidence checks passed
    Residual risk 0.03 = Change Risk (0.32) × (1 − Review Confidence (0.92)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.32 · 105 lines diff across 2 files
    0.32
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.93 · 5 substantive comment(s)
    0.93
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    92%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.279
    Real PR Conversation Timeline
    10 items
    david-cortes-intel david-cortes-intel commented on code on Oct 26, 2026 13:20 UTC
    Code Review
    cpp/oneapi/dal/algo/decision_forest/test/fixture.hpp:1
    @@ -352,6 +353,80 @@ class df_test : public te::crtp_algo_fixture<TestType, Derived> {
             REQUIRE(train_leaf_sizes(first, 4) != train_leaf_sizes(second, 4));
         }
     
    +    /// Trains a forest twice with the same seed and checks that the trees and the inference
    +    /// results are bitwise identical.
    +    ///
    +    /// @param[in] splitter The splitter mode of the forest.
    +    void check_same_seed_same_forest(splitter_mode splitter) {
    +        constexpr bool is_cls = std::is_same_v<Task, decision_forest::task::classification>;
    +        constexpr std::int64_t row_count = 1000;
    +        constexpr std::int64_t column_count = 6;
    +        constexpr std::int64_t class_count = 3;

    Please check also for binary and regression, make the example as small as possible, and make it more prone to mathematical divergences (e.g. duplicated columns, highly correlated, etc.).

    david-cortes-intel david-cortes-intel commented on code on Oct 26, 2026 13:20 UTC
    Code Review
    cpp/oneapi/dal/algo/decision_forest/test/fixture.hpp:1
    @@ -352,6 +353,80 @@ class df_test : public te::crtp_algo_fixture<TestType, Derived> {
             REQUIRE(train_leaf_sizes(first, 4) != train_leaf_sizes(second, 4));
         }
     
    +    /// Trains a forest twice with the same seed and checks that the trees and the inference
    +    /// results are bitwise identical.
    +    ///
    +    /// @param[in] splitter The splitter mode of the forest.
    +    void check_same_seed_same_forest(splitter_mode splitter) {
    +        constexpr bool is_cls = std::is_same_v<Task, decision_forest::task::classification>;
    +        constexpr std::int64_t row_count = 1000;
    +        constexpr std::int64_t column_count = 6;
    +        constexpr std::int64_t class_count = 3;
    +
    +        auto x_arr = array<Float>::empty(row_count * column_count);
    +        auto y_arr = array<Float>::empty(row_count);
    +        Float* x_ptr = x_arr.get_mutable_data();
    +        Float* y_ptr = y_arr.get_mutable_data();
    +        std::mt19937 rng(2024);
    +        std::uniform_real_distribution<float> dist(-1.0f, 1.0f);
    +        for (std::int64_t i = 0; i < row_count; ++i) {
    +            float v[column_count];
    +            for (std::int64_t j = 0; j < column_count; ++j) {
    +                v[j] = dist(rng);
    +                x_ptr[i * column_count + j] = v[j];
    +            }
    +            y_ptr[i] = is_cls ? static_cast<Float>((v[0] + v[1] > 0.0f) + (v[2] > 0.3f))
    +                              : static_cast<Float>(v[0] * v[1] + v[2] + 0.1f * dist(rng));

    This is an example with very poor predictability. Please create data with a strong pattern.

    napetrov napetrov commented on code on Nov 07, 2026 22:38 UTC
    Code Review
    cpp/oneapi/dal/algo/decision_forest/test/fixture.hpp:1
    @@ -352,6 +354,87 @@ class df_test : public te::crtp_algo_fixture<TestType, Derived> {
             REQUIRE(train_leaf_sizes(first, 4) != train_leaf_sizes(second, 4));
         }
     
    +    /// Trains a forest twice with the same seed and checks that the trees and the inference
    +    /// results are bitwise identical. The response follows a strong pattern, and the features
    +    /// repeat it as exact, scaled, mirrored and near duplicates on a coarse grid, so split gains
    +    /// and thresholds tie and any order-dependent choice changes the forest.
    +    ///
    +    /// @param[in] splitter    The splitter mode of the forest.
    +    /// @param[in] class_count The number of classes; ignored for regression.
    +    void check_same_seed_same_forest(splitter_mode splitter, std::int64_t class_count = 2) {
    +        constexpr bool is_cls = std::is_same_v<Task, decision_forest::task::classification>;
    +        constexpr std::int64_t row_count = 64;
    +        constexpr std::int64_t column_count = 6;
    +
    +        auto x_arr = array<Float>::empty(row_count * column_count);
    +        auto y_arr = array<Float>::empty(row_count);
    +        Float* x_ptr = x_arr.get_mutable_data();
    +        Float* y_ptr = y_arr.get_mutable_data();
    +        std::mt19937 rng(2024);
    +        std::uniform_int_distribution<int> grid(-8, 8);

    question: a same-seed test whose input depends on the standard library's distribution

    cpp/oneapi/dal/algo/decision_forest/test/fixture.hpp:374 (check_same_seed_same_forest): the grid values are drawn with std::uniform_int_distribution, whose algorithm the standard leaves implementation-defined. libstdc++, libc++ and MSVC can produce different data from the same seed, so a same-seed failure seen on one platform may not reproduce on another, which weakens the reproducibility purpose of the test.

    How to check: not run (read only; provenance introduced (read)).
    Expected: a reproducibility test whose input is identical on every platform, since its purpose is to reproduce a report.
    Fix: map the raw rng() output to the grid directly (for example rng() % 17 - 8), so the input does not depend on the library's distribution.

    napetrov napetrov commented on code on Nov 07, 2026 22:38 UTC
    Code Review
    cpp/oneapi/dal/algo/decision_forest/test/fixture.hpp:1
    @@ -352,6 +354,87 @@ class df_test : public te::crtp_algo_fixture<TestType, Derived> {
             REQUIRE(train_leaf_sizes(first, 4) != train_leaf_sizes(second, 4));
         }
     
    +    /// Trains a forest twice with the same seed and checks that the trees and the inference
    +    /// results are bitwise identical. The response follows a strong pattern, and the features
    +    /// repeat it as exact, scaled, mirrored and near duplicates on a coarse grid, so split gains

    question: the comment says the features repeat the response, but no column equals it

    cpp/oneapi/dal/algo/decision_forest/test/fixture.hpp:359 (check_same_seed_same_forest): the response is s = u + 0.5 * v, and no column equals s. Columns 0-3 repeat or scale u and column 5 is v. The comment's "the features repeat it" misdescribes the data that is meant to induce ties.

    How to check: not run (read only; provenance introduced (read)).
    Expected: the comment describes the data: the features repeat u and v, and the response mixes them.
    Fix: reword the comment to match the data.

    napetrov napetrov commented on Nov 07, 2026 22:38 UTC
    Reviewer

    Verdict: comment only, no blocking finding. Head 245afbe8e, merge base ed085192b. This is a draft and test-only PR. Not built or run here; the findings come from reading the head tree.

    CI on head: one failing job, Enforce Labels (no label on the PR). It has no base run to compare with; it is a metadata check, not a code result.

    Findings (threads are inline): 2 questions, both about the test fixture (the standard-library distribution used for the grid, and a comment that misdescribes the data).

    Raised before:

  • @david-cortes-intel T1: still open, partly addressed. The binary, regression and correlated-column parts are on head; the example is still 64 rows x 6 columns x 8 trees, not as small as asked.

  • @david-cortes-intel T2: fixed on head.
  • Coverage: checked the diff against the head tree, CI verdicts and prior threads. Not looked at: the built test binary, GPU behaviour. The PR's fixture.hpp is also changed by #3911, #3910 and #3889 in the same decision-forest test batch; nothing in this review is rooted in those sibling PRs.

    Alexandr-Solovev Alexandr-Solovev commented on code on Nov 09, 2026 07:07 UTC
    Code Review
    cpp/oneapi/dal/algo/decision_forest/test/fixture.hpp:1
    @@ -352,6 +353,80 @@ class df_test : public te::crtp_algo_fixture<TestType, Derived> {
             REQUIRE(train_leaf_sizes(first, 4) != train_leaf_sizes(second, 4));
         }
     
    +    /// Trains a forest twice with the same seed and checks that the trees and the inference
    +    /// results are bitwise identical.
    +    ///
    +    /// @param[in] splitter The splitter mode of the forest.
    +    void check_same_seed_same_forest(splitter_mode splitter) {
    +        constexpr bool is_cls = std::is_same_v<Task, decision_forest::task::classification>;
    +        constexpr std::int64_t row_count = 1000;
    +        constexpr std::int64_t column_count = 6;
    +        constexpr std::int64_t class_count = 3;

    Added in 245afbe8e: binary and 3-class classification and regression, each with the best and random splitters. The features are exact, scaled, mirrored and near duplicates of one grid value, so split gains and thresholds tie. The data is 64 rows x 6 columns with 8 trees; if you want a specific smaller size, I can cut it.

    Alexandr-Solovev Alexandr-Solovev commented on code on Nov 09, 2026 07:07 UTC
    Code Review
    cpp/oneapi/dal/algo/decision_forest/test/fixture.hpp:1
    @@ -352,6 +353,80 @@ class df_test : public te::crtp_algo_fixture<TestType, Derived> {
             REQUIRE(train_leaf_sizes(first, 4) != train_leaf_sizes(second, 4));
         }
     
    +    /// Trains a forest twice with the same seed and checks that the trees and the inference
    +    /// results are bitwise identical.
    +    ///
    +    /// @param[in] splitter The splitter mode of the forest.
    +    void check_same_seed_same_forest(splitter_mode splitter) {
    +        constexpr bool is_cls = std::is_same_v<Task, decision_forest::task::classification>;
    +        constexpr std::int64_t row_count = 1000;
    +        constexpr std::int64_t column_count = 6;
    +        constexpr std::int64_t class_count = 3;
    +
    +        auto x_arr = array<Float>::empty(row_count * column_count);
    +        auto y_arr = array<Float>::empty(row_count);
    +        Float* x_ptr = x_arr.get_mutable_data();
    +        Float* y_ptr = y_arr.get_mutable_data();
    +        std::mt19937 rng(2024);
    +        std::uniform_real_distribution<float> dist(-1.0f, 1.0f);
    +        for (std::int64_t i = 0; i < row_count; ++i) {
    +            float v[column_count];
    +            for (std::int64_t j = 0; j < column_count; ++j) {
    +                v[j] = dist(rng);
    +                x_ptr[i * column_count + j] = v[j];
    +            }
    +            y_ptr[i] = is_cls ? static_cast<Float>((v[0] + v[1] > 0.0f) + (v[2] > 0.3f))
    +                              : static_cast<Float>(v[0] * v[1] + v[2] + 0.1f * dist(rng));

    Fixed in 245afbe8e: the response is now a function of the features (u + 0.5 * v, bucketed into classes for classification), with no noise.

    Alexandr-Solovev Alexandr-Solovev commented on code on Nov 09, 2026 07:07 UTC
    Code Review
    cpp/oneapi/dal/algo/decision_forest/test/fixture.hpp:1
    @@ -352,6 +354,87 @@ class df_test : public te::crtp_algo_fixture<TestType, Derived> {
             REQUIRE(train_leaf_sizes(first, 4) != train_leaf_sizes(second, 4));
         }
     
    +    /// Trains a forest twice with the same seed and checks that the trees and the inference
    +    /// results are bitwise identical. The response follows a strong pattern, and the features
    +    /// repeat it as exact, scaled, mirrored and near duplicates on a coarse grid, so split gains
    +    /// and thresholds tie and any order-dependent choice changes the forest.
    +    ///
    +    /// @param[in] splitter    The splitter mode of the forest.
    +    /// @param[in] class_count The number of classes; ignored for regression.
    +    void check_same_seed_same_forest(splitter_mode splitter, std::int64_t class_count = 2) {
    +        constexpr bool is_cls = std::is_same_v<Task, decision_forest::task::classification>;
    +        constexpr std::int64_t row_count = 64;
    +        constexpr std::int64_t column_count = 6;
    +
    +        auto x_arr = array<Float>::empty(row_count * column_count);
    +        auto y_arr = array<Float>::empty(row_count);
    +        Float* x_ptr = x_arr.get_mutable_data();
    +        Float* y_ptr = y_arr.get_mutable_data();
    +        std::mt19937 rng(2024);
    +        std::uniform_int_distribution<int> grid(-8, 8);

    Fixed in bbf689805: the grid is now rng() % 17 - 8 on the raw std::mt19937 output, which the standard fixes, so the data is the same with every standard library.

    Alexandr-Solovev Alexandr-Solovev commented on code on Nov 09, 2026 07:07 UTC
    Code Review
    cpp/oneapi/dal/algo/decision_forest/test/fixture.hpp:1
    @@ -352,6 +354,87 @@ class df_test : public te::crtp_algo_fixture<TestType, Derived> {
             REQUIRE(train_leaf_sizes(first, 4) != train_leaf_sizes(second, 4));
         }
     
    +    /// Trains a forest twice with the same seed and checks that the trees and the inference
    +    /// results are bitwise identical. The response follows a strong pattern, and the features
    +    /// repeat it as exact, scaled, mirrored and near duplicates on a coarse grid, so split gains

    Fixed in bbf689805: the comment now says the response is a pattern of u and v, the features repeat u and add v.

    Assignees
    Alexandr-Solovev Alexandr-Solovev
    Labels
    risk: low confidence: 92.2% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 32.4% (LOW) · Higher = larger blast radius
    32.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 92.2% · Lower = rushed or shallow review
    92.2%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 2.5% · Safe to merge
    2.5%