Skip to content

Invariants#

The cross-file contracts. Each is stated once here and nowhere else; every other doc links to it rather than restating it.

Generated by scripts/render_invariants.py. Do not edit. Enforced entries come from the tests that prove them, so a contract and its gate cannot drift apart; asserted entries are hand-written in docs/invariants.src.md.

Enforced by a test#

Breaking one of these fails the suite.

binned-walk-bit-identical-to-raw-walk#

Predicting through a Dataset carrying the model's own cuts is bit-identical to predicting through the raw matrix, across the whole family: predict, staged, leaf indices and SHAP contributions. This is a documented escape hatch ("pass a Dataset instead of X"), so a divergence would silently change answers for a caller who took the advice.

caller-mask-restored-after-fit#

A FitPlace narrows the calling thread to the team's first CPU for its scope and hands the thread's own mask back when it closes, so a fit leaves the thread it ran on, and every thread created after it, exactly as placed as before. With the runtime's placement variables set the scope changes nothing. Linux only: elsewhere the scope is a no-op and there is nothing to restore.

constrained-scan-matches-scalar-scan#

A monotone constraint adds a bounded leaf weight test to its lane group. Constrained and free features share groups here, half the nodes under leaf value bounds, and every node returns the reference scan's split to the bit.

cuda-training-bit-reproducible#

A device fit is bit-reproducible on one device and one build. Histogram cells are int64 fixed point, so every accumulation is an exact integer sum whatever order the atomics land in, and everything downstream of the fill already ran in a fixed order. Three fits of one dataset serialize to identical bytes on every device plane, with the device objective and with the host objective forced. Not claimed: cross-device, cross-toolkit, or host-vs-device equality, which stay tolerance-bound.

cut-order-key#

A valid cut carries a strictly positive gain: score_cut_exact admits a candidate only when gain > 0.0, and the level finder only when it beats a best seeded at 0.0. On that domain the bit pattern of a double orders like its value, so split_better, which compares the pattern to keep the warp scan on the integer pipe, ranks every pair exactly as feat_better does. If either finder ever marked a non-positive or NaN gain valid, the two finders would disagree and this test would fail on the -0.0 and NaN rows.

dart-excludes-early-stopping#

DART and early stopping are incompatible by construction and the combination throws rather than silently producing wrong validation numbers: DART rescales earlier trees every round, which invalidates the incrementally accumulated validation scores early stopping reads.

device-bin-width-criterion-matches-host#

The u8-vs-u16 storage decision uses the same bin-count criterion on both sides, so a device-binned Dataset and a host-binned one hold the same width as well as the same values. Disagreeing would read a plane at the wrong stride, which is a memory-safety fault rather than a wrong number. The u16 section is the load-bearing half: it pushes max_bin past 256 and asserts the widths match, that the width really did switch, and that every cell agrees.

device-cuts-bit-identical#

cuda_fit_mappers returns the cuts BinMappers::fit returns, compared as uint32 bit patterns over every branch of create_cuts: all-distinct, greedy, stride, tie runs, signed zeros, and the NaN and infinity tails. The device model hash is only reproducible from the host hash's inputs while this holds; a sign flip on a zero or a one-ulp midpoint difference fails here.

device-finder-screen-is-exact#

The device finders screen every cut with fp32 interval bounds and score only the survivors in fp64; the screen may only discard a cut whose gain upper bound is below a gain already certified, so the exact best cut always survives and the chosen split, its bin and its direction are the same bytes the exhaustive fp64 sweep picks. BONSAI_CUDA_FINDER_EXHAUSTIVE disables the screen, and this test requires the two to route every row identically on data built to make the bounds tight: duplicate and near-duplicate columns, plateaus, a constant column, missing values, gradients at 1e-6 and 1e6, unit hessians on the min_child_hess boundary, lambda_l1, and monotone constraints with a positive min_gain_to_split.

device-grower-by-engine-type#

Whether a grower runs on a device is answered by its engine type through the registry, never by a caller inspecting the name. The registered spellings still say cuda_ for every device grower, so the predicate agrees with the prefix on every name the table holds; a name outside the table is not a device grower however it is spelled.

device-id-not-persisted#

A saved model names no device: parallel.device_id is a property of the machine that trained it, and a model loaded elsewhere places itself under the loader's config. The writer skips the leaf and the loader ignores it, so a file carries no "device_id" key and a load reads the default.

device-ingest-chunk-reuse#

Device ingest above 8 GiB of raw floats streams chunks through three pinned slots; a slot is reused only after the fence that follows its copy and bin kernel, so a matrix spanning more chunks than slots (here 256 MB row-major, four 64 MB chunks, and sixteen single-chunk columns) bins identically to the host on both paths. A slot reused early would bin a chunk from half-written raw. BONSAI_CUDA_INGEST_RING engages the ring below the threshold so this matrix exercises it; without the flag the same matrix uploads pageable through one slot and must bin the same bytes.

device-leaf-renewal-matches-host#

MAE, Huber and Quantile replace each leaf with a statistic of its residuals after the tree is built (src/objective.cpp renew_leaf). The resident path renews on the device: a radix selection over each leaf's residual keys, counted per row or summed by fixed-point weight, Huber's clamped mean, the monotone fence. This suite is its cross-check against the host renewal on all three planes, weighted and not, to the same tolerance the Newton objectives hold.

device-objective-formula-matches-host#

The device gradient and hessian kernels must stay numerically identical to src/objective.cpp's host formulas. Device-resident training reads them every round with no host cross-check, so a divergence shows up only as a quality difference. This suite is the cross-check: MSE, LogLoss and Poisson, on both the depthwise and levelwise planes, against the same fit with the host objective forced; the renewal objectives have their own pin below.

device-oversized-tree-refuses-not-falls-back#

A tree the device cannot hold is refused, never quietly moved to the host. All three device planes gate on the same histogram budget and throw ConfigError naming the limit; the host plane trains the same dataset without complaint, so the refusal is a device-capacity fact rather than a rejected dataset. Falling back instead would turn a configuration error into a silent performance cliff.

device-root-spends-its-host-rows#

A device root carries a host row list only until the engine stages it; from begin_root on it is a count and sums, the shape the identity root has from the start. A tree that ends at the root therefore stamps nothing on the host, which matters in resident mode: the per-row outputs are empty there, and a stamp over the staged rows writes past them.

device-weighted-renewal-selects-as-host#

A weighted renewal on the device sums each row's weight as a fixed-point integer at a power-of-two scale per leaf and evaluates the host's rank predicate on those exact sums. The scale cancels in the predicate, so where every weight is exact on the grid the device selects the element the host selects, ties included. One round isolates the rule: from round two on the resident and host gradients drift apart at rounding level for reasons the renewal does not own. Huber's correction is a double sum in partition order on the host, so it holds to a tolerance, not to the bit.

early-stopping-keeps-best-round#

A fit with early stopping returns the rounds up to its best validation loss, whether patience fired or the round budget ended first. A model that kept the rounds after its best one would not be the model the reported best loss was measured on.

equal-weights-select-the-unweighted-quantile#

Under one constant weight on every row the weighted quantile is the element the unweighted rule picks, for the base score and for leaf renewal, at every size and every alpha, with ties or without.

estimators-ignore-zero-weight-rows#

The label of a row whose sample_weight is zero never reaches the fit: whatever it says, every estimator predicts the same values, for every objective and for a multi-target y.

finder-reads-own-feature-totals#

Every feature's right side and node score are read from that feature's own histogram totals, never from another feature's. Float cells summed over a long same-sign run disagree across features by hundreds; read against one shared total, a feature's empty right side inherits the difference and an 800k-row label-sorted classification fit took that phantom cut at the root of every tree from round three on (issue 549). The free lane scan and the bounded one a monotone constraint selects both hold it.

fit-holds-under-label-sorted-rows#

A classification fit over rows sorted by label grows every leaf the same rows grow shuffled. Float histogram cells summed over a long run of one class disagree across features by hundreds, and a finder that read one shared total took a phantom cut on an empty side at the root of every tree, so this matrix, the shape of issue 549's, fitted a constant in block order.

fit-id-gates-resident-reuse#

A row-narrowed view mints a FitId distinct from its parent's, and a copy shares one. Anything caching against a Dataset keys on these tokens, so an equal token means "the same fit" with no allocator caveat: the device resident state is armed for ONE FitId, and a token that compared equal across two different fits would leave the previous fit's labels, scores and rows live under the next one.

infeasible-node-scores-its-parent#

A frontier node whose children would fall under min_child_hess contributes its parent score (zero gain) to a level candidate instead of vetoing it. At real depths some frontier node is always near-empty, so a veto rejected every good deep cut. The device level finder holds the same rule, pinned by its own parity case in test_cuda_grower.cpp.

init-scores-length-pins-output-count#

A multiclass booster's init scores are one per output or none: the score broadcast copies that vector into each row, so a vector of another length is refused at the boundary rather than written past a row.

label-block-rows-by-targets#

The label block is n_rows x n_targets row-major: target k of row r sits at r * n_targets + k, and a view gathers whole rows of it, so a rewrite of the view's rows carries every target of every selected row in view order. A vector y is the block at width 1, which is why every single-target reader of labels() is untouched by the width.

lane-level-scan-matches-scalar-scan#

lane-scan-matches-scalar-scan#

leaf-budget-cannot-bind-is-depthwise#

A depth-D tree has at most 2^D leaves, so a budget of 0 or of 2^D and above never stops an expansion: every leaf with positive gain splits, the same set depthwise splits. Sibling histograms are paired by subtraction in both growers, so leaf values agree to float rounding.

  • enforced by: ../tests/unit/test_leafwise_grower.cpp

leaf-budget-route-keeps-the-name#

The routed triple is what the table is searched with; cfg.dispatch is what the user wrote and what a saved model carries. Only the device routes: the host leaf plane keeps its grower at every budget.

  • enforced by: ../tests/unit/test_make_booster.cpp

leaf-budget-route-round-trips#

The saved config carries "leafwise" as written; the load resolves the same triple the save did (the host leaf plane, or the device's depthwise one on CUDA), so the bytes round-trip and the loaded booster continues on the same plane.

  • enforced by: ../tests/unit/test_model_io.cpp

leaf-plane-hands-small-arenas-to-the-level-plane#

The plane is picked per fit from the node arena's size: below k_level_plane_arena_bytes the level plane's eight rounds beat the leaf plane's one round per leaf, above it the leaf plane's cache-resident fill wins. A binding budget never hands over.

  • enforced by: ../tests/unit/test_leafwise_grower.cpp

leaf-renewal-holds-at-any-thread-count#

A renewed leaf value is the objective's renew_leaf over that leaf's residuals in row order, clamped into the leaf's fence, whatever the thread count: one thread, two and eight write the same table and the same row values, bit for bit. A leaf whose rows all carry zero weight, and a leaf with no row at all, keep the grower's value. The two row counts sit either side of the count at which the gather joins the select on the team.

level-fill-matches-lone-nodes#

The level plane fills a level's smaller children in one call and derives each larger child by subtracting its sibling from the parent's histograms. Whatever order the level fill zeroes, scatters and subtracts in, every small child's cells equal the node filled alone (bit for bit at one thread, where no partial arenas exist), a child with no rows carries no histograms and leaves its sibling the parent's cells untouched, and every other large child's cell is the parent's cell minus the small child's cell in float, once per cell.

level-finder-reads-own-feature-totals#

The level finder reads each parent's right side and parent score from the feature's own histogram, so a feature whose float cells sum differently from its neighbours offers no phantom cut on an empty side.

level-finder-skips-empty-slots#

A feature the tree's sample left out is an empty histogram slot on every frontier node. The level finder skips it on both its paths, the lane group and the scalar scan, the way the node finder does; reading it as a histogram with zero cuts walked past its storage.

level-scan-by-feature-matches-lane-scan#

The level finder's scan by feature is find's path only on an x86-64 host without AVX2. find_by_feature runs it on every host, and over frontiers with empty parents and empty feature slots it returns the reference scan's split and find's, to the bit.

levelwise-monotone-holds#

A levelwise fit under a monotone constraint produces predictions ordered by that feature, on both the CPU and CUDA engines. The mechanism is a projection of the finished leaf table onto the monotone cone (project_monotone), not a veto during growth, so the tree's structure is whatever the unconstrained search would have chosen.

levelwise-rejects-interaction-constraints#

The levelwise (oblivious) grower rejects interaction constraints at construction rather than silently ignoring them, on both the CPU and CUDA engines: the throw is in the shared template, so an engine cannot opt out of it. Monotone constraints are honoured rather than rejected, by project_monotone; interaction constraints have no equivalent projection, because they constrain which features may share a path rather than how leaf values are ordered.

lone-totals-fill-matches-lone-fill#

The leaf plane's form: the lone fill blocks a child's rows by the full selection's width, so the one-feature fill takes the same blocks and the same merge order, and the sibling it subtracts from ends up as the full fused fill would leave it for that feature.

multi-target-fit-matches-single-target-fits#

A multi-target regression grows one tree per target per round from that target's column of the label block and score matrix, through the same objective, renewal and score update a single-target fit runs, so with every row selected its prediction for target k equals, bit for bit, the prediction of a single-target fit on column k alone. Any engine or objective change that holds the three model hashes therefore holds the multi-target fit too.

perfect-tree-numbering-one-scheme#

The flattened node table and ObliviousTree::leaf_for agree on one numbering. The table gives internal node i the children 2i+1 and 2i+2 and appends the leaves after the internals in leaf_table order; leaf_for builds its index by shifting a bit per level, left as 0. Those two must name the same leaf for every root-to-leaf path, or the device epilogue and the host walk read different values out of the same tree. Four sites share the scheme, which is past the count where a normal change reliably updates all of them.

random-seed-varies-feature-draws#

The booster seeds the grower's feature_fraction draws from random_seed and feature_seed together, so two fits that differ only in random_seed draw different columns under the default all_rows sampler, and a fit with both fixed is reproducible. Before this pin random_seed reached the row sampler only, and a seed set of five fits under all_rows was five copies.

renewal-keeps-monotone#

A depthwise or leafwise fit under a monotone constraint stays ordered by that feature after leaf renewal. Renewal replaces each leaf's Newton step with a residual statistic (median, Huber mean, quantile) that can reverse the order the growth-time fence enforced, so the renewed value is clamped back into the fence the grower left for that leaf.

row-list-follows-the-fit#

The row list a round trains on belongs to the fit it was materialized for, keyed on the fit's minted token and never on its size: a second fit on a same-sized view of different rows grows the tree those rows grow, not the previous view's.

scan-by-feature-matches-lane-scan#

find scans one feature at a time only on an x86-64 host without AVX2, so no test host reaches that scan through find. find_by_feature runs it on every host, and on free and on constrained nodes it returns the reference scan's split and find's, to the bit.

smaller-child-tie-break-agrees#

On equal child row counts the fresh histogram slot goes to the LEFT child. The larger sibling derives by subtracting the smaller from the parent, so host and device must pick the same side or a subtraction reads the wrong sibling's histogram and the tree silently changes. The device makes the same <= comparison twice, in publish_small_child (which child's rows the partition kernel fills) and in leaf_children (which child holds the fresh slot), and those two must agree with each other as well.

team-packs-one-package-first#

A team fills one CPU per core, cores in id order, one package before the next: SMT siblings of a core never both host a worker, and a team no wider than a package shares its cache and memory node. Read from the process mask and /sys on Linux; the ordering is pinned from values here.

totals-fill-matches-full-fill#

A node's sums are read from one histogram, the lowest selected feature's, and a fill of that feature alone produces the same cells as the full fill, bit for bit: the same rows in the same chunks with the same partial order, only fewer features per row. The host growers rely on it for children that become leaves, filling that one feature instead of every selected one, so the leaf values are unchanged while the deepest level's fill shrinks by a factor near the feature count.

train-predict-bin-boundary-parity#

A row sitting exactly on a cut routes the same at train time and at predict time. The grower routes on bin <= split_bin while the predict walk routes on the stored raw threshold, and the two agree only because the binner is right-inclusive (bin b holds v in (cuts[b-1], cuts[b]]) and the FLT_MAX top-band closer keeps every finite value above the last cut out of the NaN sentinel. Cut values are the witness: they are the only inputs where a one-ulp disagreement between the two rules changes the leaf.

u16-bins-take-the-column-route#

A dataset past 255 bins reaches the level fill and the lone fill on the column route only: the row fills address a node's cells at the u8 feature stride, so a u16 node entering them would land in the wrong cells silently.

untouched-resize-writes-nothing#

A resize of an untouched vector allocates and constructs nothing: every zero-argument construction is skipped, so the first write to each page is the producer's and homes the page on the writer's memory node, which is what lets a bound team read the row mirror from its own node. A construction from a value runs as usual.

view-narrows-rows-not-plane#

A row view narrows which rows a fit visits and leaves the plane alone: view_n_rows() is the selection, plane_n_rows() stays the storage. Every row id remains a global id into the plane, which is why grad, hess, labels and the row-major mirror stay full length whatever the view selects.

warm-start-config-is-the-models#

A warm start's config is the loaded model's in every field the registry holds, except the fit's own: the data, metrics and parallel sections and the booster's n_iters, early_stopping_rounds and log_intervals. The continuation trains through the loaded booster, and predict applies the saved learning rate to every tree, so a field that kept the invocation's value would describe a model that was never fit. The fixture moves every registered field off its default, so a field the registry gains later is held to the same rule without an edit here.

zero-cover-branches-are-real#

Oblivious trees densify into a perfect shape, so a trained model really does carry leaves no training row reached. TreeSHAP's zero-cover guard therefore protects against an input that occurs, not a theoretical one. The second half matters as much: held-out rows drawn off the training joint distribution still do not route into a dead leaf, so the guard is about weighting those branches at zero rather than about rows landing there.

zero-parent-moves-no-level-split#

An oblivious level's shared split applies to every frontier node, so a node whose rows all routed one way leaves an empty child in the next frontier. That child contributes nothing to any candidate: its parent score and both children's scores are zero, so the level split chosen with it in the frontier is the split chosen without it, gain bit for bit; and a child that carries no histograms at all scans as that parent of zeros, wherever it sits in the frontier.

zero-weight-labels-never-reach-the-fit#

The label of a row whose weight is zero never reaches the fit: two fits whose labels differ only on such rows predict the same on every row, on each host grower and under each objective, for the base score, the splits and the renewed leaves alike.

Asserted in prose#

Two kinds sit here. Some cannot have a unit test: build flags, packaging matrices, claims about nondeterminism, decisions. Others are testable and simply are not marked yet, which makes this section the backlog: promoting one is writing its test and adding the marker. The code: lines name the source carrying each claim, and docs-check fails when one stops resolving.

Device planes#

multiclass-device-decline#

A multiclass model declines the CUDA predict and TreeSHAP planes and rides the host bin walk; width-1 dense and levelwise models ride the device.

  • code: include/bonsai/booster.hpp : device_plan_input
  • code: src/cuda/shap.cu : pack_shap_paths
  • code: src/python/module.cpp : predict_on_device
  • elaboration: decisions 108 and 111; issue #407 tracks the multiclass half.

device-paths-decline-never-error#

Every device predict and SHAP path declines to the host walk, never errors, on capability shortfalls: no CUDA build or device, multiclass, a feature over 255 bins, merged path length over 32, foreign ingest plane, allocation failure. A missing-covers model stays a host-side error, a model defect rather than a capability gap.

  • code: src/cuda/predict.cu : cuda_predict_plan
  • code: src/cuda/shap.cu : cuda_shap_plan
  • elaboration: decision 108.

device-predict-bit-equality#

Device predict is bit-equal to the host binned walk, row for row; the epilogue spells its rounding out because the kernel TU compiles with contraction on.

  • code: src/cuda/predict.cu : __fadd_rn
  • code: include/bonsai/detail/bin_walk.hpp : split_bins
  • elaboration: decision 108.

stub-trains-nothing-predicts-anywhere#

The cuda growers are registered in every build; without a device, construction and load succeed and training throws with a message naming the fix. Models trained on a device predict on any build.

  • code: src/cuda/histogram_engine_stub.cpp : throw_unavailable
  • code: include/bonsai/registry/typelists.hpp : CudaObliviousGrower
  • elaboration: decision 70.

resident-objective-eligibility#

The device-resident objective arms for MSE, LogLoss, Poisson, MAE, Huber and Quantile with no DART and a sampler that never reads gradient values; everything else takes the host path. Each arms weighted or not; a weighted MAE, Huber or Quantile fit renews its leaves on the device by the host's weighted rule over fixed-point weights scaled per leaf, so its selection equals the host's wherever each weight is exact on that grid. A renewal fit takes the host path when an oblivious tree is under a monotone constraint (its leaf table is reprojected on the host). BONSAI_HOST_OBJECTIVE=1 forces the host path. A K-target regression fit arms under the same rules, once with the whole label and score blocks, and grows tree k from the device's column k.

  • code: include/bonsai/booster.hpp : resident_begin
  • code: include/bonsai/multi_output_booster.hpp : try_resident_round
  • code: src/cuda/detail/device_context.cu : resident_begin
  • elaboration: decision 78.

Training semantics#

split-tie-break#

Exact gain ties break to the earliest candidate: lowest feature id, then lowest bin, then default-left first. Load-bearing for the bit-identity contract; both scan orders preserve it.

  • code: src/split.cpp : update_best
  • elaboration: decision 16.

subtraction-trick#

Level batching populates only each smaller sibling's histograms; the larger sibling derives by cell-wise subtraction, on both planes. Node totals are computed at split time, never accumulated during the fill.

  • code: src/step/primitives.hpp : smaller_child
  • code: src/step/primitives.hpp : finish_split
  • code: include/bonsai/histogram.hpp : Histogram
  • elaboration: decision 19.

gain-and-cover-stamped-at-grow#

Split gains and per-node covers are stamped at grow time; neither is reconstructible from a stored tree, so a model saved without them loads with the dependent features (importance, TreeSHAP) declining and saying why.

  • code: include/bonsai/tree.hpp : covers
  • code: src/shap_paths.cpp : pack_shap_paths
  • elaboration: the gain-storage entry in decisions.md.

auto-thread-cap#

n_threads=0 resolves to hardware concurrency capped at auto_thread_cap (16) and further capped by any cgroup CPU quota; the quota read is what makes container fits honest.

  • code: include/bonsai/parallel.hpp : auto_thread_cap
  • elaboration: the threading entries in decisions.md.

softmax-true-hessian#

Multiclass softmax uses the true diagonal Hessian p(1-p), not the factor-2 convention, floored at 1e-6 before weighting.

  • code: include/bonsai/multiclass_booster.hpp : 1e-6F
  • elaboration: the multiclass entry in decisions.md; guide/12-multiclass.md teaches it.

Data plane#

host-determinism#

Model bytes are a function of the input, the config and the configured thread count. At a fixed thread count they are identical across runs and across CPU architectures; CI trains a reference model serially and at eight threads on arm64 and x86-64 and compares file hashes per commit. With u16 bins (a feature with more than 256 bins, which needs max_bin above 256) they are also identical at any thread count; with u8 bins the sparse nodes deeper in the tree reduce partial histograms in an order set by the thread count. Host builds compile with contraction off, which is what makes the claim hold across compilers. A host fit and a device fit of one dataset never agree byte for byte, because the host accumulates histogram cells in float and the device in int64 fixed point: one tree grown on each from the same gradients gives every row a value within an absolute 1e-4 of the other (tests/unit/test_cuda_grower.cpp), and the release check on a 30-tree fit allows 1e-3 on predictions and 0.005 on R-squared (scripts/wheel_smoke_cuda.py). The device fit's own byte identity is the enforced cuda-training-bit-reproducible.

device-binning-byte-identity#

Device ingest produces bins byte-identical to the host mapper's transform: the kernel runs the same binary search over the same cuts, so a device-binned Dataset and a host-binned one are the same object to everything downstream.

  • code: src/cuda/detail/ingest_kernels.cuh : transform_bin
  • code: src/bin_mapper.cpp : BinMapper::transform
  • elaboration: decision 99.

routing-rule-one-source#

A row routes left iff its bin is at or below the split bin, with the last bin following default_left. The device kernels mirror the host rule rather than reimplementing it, and the [cuda] parity suite fails when they diverge.

  • code: include/bonsai/dataset.hpp : routes_left
  • code: src/cuda/detail/kernels.cuh : goes_left_dev
  • elaboration: decision 108's bit-equality claim rests on this.

threshold-to-bin-one-inversion#

A stored split threshold is turned back into a bin by exactly one function. The grower records threshold = cuts()[bin] and cuts are strictly increasing, so lower_bound recovers the bin exactly; DART, warm start, the device epilogue, and the SHAP packers all go through it rather than re-deriving the mapping.

  • code: include/bonsai/bin_mapper.hpp : bin_of_threshold
  • code: src/cuda/predict.cu : bin_of_threshold
  • elaboration: an edit here is a wire-format change even though no byte layout moves.

max-bin-default#

bin_mapper.max_bin defaults to 255, which is what keeps the default bin plane u8; a setting above 256 switches storage to u16 and costs the device SHAP plane (8-bit intervals).

  • code: include/bonsai/config/bin_mapper_config.hpp : max_bin
  • code: include/bonsai/bin_store.hpp : BinColumns
  • elaboration: api/parameters.md is the generated reference; prose says "255 by default" and links there.

shap-additivity-exact#

Host TreeSHAP satisfies the efficiency property exactly: sum(phi) plus the expected value reproduces the raw prediction, by construction of the closed form. The device fp32 path is tolerance-bound instead, and the raw-matrix fp64 host walk is the escape.

  • code: include/bonsai/shap.hpp : tree_shap
  • code: src/shap.cpp : tree_expected_value
  • elaboration: decision 108; its status banner records the fp32 device bound reaching 1e-5 at 200 trees depth 10.

dataset-not-picklable#

Dataset objects, host-built or device-resident, do not pickle; rebuild from X and y in the target process. Model objects pickle.

  • code: src/python/module.cpp : __reduce__
  • elaboration: the pickling entry in decisions.md.

Build and packaging#

wheel-arch-matrix#

The linux x86_64 wheel fatbins the one kernel TU for sm_70 through sm_120 with a compute_90 PTX floor for forward-JIT, links cudart statically, and imports on GPU-less hosts.

  • code: CMakeLists.txt : BONSAI_CUDA_PTX_ARCH
  • elaboration: decision 70; api/install.md carries the support matrix.

static-libomp#

BONSAI_OPENMP_STATIC=ON links libomp into the module statically so bonsai and another OpenMP library (XGBoost, LightGBM) in one process cannot deadlock on two runtimes.

  • code: CMakeLists.txt : BONSAI_OPENMP_STATIC
  • elaboration: the libomp entry in decisions.md; api/building.md documents the flag.

python-floor#

Supported CPythons are 3.9 through 3.13 on every wheel platform; the 3.9 floor is why nanobind is pinned below 3.

  • code: pyproject.toml : requires-python
  • elaboration: api/install.md carries the matrix.

eight-cli-subcommands#

The CLI wires eight subcommands: fit, predict, eval, bench, dump, importance, info, params. info reads the same registry dispatch uses, so it cannot drift from what a build can construct.

multi-gpu-withdrawn#

Multi-GPU's supported story is fit-parallelism: N independent single-GPU fits. The data-parallel engine reached measured parity and is withdrawn to a branch; config carries a singular parallel.device_id.

  • code: include/bonsai/config/parallel_config.hpp : device_id
  • elaboration: decisions 76 and 98.

Deleted symbols#

Symbols that docs or comments may still name, gone from the tree: Dataset::is_categorical, Dataset::row_major_bins (now Dataset::mirror()), finalize_rows (now finalize_tree), populate_many, NoSampler (now AllRowsSampler), SplitCandidate (now SplitOutput), the 4-axis dispatch (Splitters was never a registry axis). A doc resurrecting one of these is stale, not informative.

  • code: include/bonsai/dataset.hpp : mirror
  • code: include/bonsai/sampler.hpp : AllRowsSampler
  • code: include/bonsai/split.hpp : SplitOutput