#model #machine-learning #deep-learning #server #store #command #another

app jams

jams is an easy-to-use CLI application for interaction with J.A.M.S - Just Another Model Server

16 releases

new 0.1.15 Jun 21, 2024
0.1.14 Jun 21, 2024

#67 in Network programming

Download history 89/week @ 2024-05-31 548/week @ 2024-06-07 728/week @ 2024-06-14

1,365 downloads per month

Apache-2.0

1MB
4K SLoC

JAMS

This crate provides a CLI for interacting J.A.M.S - Just Another Model Server.

Alt text

⚠️ DISCLAIMER: jams is currently unstable and may not run properly on your machines. I have tested the above on Apple Silicon and Linux x86_64 machines. Future releases will fix this

Features

  • Async
  • Separate Rayon Threadpool for computing predictions
  • Multiple Model Frameworks Supported
    • Tensorflow
    • Torch
    • Catboost
    • LightGBM
  • Multiple Model Store Backends Supported
    • Local File System
    • AWS S3
    • Azure Blob Storage
  • Thin & Fast API Layer
    • HTTP via Axum
    • gRPC via Tonic

The following features are in progress 🚧

  • Support XGBoost framework
  • Redis & DynamoDB as feature stores
  • User defined Configurations via YAML file
  • ModelSpec - Single source of information about models. This will assist in input validations
  • Client Implementations in Python, Go, TypeScript, JAVA

Docker Setup

J.A.M.S is also hosted on DockerHub.

Please follow the following commands to start the server inside docker

  1. Run docker pull gagansingh894/jams

To run HTTP server, use

docker run --rm -v /your/path/to/model_store:/model_store -p 3000:3000 gagansingh894/jams start http

To run gRPC server, use

docker run --rm -v /your/path/to/model_store:/model_store -p 4000:4000 gagansingh894/jams start grpc

To run with a S3 backend

  • Create a S3 bucket with some models in it. Please refer to the structure of model store here.
  • Set the environment variables - AWS_REGION, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY. Alternatively if you have multiple AWS profiles then just set the AWS_PROFILE-<profile_name> You also need to set the bucket name. This can either be set via S3_BUCKET_NAME env variable or passed via --s3-bucket-name flag
  • Run the command to start HTTP server with S3 model store. It assumes that bucket name is already set via S3_BUCKET_NAME
docker run --rm -p 3000:3000 gagansingh894/jams start http --with-s3-model-store=true
  • For gRPC server, use
docker run --rm -p 4000:4000 gagansingh894/jams start grpc --with-s3-model-store=true
  • If you want to pass bucket name, use
docker run --rm -p 3000:3000 gagansingh894/jams start http --with-s3-model-store=true --s3-bucket-name=<bucket_name>

To run with a Azure Blob Storage backend

  • Create a Azure Storage container with some models in it. Please refer to the structure of model store here.
  • Set the environment variables - STORAGE_ACCOUNT, STORAGE_ACCESS_KEY. You also need to set the azure container name. This can either be set via AZURE_STORAGE_CONTAINER_NAME env variable or passed via --azure-storage-container-name flag
  • Run the command to start HTTP server with Azure model store. It assumes that container name is already set via AZURE_STORAGE_CONTAINER_NAME
docker run --rm -p 3000:3000 gagansingh894/jams start http --with-azure-model-store=true
  • For gRPC server, use
docker run --rm -p 4000:4000 gagansingh894/jams start grpc --with-azure-model-store=true
  • If you want to pass container name, use
docker run --rm -p 3000:3000 gagansingh894/jams start http --with-azure-model-store=true --azure-storage-container-name=<container_name>

Please refer to OpenAPI Spec for API endpoints.

Alternatively, you can also refer to the proto definition.


Local Setup

Ensure that Cargo and Rust compiler are installed. Follow instructions here if not installed

This project relies on a couple of shared libraries. To easily set up, please follow the steps below

Mac

  1. Install Homebrew if not already installed
  2. Run the following command to install bazel, lightgbm, pytorch and tensorflow
brew install lightgbm pytorch tensorflow
  1. Download catboost library(.dylib) directly from Github
wget -q https://github.com/catboost/catboost/releases/download/v1.2.5/libcatboostmodel-darwin-universal2-1.2.5.dylib -O /usr/local/lib/libcatboostmodel.dylib
  1. Copy lightgbm to usr/local/lib
cp /opt/homebrew/Cellar/lightgbm/4.3.0/lib/lib_lightgbm.dylib /usr/local/lib
  1. Add the following environment variables
export LIBTORCH=/opt/homebrew/Cellar/pytorch/2.2.0_4
export LIGHTGBM_LIB_PATH=/opt/homebrew/Cellar/lightgbm/4.3.0/lib/
export DYLD_LIBRARY_PATH=/usr/local/lib:$DYLD_LIBRARY_PATH

Remember to check version numbers in the path as homebrew downloads the latest stable version.

Use brew info to get the exact path which you can use to set the environment variables

  1. Run the following command to install jams
cargo install jams

Linux

  1. Use the bash script here based on your system architecture

  2. Run the following commands or add them to shell profile

# add environment variables
export COMMON_LIBS_PATH=/usr/local/lib
export LIGHTGBM_LIB_DIR=$COMMON_LIBS_PATH
export LIBTORCH=$COMMON_LIBS_PATH/libtorch
export LIBTORCH_INCLUDE=$COMMON_LIBS_PATH/libtorch
export LIBTORCH_LIB=$COMMON_LIBS_PATH/libtorch
export LD_LIBRARY_PATH=$COMMON_LIBS_PATH:$COMMON_LIBS_PATH/libtorch/lib
export LIBRARY_PATH=$LIBRARY_PATH:$COMMON_LIBS_PATH/libtensorflow
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$COMMON_LIBS_PATH/libtensorflow/lib
  1. Run the following command to install J.A.M.S
cargo install jams

API Endpoints

Once J.A.M.S is up and running, these endpoints will help you interact with the server.

Please refer to OpenAPI Spec for details.

/healthcheck: Endpoint for health checks

/api/predict: Endpoint for making predictions

/api/models: Endpoint for managing models

Alternatively, you can refer also refer to the proto definition. It provides the following RPCs

  • HealthCheck
  • Predict
  • GetModels
  • AddModel
  • UpdateModel
  • DeleteModel

Usage

The CLI provides the following commands

- jams start
- jams predict

start

Use this command to start either the HTTP/gRPC model server on 0.0.0.0:3000/0.0.0.0:4000 with separate rayon threadpool for computing predictions

The server expects a model directory containing the models. This can be either passed using the --model-dir flag

To start HTTP server

jams start http --model-dir path/to/model_dir

To start gRPC server

jams start grpc --model-dir path/to/model_dir

Alternatively, you can set the MODEL_STORE_DIR env variable pointing to the model directory and run jams start http or jams start grpc

export MODEL_STORE_DIR=path/to/model_dir

By default, the server runs on port 3000 and 2 workers in the rayon threadpool.You can override using the --port and --num-workers flags respectively. The log level can also be changed to DEBUG level using --use-debug-level=true.

Model Store

Below is the expected structure of model stores.

  • Notice the model naming convention <model_framework>-model_name.tar.gz.
  • The server unpacks and loads the model files.
  • The server will warn about the unsupported formats and continue to load other models
└── model_store
    ├── catboost-my_awesome_binary_model.tar.gz
    ├── catboost-my_awesome_multiclass_model.tar.gz
    ├── catboost-my_awesome_regressor_model.tar.gz
    ├── catboost-titanic_model.tar.gz
    ├── lightgbm-my_awesome_binary_model_2.tar.gz
    ├── lightgbm-my_awesome_reg_model.tar.gz
    ├── lightgbm-my_awesome_xen_binary_model.tar.gz
    ├── lightgbm-my_awesome_xen_prob_model.tar.gz
    ├── pytorch-my_awesome_californiahousing_model.tar.gz
    ├── tensorflow-my_awesome_autompg_model.tar.gz
    ├── tensorflow-my_awesome_penguin_model.tar.gz
    ├── tensorflow-my_awesome_sequential_model.tar.gz
    └── torch-my_awesome_penguin_model.tar.gz

predict

Use this command for making predictions via CLI for making predictions for the following models

  • Tensorflow
  • Torch
  • Catboost
  • LightGBM

Refer below for some examples of the predict command.

There are multiple python scripts in examples folder which would allow you to generate different models and their corresponding sample json input. Below are some examples

Tensorflow

  1. Run tensorflow_penguin_multiclass_classification_model.py
  2. This will create two files- a model file and input json file
  3. Run the following command and pass in the path for model file and input file
jams predict tensorflow --model-path=tensorflow_penguin_functional --input-path=tensorflow_input.json

Torch

  1. Run torch_penguin_multiclass_classification_model.py
  2. This will create two files- a model file and input json file
  3. Run the following command and pass in the path for model file and input file
jams predict torch --model-path=torch_penguin.pt --input-path=torch_input.json

Catboost

  1. Run catboost_titanic_binary_classification_model.py
  2. This will create two files- a model file and input json file
  3. Run the following command and pass in the path for model file and input file
jams predict catboost --model-path=catboost_titanic --input-path=catboost_input.json

LightGBM

  1. Run lightgbm_iris_binary_classification_model.py
  2. This will create two files- a model file and input json file
  3. Run the following command(example) and pass in the path for model file and input file
jams predict lightgbm --model-path=lightgbm_iris.txt --input-path=lightgbm_input.json

Dependencies

~89MB
~1.5M SLoC