nirs4all.pipeline.execution.refit.stacking_refit module

Stacking refit executor for pipelines with merge-predictions.

Implements a two-step refit strategy for stacking pipelines:

Step 1 – Base model refit: For each base model branch in the winning variant, clone the preprocessing pipeline, fit on all training data, train the model, and generate in-sample predictions that will serve as meta-features for Step 2.

Step 2 – Meta-model refit: Collect base model in-sample predictions into a feature matrix, train the meta-model on that matrix, evaluate on the test set (if available), and persist the result with fold_id="final" and refit_context="stacking".

This module also handles mixed merge pipelines (Task 3.4) where some branches contribute features and others contribute predictions, as well as GPU-aware serialization (Task 3.5) to avoid OOM when multiple GPU models are refit concurrently.

nirs4all.pipeline.execution.refit.stacking_refit.DEFAULT_MAX_STACKING_DEPTH = 3

Maximum nesting depth for stacked pipelines during refit.

Deeper nesting increases refit complexity exponentially (each level multiplies by the number of branches). 3 levels is sufficient for most real-world stacking scenarios (base models -> meta-model -> super-meta-model). Override by passing max_depth to execute_stacking_refit().