Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Blocking] python kernel failed when call Booster().predict #4056

Closed
zzd1992 opened this issue Jan 13, 2019 · 6 comments · Fixed by #4066
Closed

[Blocking] python kernel failed when call Booster().predict #4056

zzd1992 opened this issue Jan 13, 2019 · 6 comments · Fixed by #4066

Comments

@zzd1992
Copy link

zzd1992 commented Jan 13, 2019

Sometimes, the python kernel will be failed when I call Booster().predict method.
Here is an example:

import xgboost as xgb
import numpy as np

d = xgb.DMatrix(np.random.rand(1000, 5))
tree = xgb.Booster({'max_depth': 3, 'eta': 0.1, 'base_score': 0.0})

tree.boost(d, np.random.rand(1000), np.ones(1000))
print('start...')
preds = tree.predict(d)
print('end...')

Then

[19:35:05] src/tree/updater_prune.cc:74: tree pruning end, 1 roots, 14 extra nodes, 0 pruned nodes, max_depth=3
start...

Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)

However, when I modify the following line

tree.boost(d, np.random.rand(1000), np.ones(1000))

into

tree.boost(d, np.ones(1000), np.ones(1000))

Then every thing is ok.

start...
[19:49:16] src/tree/updater_prune.cc:74: tree pruning end, 1 roots, 0 extra nodes, 0 pruned nodes, max_depth=0
end...

How to fix this problem?

@trivialfis
Copy link
Member

@zzd1992 Let me look into this.

@trivialfis
Copy link
Member

@zzd1992 If you run the training process via xgb.train, XGBoost wiol throw an error tells you that you need labels for training since XGBoost implements supervised learning.

Maybe a better error handling in c++ is needed.

@zzd1992
Copy link
Author

zzd1992 commented Jan 14, 2019

@trivialfis Thanks.
It doesn't work to add labels to DMatrix when I call the predict method.
And the predict method should not be dependent on labels.
In fact, I need to growth the tree one by one and modify its predictions by myself.
So it looks not suitable to run xgb.train. xgb.Booster().boost() is better for me.

@trivialfis
Copy link
Member

@zzd1992 The label is only needed in training:

dtrain = xgb.DMatrix(train_data, label=labels)
bst = xgb.train(params, dtrain)

on prediction labels are not needed:

dtest = xgb.DMatrix(testing_data)
bst.predict(dtest)

The error you encountered is due to the fact that with empty labels in DMatrix, no training can be performed hence no tree is built. Later prediction needs at least one tree, which leads to an memory error.

@zzd1992
Copy link
Author

zzd1992 commented Jan 14, 2019

@trivialfis After running Booster().boost(), one tree is built. So there already exists a tree when predicting.
Here is an example:

d = xgb.DMatrix(np.random.rand(1000, 5), np.random.rand(1000))
tree = xgb.Booster({'max_depth': 3, 'eta': 0.1, 'base_score': 0.0})

tree.boost(d, np.random.rand(1000), np.ones(1000))
print(tree.get_dump()[0])

print('start...')
preds = tree.predict(d)
print('end...')

Then

0:[f3<0.011232] yes=1,no=2,missing=1
	1:[f0<0.817435] yes=3,no=4,missing=3
		3:leaf=-0.0150572
		4:leaf=-0.00429241
	2:[f4<0.30253] yes=5,no=6,missing=5
		5:[f4<0.291276] yes=7,no=8,missing=7
			7:leaf=-0.048414
			8:leaf=-0.0217552
		6:[f4<0.997218] yes=9,no=10,missing=9
			9:leaf=-0.0531961
			10:leaf=-0.0129695

start...
[23:24:37] src/tree/updater_prune.cc:74: tree pruning end, 1 roots, 10 extra nodes, 0 pruned nodes, max_depth=3

Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)

@trivialfis trivialfis changed the title python kernel failed when call Booster().predict [Blocking] python kernel failed when call Booster().predict Jan 19, 2019
@trivialfis
Copy link
Member

I never tried this before. I don't think Booster.boost or Booster.update is meant to be called by users. But still segmentation fault is not acceptable.

@lock lock bot locked as resolved and limited conversation to collaborators May 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants