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

error: ‘inf’ undeclared with export_lib #8

Closed
travisbrady opened this issue Oct 18, 2017 · 8 comments
Closed

error: ‘inf’ undeclared with export_lib #8

travisbrady opened this issue Oct 18, 2017 · 8 comments

Comments

@travisbrady
Copy link

Hi, treelite looks excellent, but so far I can't seem to get my lightgbm model to export correctly.
Any pointers?

In [10]: tl.export_lib(toolchain='gcc', libpath='tree_test.so', verbose=False)
[19:31:42] /io/treelite/src/compiler/recursive.cc:188: Parallel compilation disabled; all member trees will be dump to a single source file. This may increase compilation time and memory usage.
[19:31:42] /home/ubuntu/anaconda3/envs/lgb207/lib/python3.6/site-packages/treelite/contrib/__init__.py:99: WARNING: some of the source files are long. Expect long compilation time. You may want to adjust the parameter parallel_comp.

---------------------------------------------------------------------------
TreeliteError                             Traceback (most recent call last)
<ipython-input-10-7ed5ccaceb4c> in <module>()
----> 1 tl.export_lib(toolchain='gcc', libpath='tree_test.so', verbose=False)

~/anaconda3/envs/lgb207/lib/python3.6/site-packages/treelite/frontend.py in export_lib(self, toolchain, libpath, params, compiler, verbose, nthread, options)
     90       self.compile(temp_dir, params, compiler, verbose)
     91       temp_libpath = create_shared(toolchain, temp_dir, nthread,
---> 92                                    verbose, options)
     93       shutil.move(temp_libpath, libpath)
     94

~/anaconda3/envs/lgb207/lib/python3.6/site-packages/treelite/contrib/__init__.py in create_shared(toolchain, dirpath, nthread, verbose, options)
    112   else:
    113     raise ValueError('toolchain {} not supported'.format(toolchain))
--> 114   libpath = _create_shared(dirpath, recipe, nthread, options, verbose)
    115   if verbose:
    116     log_info(__file__, lineno(),

~/anaconda3/envs/lgb207/lib/python3.6/site-packages/treelite/contrib/gcc.py in _create_shared(dirpath, recipe, nthread, options, verbose)
     90         f.write(result[id]['stdout'] + '\n')
     91       raise TreeliteError('Error occured in worker #{}: '.format(id) +\
---> 92                           '{}'.format(result[id]['stdout']))
     93
     94   # 2. Package objects into a dynamic shared library (.so)

TreeliteError: Error occured in worker #0: tmpl86ac6yh.c: In function ‘predict_margin’:
tmpl86ac6yh.c:10072:61: error: ‘infundeclared (first use in this function)
           if ( (data[1].missing != -1) && data[1].fvalue <= inf) {
                                                             ^
tmpl86ac6yh.c:10072:61: note: each undeclared identifier is reported only once for each function it appears in
@hcho3
Copy link
Collaborator

hcho3 commented Oct 18, 2017

@travisbrady This is interesting. Can you attach the LightGBM model file? I'm really not sure how that 'inf' constant got there.

@travisbrady
Copy link
Author

Absolutely, apologies for the delay. Had to anonymize this.
Model is here: https://gist.github.com/travisbrady/0dce5b62c9c2de5ee9c2900bc930099e

@hcho3
Copy link
Collaborator

hcho3 commented Oct 26, 2017

@travisbrady Thanks! A quick inspection does reveal the occurrence of constant 1e+300 in 8 trees (Trees 34, 100, 143, 160, 173, 199, 203, 248). Since 1e+300 is way too big to be stored in a 32-bit float, it gets converted into inf (infinity).

According to this page, LightGBM uses 1e+300 to indicate an infinite threshold. I will push a bug fix soon to accommodate infinite thresholds.

Thanks a lot for taking time to report this problem.

@travisbrady
Copy link
Author

@hcho3 No thank you so much for looking into this so quickly.
I'm really excited about treelite and would love to contribute. Incidentally, do you have any benchmarks? Perhaps comparing against xgboost, lightgbm and maybe https://github.com/ajtulloch/sklearn-compiledtrees ?

@hcho3
Copy link
Collaborator

hcho3 commented Oct 27, 2017

@travisbrady We're currently working on it. Our goal is to have 1) deployment tutorial and 2) benchmarks, before the official launch (some time next month?) Thanks for your interest.

hcho3 added a commit that referenced this issue Oct 27, 2017
hcho3 added a commit that referenced this issue Oct 27, 2017
@hcho3
Copy link
Collaborator

hcho3 commented Oct 27, 2017

@travisbrady I've pushed a bug fix to address the issue. A new binary wheel (version 0.1a10) will be available on PyPI within an hour or two.

@hcho3
Copy link
Collaborator

hcho3 commented Oct 27, 2017

As a side note, it may take a really long time to compile your model. To reduce compile time, you should enable both nthread option (uses multiple cores) and parallel_comp option (internally splits C program into multiple pieces).

Example:

model.export_lib('gcc', libpath='./libtest.dylib',
                 params={'parallel_comp':4}, nthread=4, verbose=True)

On my machine (specification), the above line takes about 2 minutes to complete.

@hcho3
Copy link
Collaborator

hcho3 commented Oct 28, 2017

The new wheel is now available. Install it by writing

pip install treelite==0.1a10

@hcho3 hcho3 closed this as completed Oct 30, 2017
hcho3 added a commit that referenced this issue Mar 26, 2018
The recent re-factor did not handle infinite thresholds properly, leading
to a problem similar to issue #8.

TODO. It is about time to write tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants