haifengl / smile

Statistical Machine Intelligence & Learning Engine
https://haifengl.github.io
Other
5.99k stars 1.12k forks source link

Parallel execution of multiple DecisionTree throws NPE in predict method #716

Closed RedCometJ closed 2 years ago

RedCometJ commented 2 years ago

Describe the bug I am using the predict method of concurrent scenariosSolidified DecisionTree model。each in its own thread,I ocassionally get NPEs in Formula::x。I encountered a problem similar to #646 Expected behavior The inference should run in parallel without any NPE, because inference should only require read access on the models internal variables.

Actual behavior Stack trace:

java.lang.NullPointerException
        at smile.data.formula.Formula$2.getDouble(Formula.java:358)
        at smile.base.cart.OrdinalNode.predict(OrdinalNode.java:45)
        at smile.base.cart.OrdinalNode.predict(OrdinalNode.java:45)
        at smile.base.cart.OrdinalNode.predict(OrdinalNode.java:45)
        at smile.classification.DecisionTree.predict(DecisionTree.java:348)
        at smile.classification.DataFrameClassifier.predict(DataFrameClassifier.java:52)

Code snippet Steps to reproduce: 1,Data conversion 2,Each runing makes predictions based on the transformed data

DataFrame validData = DataFrame.of(CollectionUtils.newArrayList(modelData), LearnModelData.class);
decisionTree.predict(validData)

Problem can be worked around by executing predict() in a synchronized method,but that is very undesirable as it creates a significant bottleneck.

Input data LearnModelData = (cookie=0, agent=0, referer=0, host=1, frequency=0, failSignNum=0, failPswNum=0, xss=0, webScan=0,result=1)

Additional context Oracle JDK 8 Smile 2.6 centos 7

haifengl commented 2 years ago

This had be fixed. Can you try master branch?

RedCometJ commented 2 years ago

Thanks! When will smile new version be available in Maven Central?