siboehm / lleaves

Compiler for LightGBM gradient-boosted trees, based on LLVM. Speeds up prediction by ≥10x.
https://lleaves.readthedocs.io/en/latest/
MIT License
364 stars 29 forks source link

How to use multiple models via the C_API? #19

Closed fuyw closed 2 years ago

fuyw commented 2 years ago

Hi Simon, many thanks for the nice work. I have a question about using the C_API:

If I have 2 LightGBM models in my application, and I want to predict using the C_API. I might need to have following two functions:

void forest_root_model1(double *, double *, int, int);

void forest_root_model2(double *, double *, int, int);

Do I need to modify the llvm_model.compile() function to change the function names?

siboehm commented 2 years ago

Yeah good question, this is not a use-case I had previously encountered, but I'd be happy to support it. It'd involve adding an (optional) parameter to the .compile() method, maybe something like model_name. Then we pass the parameter into the codegen and update the function name here: https://github.com/siboehm/lleaves/blob/master/lleaves/compiler/codegen/codegen.py#L81

Ideally the default function name stays backwards compatible. Do you want to send a PR? Else I might be able to get to it next week.

fuyw commented 2 years ago

Sure, I would like to try send a PR.

siboehm commented 2 years ago

Closed by #21