Giter Club home page Giter Club logo

lightgbm-serving's Introduction

lightgbm-serving

Test Docker Image

A lightweight http server for lightGBM that support multi-model server.

Installation

Using docker

$ docker pull docker.pkg.github.com/jeongukjae/lightgbm-serving/lightgbm-serving

Build from source code

$ git clone https://github.com/jeongukjae/lightgbm-serving
$ cd lightgbm-serving
$ git submodule update --init --recursive
$ mkdir build && cd build && cmake .. -DCMAKE_BUILD_TYPE=Release
$ make
$ ./lightgbm-server --help
A lightweight server for LightGBM

Usage:
  ./lightgbm-server [OPTION...]

      --host arg              Host (default: localhost)
  -p, --port arg              Port (default: 8080)
  -c, --config arg            Model Config File (default: "")
  -l, --listener-threads arg  Num of threads of listener (default: 4)
  -v, --version               Show version string and infos and exit
  -h, --help                  Print usage

Usage

LightGBM-Serving takes a config file and model files. The config file is passed as a cli argument (-c or --config).

Configure Model Config

The config file should be json file, and should be structed like below.

{
    "config": [
        {
            "name": "test-model",
            "path": "/path/to/model"
        },
        ...
        // and more models!!
    ]
}

Run the server

$ ./lightgbm-serving --host 0.0.0.0 --port 8080 --config path-to-config.json

or use docker

$ docker run --rm -it \
  -v PATH_TO_MODEL:/models \
  -v PATH_TO_CONFIGL:/config.json \
  docker.pkg.github.com/jeongukjae/lightgbm-serving/lightgbm-serving -c /config.json
[2020-10-16 01:29:23.200] [info] Found 1 configs.
[2020-10-16 01:29:23.224] [info] Loaded test-model model from '/models/model.lgbm'.
[2020-10-16 01:29:23.224] [info] Running server on http://localhost:8080

Show debug log

Set environment variable LGBM_DEBUG to any values. (condition: if (std::getenv("LGBM_DEBUG")))

Example:

$ LGBM_DEBUG=1 ./lightgbm-server --config ../temp/config.json --host 0.0.0.0
[2020-10-16 01:27:39.549] [debug] CLI Arguments:
[2020-10-16 01:27:39.549] [debug]  - config : ../temp/config.json
[2020-10-16 01:27:39.549] [debug]  - host : 0.0.0.0
[2020-10-16 01:27:39.550] [info] Found 1 configs.
[2020-10-16 01:27:39.571] [info] Loaded test-model model from '../temp/test-model'.
[2020-10-16 01:27:39.571] [info] Running server on http://0.0.0.0:8080
[2020-10-16 01:27:44.966] [debug] POST /v1/models/test-model:predict HTTP/HTTP/1.1 200 - from 127.0.0.1
[2020-10-16 01:27:46.944] [debug] POST /v1/models/test-model:predict HTTP/HTTP/1.1 200 - from 127.0.0.1
[2020-10-16 01:27:47.485] [debug] POST /v1/models/test-model:predict HTTP/HTTP/1.1 200 - from 127.0.0.1
[2020-10-16 01:31:34.928] [debug] POST /v1/models/test-model:predict HTTP/HTTP/1.1 400 - from 127.0.0.1

View server status

$ curl http://localhost:8080/v1/stat

Inference

$ curl http://localhost:8080/v1/models/{MODEL_NAME_IN_CONFIG_FILE}:predict -d "[[1,2,3,4,5], [1,2,3,4,5]]"

###Payload should be 2d array that shape of is (batch size, num features).###

Inference Results

If a parameter num_classes of model is 1, then server will return 1d array with shape (batch size, ) like [0.5,0.3,0.2]. If not, server will return 2d array with shape (batch size, num classes) like [[1.0,2.0,3.0,4.0],[5.0,6.0,7.0,8.0]].

When error occured

code body reason
400 {"error": "There is no model"} When the model name key in url is missing.
400 {"error": "Cannot parse json array"} Cannot parse json array.
400 {"error": "invalid shape"} Invalid shape when parsing json array.

lightgbm-serving's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

lightgbm-serving's Issues

Documentation updates

There are two updates to documentation that could allow users to start this up more quickly:

  1. provide a valid model name in the example config.json (test-model doesn't match the API regex for models)
  2. have the test script generate a model with a number of input features which matches the sample request (40 vs 5 currently).

I can make a quick PR for this if it helps

Problems building from source

I'm running this on Mac OS 10.15

$ mkdir build && cd build && cmake .. -DCMAKE_BUILD_TYPE=Release

The command runs but warns about subdirectories not containing CMakeLists.txt and finishes with -- Configuring incomplete, errors occurred!

I can also pass along the CMakeOutput.log if that's helpful. Afterwards, if I try running the make command, I see make: *** No targets specified and no makefile found. Stop.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.