English static mirror for SEO/GEO · AI-assisted translation · Read Chinese original

leaves Project Evolution Plan: From Pure Prediction Library to Full GBRT Framework with GoMLX

Forum topic · ✨步子哥 · 2026-06-12

Summary

This draft (v1.0, dated 2026-06-13) outlines a phased roadmap to evolve the leaves Go library—currently a pure-Go GBRT inference library (v0.8.0) that loads and runs LightGBM, XGBoost, and scikit-learn models—into a complete, trainable, GPU-accelerated, and interpretable GBRT framework. Phase 0 refactors the monolithic package into modular packages, introduces a pluggable Engine interface and a framework-agnostic ForestIR/TreeIR intermediate representation, and adds the GoMLX dependency. Phase 1 implements a GoMLX symbolic-graph inference engine with XLA/GPU acceleration, loop unrolling or While-based tree traversal, NaN-based missing-value handling, and a WithBackend() option with automatic fallback to the native pure-Go path. Phase 2 adds XGBoost JSON model loading, ~12 evaluation metrics (RMSE, AUC, NDCG, etc.), native categorical features, and multi-output trees. Phase 3 delivers Tree SHAP values, SHAP interactions, five feature importance types, and model visualization (text/JSON/DOT). Phase 4 introduces GBDT training (Trainer, Booster, objectives, histogram tree builder, CV, early stopping). Phase 5 targets distributed training, quantized inference, ONNX interop, and WASM deployment. Design principles emphasize incremental enhancement, stable public APIs, GoMLX-first with native fallback, and test-driven evolution.

This is an English summary of a long Chinese draft document: the leaves project evolution plan (draft v1.0, 2026-06-13). leaves is a pure-Go GBRT prediction library (v0.8.0) that loads models trained by LightGBM, XGBoost, and scikit-learn. The plan proposes using GoMLX (a JAX-style symbolic graph + XLA JIT framework for Go) as the computation base to evolve leaves into a full GBRT framework, benchmarked against XGBoost as reference (not a clone).

Key points

Overall vision

  • leaves today is a "translator": it reads trained model files, walks each tree, and emits predictions. It has good bones (unified API + multi-backend IO) but lacks "muscle" (GPU acceleration, SHAP) and a "brain" (training).
  • Core question: how to add GoMLX-backed training, GPU acceleration, and interpretability without breaking ecosystem compatibility (LightGBM/XGBoost/sklearn model loading).
  • Design principles: incremental phases each shipping usable versions; stable Ensemble public API; GoMLX-first with fallback to the native pure-Go path; test-driven evolution with benchmarks per phase.
  • Current state

  • Supported: LightGBM (text/JSON), XGBoost (binary), sklearn (pickle); gbtree/dart/gblinear/random forest; dense + CSR inputs; Raw/Logistic/Softmax/Exponential/LeafIndex transforms; NaN default-left handling; LightGBM categorical one-hot rules; goroutine-pool batch prediction.
  • Gaps vs XGBoost: SHAP values, feature importance, ~24 built-in metrics, JSON model format, native categorical features, multi-output trees, GPU inference, training, survival objectives, distributed execution.
  • Performance bottleneck: scalar per-node tree traversal loops—no SIMD/GPU utilization; currently near C-API performance (<20% gap single-threaded).
  • Phase 0 — Architecture dual-track (v0.9.0)

  • Upgrade Go toolchain; add github.com/gomlx/gomlx dependency.
  • Split the monolithic root package into model/, tree/, io/, ensemble/, transform/, mat/, etc., keeping backward compatibility via type aliases in the root package until v1.0.0.
  • Define a pluggable tree.Engine interface (PredictDense, PredictCSR, PredictSingle, NOutputGroups, Close) plus a Factory.
  • Introduce a framework-agnostic intermediate representation: ForestIR / TreeIR (split feature, threshold, default-left, child indices, leaf values, categorical thresholds), unified from all model sources.
  • Phase 1 — GoMLX inference engine (v1.0.0)

  • Represent tree traversal as symbolic graphs using Gather, LessThan, Where, optional While loops, ReduceSum, and IsNaN for missing values.
  • Approach A (recommended): fully unroll loops for fixed-depth trees (depth 6 typical). Approach B: While loops for variable-depth trees. Categorical decisions via vectorized membership checks.
  • Forest-level parallelism: stack per-tree outputs as [batch, numTrees] and reduce-sum.
  • Transforms map to GoMLX built-ins (Logistic, fused Softmax, Exp).
  • New WithBackend() option: BackendAuto (GoMLX/XLA with native fallback), BackendGoMLX, BackendNative, BackendSimpleGo (WASM-compatible).
  • Performance expectations: native best for tiny batches; XLA GPU best for large batches (10K+); SimpleGo is the only WASM option.
  • Phase 2 — Format and feature parity (v1.1.0)

  • XGBoost JSON model loader (parse gbtree_model_param, trees[], train_param), converting into ForestIR.
  • A metrics/ package with core metrics: RMSE, MAE, MAPE, RMSLE, LogLoss, AUC, Error, multi-class LogLoss/Error, NDCG@k, MAP.
  • XGBoost-native categorical features (partition-based, ftype == 1) distinct from LightGBM one-hot.
  • Multi-output trees with vector leaves via Reshape/Gather.
  • Phase 3 — Interpretability (v1.2.0)

  • Tree SHAP contribution values and interaction values (pure-Go path computation on ForestIR, GoMLX for batch post-processing); O(TLD²) complexity considered acceptable.
  • Five feature importance types (weight/gain/total gain/cover/total cover), requiring IO parsers to extract loss_chg and sum_hess into TreeIR.
  • Model visualization: text / JSON / Graphviz DOT dumps; Saabas approximate contributions as a lightweight SHAP alternative.
  • Consistency tests against XGBoost Python SHAP.
  • Phase 4 — Training (v2.0.0)

  • XGBoost-style layered architecture: Trainer (loop, CV, early stopping, callbacks) → GradientBooster (gbtree/dart/gblinear) → Objective/Metric → histogram TreeBuilder → GoMLX backend.
  • Initial objectives: squared error, logistic, binary logistic, gamma, multi:softmax, rank:pairwise (LambdaRank); histogram-based tree building with optional GoMLX acceleration for histogram aggregation and split-gain computation.
  • Phase 5 — High performance and distribution (v3.0.0)

  • GPU/distributed training, quantized inference, ONNX interoperability, WASM deployment.
  • Risks and timeline

  • The document includes risk/mitigation sections and a milestone timeline mapping each phase to versions v0.9.0 → v3.0.0; mitigations for GoMLX limits include shape caching in Exec, per-tree subgraphs, loop unrolling for shallow trees, and Dense-first sparse handling.

Tags

#golang#gbrt#gomlx#xgboost#lightgbm#gpu-acceleration#shap#machine-learning

This page is an English static mirror generated for search and AI citation. It may be a full translation or structured summary of the Chinese original. Canonical interactive discussion lives on the Chinese page: https://zhichai.net/topic/177981183