microsoft / microsoft/onnxruntime

[Feature Request] Support linear_tree=True in Lightgbm

Open
#25,623 0 comments 0 reactions 0 assignees View on GitHub
feature request
Dominant language
C++
Stars
21.9k
Forks
4.2k
Avg merge
4d 11h
Merged PRs (30d)
184

Description

### Describe the feature request

I am using lightgbm4.6.0, and i use linear_tree=True to train a model, thus, the output is different.

The problem must be the linear_tree option, because if i set linear_tree=False, then the output is exactlly same. Do you have plan to support it?

### Describe scenario use case

```python
import numpy as np
import lightgbm as lgb
from sklearn.model_selection import train_test_split

np.random.seed(42)
n_samples = 5000
X = np.random.rand(n_samples, 5) * 10
y = 1.5 * X[:, 0] + 0.8 * X[:, 1] - 2.0 * X[:, 2] + np.sin(X[:, 3]) + 0.1 * np.random.randn(n_samples)

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

params = {
'objective': 'regression',
'linear_tree': True,
'num_leaves': 31,
'learning_rate': 0.05,
'verbose': -1
}

train_data = lgb.Dataset(X_train, label=y_train)
test_data = lgb.Dataset(X_test, label=y_test, reference=train_data)

model = lgb.train(
params,
train_data,
num_boost_round=200
)

from onnxmltools.convert import convert_lightgbm
import onnxruntime as ort
from onnxconverter_common.data_types import FloatTensorType

onnx_model = convert_lightgbm(model, initial_types=[('input', FloatTensorType([None, 5]))])
with open('xxx', 'wb') as f:
f.write(onnx_model.SerialieToString())

session = ort.InferenceSession('xxx', providers=['CUDAExecuttionProvider'])
session.run(['variable'], {'input': X_test})
```

Contributor guide

Open the contributing guide

Research direction

Start by running the supplied Python example with LightGBM's linear_tree=True and the convert_lightgbm conversion path, then compare its output with linear_tree=False. Done means the conversion and ONNX Runtime inference preserve the expected output for linear-tree models.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, scikit-learn
Domain
ai, machine-learning
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.